2025-12-21 04:56:50 +01:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Admin settings and configuration
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!defined('ABSPATH')) {
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-22 19:02:18 +01:00
|
|
|
if (!class_exists('WC_TPP_Admin')) {
|
|
|
|
|
class WC_TPP_Admin {
|
2025-12-21 04:56:50 +01:00
|
|
|
|
2025-12-22 20:01:27 +01:00
|
|
|
private static $instance = null;
|
|
|
|
|
private static $settings_instance = null;
|
|
|
|
|
|
|
|
|
|
public static function get_instance() {
|
|
|
|
|
if (null === self::$instance) {
|
|
|
|
|
self::$instance = new self();
|
|
|
|
|
}
|
|
|
|
|
return self::$instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function __construct() {
|
2025-12-21 05:14:19 +01:00
|
|
|
add_filter('woocommerce_get_settings_pages', array($this, 'add_settings_page'));
|
2025-12-21 04:56:50 +01:00
|
|
|
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 05:14:19 +01:00
|
|
|
/**
|
|
|
|
|
* Add settings page to WooCommerce settings
|
|
|
|
|
*/
|
|
|
|
|
public function add_settings_page($settings) {
|
2025-12-22 20:01:27 +01:00
|
|
|
if (null === self::$settings_instance) {
|
2025-12-22 23:29:35 +01:00
|
|
|
require_once WC_TPP_PLUGIN_DIR . 'includes/class-wc-tpp-settings.php';
|
|
|
|
|
self::$settings_instance = new WC_TPP_Settings();
|
2025-12-22 20:01:27 +01:00
|
|
|
}
|
2025-12-22 23:05:11 +01:00
|
|
|
|
|
|
|
|
// Check if our settings page is already in the array to prevent duplicates
|
2025-12-22 23:33:12 +01:00
|
|
|
// Check by class type and ID instead of instance comparison
|
2025-12-22 23:05:11 +01:00
|
|
|
foreach ($settings as $settings_page) {
|
2025-12-22 23:33:12 +01:00
|
|
|
if ($settings_page instanceof WC_TPP_Settings) {
|
|
|
|
|
return $settings;
|
|
|
|
|
}
|
|
|
|
|
// Also check by ID property if it's a WC_Settings_Page
|
|
|
|
|
if (is_object($settings_page) &&
|
|
|
|
|
method_exists($settings_page, 'get_id') &&
|
|
|
|
|
$settings_page->get_id() === 'tier_package_prices') {
|
|
|
|
|
return $settings;
|
|
|
|
|
}
|
|
|
|
|
// Check id property directly
|
|
|
|
|
if (is_object($settings_page) &&
|
|
|
|
|
isset($settings_page->id) &&
|
|
|
|
|
$settings_page->id === 'tier_package_prices') {
|
2025-12-22 23:05:11 +01:00
|
|
|
return $settings;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-22 20:01:27 +01:00
|
|
|
$settings[] = self::$settings_instance;
|
2025-12-21 05:14:19 +01:00
|
|
|
return $settings;
|
2025-12-21 04:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function enqueue_admin_scripts($hook) {
|
2025-12-21 05:14:19 +01:00
|
|
|
if ('woocommerce_page_wc-settings' === $hook || 'post.php' === $hook || 'post-new.php' === $hook) {
|
2025-12-21 04:56:50 +01:00
|
|
|
wp_enqueue_style('wc-tpp-admin', WC_TPP_PLUGIN_URL . 'assets/css/admin.css', array(), WC_TPP_VERSION);
|
|
|
|
|
wp_enqueue_script('wc-tpp-admin', WC_TPP_PLUGIN_URL . 'assets/js/admin.js', array('jquery'), WC_TPP_VERSION, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-22 19:32:47 +01:00
|
|
|
|
2025-12-22 20:01:27 +01:00
|
|
|
WC_TPP_Admin::get_instance();
|
2025-12-22 19:02:18 +01:00
|
|
|
}
|