Files

71 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2025-12-21 04:56:50 +01:00
<?php
/**
* Admin settings and configuration
*/
if (!defined('ABSPATH')) {
exit;
}
if (!class_exists('WC_TPP_Admin')) {
class WC_TPP_Admin {
2025-12-21 04:56:50 +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) {
if (null === self::$settings_instance) {
require_once WC_TPP_PLUGIN_DIR . 'includes/class-wc-tpp-settings.php';
self::$settings_instance = new WC_TPP_Settings();
}
// Check if our settings page is already in the array to prevent duplicates
// Check by class type and ID instead of instance comparison
foreach ($settings as $settings_page) {
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') {
return $settings;
}
}
$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);
}
}
}
WC_TPP_Admin::get_instance();
}