|
7 | 7 |
|
8 | 8 | // If this file is called directly, abort. |
9 | 9 | if ( ! defined( 'WPINC' ) ) { |
10 | | - die; |
| 10 | + die; |
11 | 11 | } |
12 | 12 |
|
13 | 13 | /** |
14 | 14 | * Main plugin class. |
15 | 15 | */ |
16 | 16 | class Optimizations_Ace_Mc { |
17 | 17 |
|
18 | | - /** |
19 | | - * The single instance of the class. |
20 | | - * |
21 | | - * @var Optimizations_Ace_Mc|null |
22 | | - */ |
23 | | - protected static $instance = null; |
24 | | - |
25 | | - /** |
26 | | - * Plugin settings. |
27 | | - * |
28 | | - * @var array |
29 | | - */ |
30 | | - private $settings = array(); |
31 | | - |
32 | | - /** |
33 | | - * Default settings. |
34 | | - * |
35 | | - * @var array |
36 | | - */ |
37 | | - private $default_settings = array( |
38 | | - 'woocommerce_show_empty_categories' => true, |
39 | | - 'woocommerce_hide_category_count' => true, |
40 | | - 'woocommerce_user_order_count_column' => true, |
41 | | - 'wpsl_show_store_categories' => true, |
42 | | - 'wpsl_disable_rest_api' => true, |
43 | | - 'admin_user_registration_date_column' => true, |
44 | | - ); |
45 | | - |
46 | | - /** |
47 | | - * Main instance. |
48 | | - * |
49 | | - * @return Optimizations_Ace_Mc |
50 | | - */ |
51 | | - public static function instance() { |
52 | | - if ( null === self::$instance ) { |
53 | | - self::$instance = new self(); |
54 | | - } |
55 | | - return self::$instance; |
56 | | - } |
57 | | - |
58 | | - /** |
59 | | - * Constructor. |
60 | | - */ |
61 | | - public function __construct() { |
62 | | - // Load settings. |
63 | | - $this->load_settings(); |
64 | | - |
65 | | - // Initialize admin interface. |
66 | | - add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); |
67 | | - add_action( 'admin_init', array( $this, 'init_settings' ) ); |
68 | | - |
69 | | - // Initialize optimizations. |
70 | | - $this->init_optimizations(); |
71 | | - } |
72 | | - |
73 | | - /** |
74 | | - * Load plugin settings. |
75 | | - */ |
76 | | - private function load_settings() { |
77 | | - $saved_settings = get_option( 'optimizations_ace_mc_settings', array() ); |
78 | | - $this->settings = wp_parse_args( $saved_settings, $this->default_settings ); |
79 | | - } |
80 | | - |
81 | | - /** |
82 | | - * Get setting value. |
83 | | - * |
84 | | - * @param string $key Setting key. |
85 | | - * @return mixed Setting value. |
86 | | - */ |
87 | | - private function get_setting( $key ) { |
88 | | - return isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : false; |
89 | | - } |
90 | | - |
91 | | - /** |
92 | | - * Initialize optimization functions. |
93 | | - */ |
94 | | - private function init_optimizations() { |
95 | | - // WooCommerce optimizations. |
96 | | - $this->init_woocommerce_optimizations(); |
97 | | - |
98 | | - // WP Store Locator optimizations. |
99 | | - $this->init_wpsl_optimizations(); |
100 | | - |
101 | | - // WordPress admin optimizations. |
102 | | - $this->init_admin_optimizations(); |
103 | | - } |
104 | | - |
105 | | - /** |
106 | | - * Initialize WooCommerce-specific optimizations. |
107 | | - */ |
108 | | - private function init_woocommerce_optimizations() { |
109 | | - // Show empty categories in WooCommerce. |
110 | | - if ( $this->get_setting( 'woocommerce_show_empty_categories' ) ) { |
111 | | - add_filter( 'woocommerce_product_subcategories_hide_empty', '__return_false' ); |
112 | | - } |
113 | | - |
114 | | - // Hide category product count in product archives. |
115 | | - if ( $this->get_setting( 'woocommerce_hide_category_count' ) ) { |
116 | | - add_filter( 'woocommerce_subcategory_count_html', '__return_false' ); |
117 | | - } |
118 | | - |
119 | | - // Add order count column to users admin. |
120 | | - if ( $this->get_setting( 'woocommerce_user_order_count_column' ) && is_admin() && current_user_can( 'list_users' ) ) { |
121 | | - add_filter( 'manage_users_columns', array( $this, 'add_user_order_count_column' ) ); |
122 | | - add_filter( 'manage_users_custom_column', array( $this, 'display_user_order_count_column' ), 10, 3 ); |
123 | | - add_filter( 'manage_users_sortable_columns', array( $this, 'make_user_order_count_sortable' ) ); |
124 | | - } |
125 | | - } |
126 | | - |
127 | | - /** |
128 | | - * Initialize WP Store Locator optimizations. |
129 | | - */ |
130 | | - private function init_wpsl_optimizations() { |
131 | | - // Show store categories in store locator. |
132 | | - if ( $this->get_setting( 'wpsl_show_store_categories' ) ) { |
133 | | - add_filter( 'wpsl_store_meta', array( $this, 'add_store_categories_to_meta' ), 10, 2 ); |
134 | | - add_filter( 'wpsl_info_window_template', array( $this, 'customize_info_window_template' ) ); |
135 | | - } |
136 | | - |
137 | | - // Disable REST API for store locator post type. |
138 | | - if ( $this->get_setting( 'wpsl_disable_rest_api' ) ) { |
139 | | - add_filter( 'wpsl_post_type_args', array( $this, 'custom_post_type_args' ) ); |
140 | | - } |
141 | | - } |
| 18 | + /** |
| 19 | + * The single instance of the class. |
| 20 | + * |
| 21 | + * @var Optimizations_Ace_Mc|null |
| 22 | + */ |
| 23 | + protected static $instance = null; |
| 24 | + |
| 25 | + /** |
| 26 | + * Plugin settings. |
| 27 | + * |
| 28 | + * @var array |
| 29 | + */ |
| 30 | + private $settings = array(); |
| 31 | + |
| 32 | + /** |
| 33 | + * Default settings. |
| 34 | + * |
| 35 | + * @var array |
| 36 | + */ |
| 37 | + private $default_settings = array( |
| 38 | + 'woocommerce_show_empty_categories' => true, |
| 39 | + 'woocommerce_hide_category_count' => true, |
| 40 | + 'woocommerce_user_order_count_column' => true, |
| 41 | + 'wpsl_show_store_categories' => true, |
| 42 | + 'wpsl_disable_rest_api' => true, |
| 43 | + 'admin_user_registration_date_column' => true, |
| 44 | + ); |
| 45 | + |
| 46 | + /** |
| 47 | + * Main instance. |
| 48 | + * |
| 49 | + * @return Optimizations_Ace_Mc |
| 50 | + */ |
| 51 | + public static function instance() { |
| 52 | + if ( null === self::$instance ) { |
| 53 | + self::$instance = new self(); |
| 54 | + } |
| 55 | + return self::$instance; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Constructor. |
| 60 | + */ |
| 61 | + public function __construct() { |
| 62 | + // Load settings. |
| 63 | + $this->load_settings(); |
| 64 | + |
| 65 | + // Initialize admin interface. |
| 66 | + add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); |
| 67 | + add_action( 'admin_init', array( $this, 'init_settings' ) ); |
| 68 | + |
| 69 | + // Initialize optimizations. |
| 70 | + $this->init_optimizations(); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Load plugin settings. |
| 75 | + */ |
| 76 | + private function load_settings() { |
| 77 | + $saved_settings = get_option( 'optimizations_ace_mc_settings', array() ); |
| 78 | + $this->settings = wp_parse_args( $saved_settings, $this->default_settings ); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Get setting value. |
| 83 | + * |
| 84 | + * @param string $key Setting key. |
| 85 | + * @return mixed Setting value. |
| 86 | + */ |
| 87 | + private function get_setting( $key ) { |
| 88 | + return isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : false; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Initialize optimization functions. |
| 93 | + */ |
| 94 | + private function init_optimizations() { |
| 95 | + // WooCommerce optimizations. |
| 96 | + $this->init_woocommerce_optimizations(); |
| 97 | + |
| 98 | + // WP Store Locator optimizations. |
| 99 | + $this->init_wpsl_optimizations(); |
| 100 | + |
| 101 | + // WordPress admin optimizations. |
| 102 | + $this->init_admin_optimizations(); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Initialize WooCommerce-specific optimizations. |
| 107 | + */ |
| 108 | + private function init_woocommerce_optimizations() { |
| 109 | + // Show empty categories in WooCommerce. |
| 110 | + if ( $this->get_setting( 'woocommerce_show_empty_categories' ) ) { |
| 111 | + add_filter( 'woocommerce_product_subcategories_hide_empty', '__return_false' ); |
| 112 | + } |
| 113 | + |
| 114 | + // Hide category product count in product archives. |
| 115 | + if ( $this->get_setting( 'woocommerce_hide_category_count' ) ) { |
| 116 | + add_filter( 'woocommerce_subcategory_count_html', '__return_false' ); |
| 117 | + } |
| 118 | + |
| 119 | + // Add order count column to users admin. |
| 120 | + if ( $this->get_setting( 'woocommerce_user_order_count_column' ) && is_admin() && current_user_can( 'list_users' ) ) { |
| 121 | + add_filter( 'manage_users_columns', array( $this, 'add_user_order_count_column' ) ); |
| 122 | + add_filter( 'manage_users_custom_column', array( $this, 'display_user_order_count_column' ), 10, 3 ); |
| 123 | + add_filter( 'manage_users_sortable_columns', array( $this, 'make_user_order_count_sortable' ) ); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Initialize WP Store Locator optimizations. |
| 129 | + */ |
| 130 | + private function init_wpsl_optimizations() { |
| 131 | + // Show store categories in store locator. |
| 132 | + if ( $this->get_setting( 'wpsl_show_store_categories' ) ) { |
| 133 | + add_filter( 'wpsl_store_meta', array( $this, 'add_store_categories_to_meta' ), 10, 2 ); |
| 134 | + add_filter( 'wpsl_info_window_template', array( $this, 'customize_info_window_template' ) ); |
| 135 | + } |
| 136 | + |
| 137 | + // Disable REST API for store locator post type. |
| 138 | + if ( $this->get_setting( 'wpsl_disable_rest_api' ) ) { |
| 139 | + add_filter( 'wpsl_post_type_args', array( $this, 'custom_post_type_args' ) ); |
| 140 | + } |
| 141 | + } |
142 | 142 |
|
143 | 143 | /** |
144 | 144 | * Initialize WordPress admin optimizations. |
|
0 commit comments