@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | { |
16 | 16 | if ( is_admin() ) { |
17 | 17 | // Add the admin page and settings. |
18 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
19 | - add_action( 'network_admin_menu', array( $this, 'addmenu' ) ); |
|
20 | - } else { |
|
21 | - add_action( 'admin_menu', array( $this, 'addmenu' ) ); |
|
22 | - } |
|
18 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
19 | + add_action( 'network_admin_menu', array( $this, 'addmenu' ) ); |
|
20 | + } else { |
|
21 | + add_action( 'admin_menu', array( $this, 'addmenu' ) ); |
|
22 | + } |
|
23 | 23 | add_action( 'admin_init', array( $this, 'registersettings' ) ); |
24 | 24 | |
25 | 25 | // Set meta info. |
@@ -630,11 +630,11 @@ discard block |
||
630 | 630 | |
631 | 631 | public function addmenu() |
632 | 632 | { |
633 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
634 | - $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show' ) ); |
|
635 | - } else { |
|
636 | - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show' ) ); |
|
637 | - } |
|
633 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
634 | + $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show' ) ); |
|
635 | + } else { |
|
636 | + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show' ) ); |
|
637 | + } |
|
638 | 638 | |
639 | 639 | add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) ); |
640 | 640 | add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) ); |
@@ -33,12 +33,12 @@ discard block |
||
33 | 33 | public function run() |
34 | 34 | { |
35 | 35 | if ( is_admin() ) { |
36 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
37 | - add_action( 'network_admin_menu', array( $this, 'admin_menu' ) ); |
|
38 | - } else { |
|
39 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
40 | - } |
|
41 | - add_action( 'admin_init', array( $this, 'registersettings' ) ); |
|
36 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
37 | + add_action( 'network_admin_menu', array( $this, 'admin_menu' ) ); |
|
38 | + } else { |
|
39 | + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
40 | + } |
|
41 | + add_action( 'admin_init', array( $this, 'registersettings' ) ); |
|
42 | 42 | add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_extra_tab' ) ); |
43 | 43 | } else { |
44 | 44 | $this->run_on_frontend(); |
@@ -342,9 +342,9 @@ discard block |
||
342 | 342 | ); |
343 | 343 | } |
344 | 344 | |
345 | - public function registersettings() { |
|
346 | - register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' ); |
|
347 | - } |
|
345 | + public function registersettings() { |
|
346 | + register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' ); |
|
347 | + } |
|
348 | 348 | |
349 | 349 | public function add_extra_tab( $in ) |
350 | 350 | { |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | public function run() |
98 | 98 | { |
99 | 99 | if ( is_admin() ) { |
100 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
101 | - add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) ); |
|
102 | - } else { |
|
103 | - add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) ); |
|
104 | - } |
|
105 | - add_action( 'admin_init', array( $this, 'registersettings' ) ); |
|
100 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
101 | + add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) ); |
|
102 | + } else { |
|
103 | + add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) ); |
|
104 | + } |
|
105 | + add_action( 'admin_init', array( $this, 'registersettings' ) ); |
|
106 | 106 | add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_imgopt_tab' ), 9 ); |
107 | 107 | } else { |
108 | 108 | $this->run_on_frontend(); |
@@ -875,9 +875,9 @@ discard block |
||
875 | 875 | ); |
876 | 876 | } |
877 | 877 | |
878 | - public function registersettings() { |
|
879 | - register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' ); |
|
880 | - } |
|
878 | + public function registersettings() { |
|
879 | + register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' ); |
|
880 | + } |
|
881 | 881 | |
882 | 882 | public function add_imgopt_tab( $in ) |
883 | 883 | { |
@@ -20,11 +20,11 @@ |
||
20 | 20 | if ( $this->enabled() ) { |
21 | 21 | add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_partner_tabs' ), 10, 1 ); |
22 | 22 | } |
23 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
24 | - add_action( 'network_admin_menu', array( $this, 'add_admin_menu' ) ); |
|
25 | - } else { |
|
26 | - add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); |
|
27 | - } |
|
23 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
24 | + add_action( 'network_admin_menu', array( $this, 'add_admin_menu' ) ); |
|
25 | + } else { |
|
26 | + add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); |
|
27 | + } |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | protected function enabled() |
@@ -12,93 +12,93 @@ |
||
12 | 12 | */ |
13 | 13 | class autoptimizeOption |
14 | 14 | { |
15 | - /** |
|
16 | - * Constructor, add filter on saving options. |
|
17 | - */ |
|
18 | - public function __construct() |
|
15 | + /** |
|
16 | + * Constructor, add filter on saving options. |
|
17 | + */ |
|
18 | + public function __construct() |
|
19 | 19 | { |
20 | - add_action('init', [$this, 'check_multisite_on_saving_options']); |
|
21 | - } |
|
20 | + add_action('init', [$this, 'check_multisite_on_saving_options']); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Ensure that is_plugin_active_for_network function is declared. |
|
25 | - */ |
|
26 | - public static function maybe_include_plugin_functions() { |
|
27 | - if( ! function_exists( 'is_plugin_active_for_network' ) ) { |
|
28 | - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
29 | - } |
|
30 | - } |
|
23 | + /** |
|
24 | + * Ensure that is_plugin_active_for_network function is declared. |
|
25 | + */ |
|
26 | + public static function maybe_include_plugin_functions() { |
|
27 | + if( ! function_exists( 'is_plugin_active_for_network' ) ) { |
|
28 | + include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
29 | + } |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Retrieves the option in standalone and multisite instances. |
|
34 | - * |
|
35 | - * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
|
36 | - * @param mixed $default Optional. Default value to return if the option does not exist. |
|
37 | - * @return mixed Value set for the option. |
|
38 | - */ |
|
32 | + /** |
|
33 | + * Retrieves the option in standalone and multisite instances. |
|
34 | + * |
|
35 | + * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
|
36 | + * @param mixed $default Optional. Default value to return if the option does not exist. |
|
37 | + * @return mixed Value set for the option. |
|
38 | + */ |
|
39 | 39 | public static function get_option( $option, $default = false ) |
40 | 40 | { |
41 | - // Ensure that is_plugin_active_for_network function is declared. |
|
42 | - self::maybe_include_plugin_functions(); |
|
41 | + // Ensure that is_plugin_active_for_network function is declared. |
|
42 | + self::maybe_include_plugin_functions(); |
|
43 | 43 | |
44 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
45 | - return get_network_option( get_main_network_id(), $option ); |
|
46 | - } else { |
|
47 | - return get_option( $option, $default ); |
|
48 | - } |
|
44 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
45 | + return get_network_option( get_main_network_id(), $option ); |
|
46 | + } else { |
|
47 | + return get_option( $option, $default ); |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | - /** |
|
52 | - * Saves the option in standalone and multisite instances. |
|
53 | - * |
|
54 | - * @param string $option Option name. Expected to not be SQL-escaped. |
|
55 | - * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. |
|
56 | - * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options, |
|
57 | - * `$autoload` can only be updated using `update_option()` if `$value` is also changed. |
|
51 | + /** |
|
52 | + * Saves the option in standalone and multisite instances. |
|
53 | + * |
|
54 | + * @param string $option Option name. Expected to not be SQL-escaped. |
|
55 | + * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. |
|
56 | + * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options, |
|
57 | + * `$autoload` can only be updated using `update_option()` if `$value` is also changed. |
|
58 | 58 | * Accepts 'yes'|true to enable or 'no'|false to disable. For non-existent options, |
59 | 59 | * the default value is 'yes'. Default null. |
60 | 60 | * @return bool False if value was not updated and true if value was updated. |
61 | - */ |
|
61 | + */ |
|
62 | 62 | public static function update_option( $option, $value, $autoload = null ) |
63 | 63 | { |
64 | 64 | |
65 | - // Ensure that is_plugin_active_for_network function is declared. |
|
66 | - self::maybe_include_plugin_functions(); |
|
65 | + // Ensure that is_plugin_active_for_network function is declared. |
|
66 | + self::maybe_include_plugin_functions(); |
|
67 | 67 | |
68 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
69 | - return update_network_option( get_main_network_id(), $option, $value ); |
|
70 | - } else { |
|
71 | - return update_option( $option, $value, $autoload ); |
|
72 | - } |
|
68 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
69 | + return update_network_option( get_main_network_id(), $option, $value ); |
|
70 | + } else { |
|
71 | + return update_option( $option, $value, $autoload ); |
|
72 | + } |
|
73 | 73 | } |
74 | 74 | |
75 | - /** |
|
76 | - * Use the pre_update_option filter to check if the option to be saved if from autoptimize and |
|
77 | - * in that case, take care of multisite case. |
|
78 | - */ |
|
79 | - public static function check_multisite_on_saving_options() |
|
75 | + /** |
|
76 | + * Use the pre_update_option filter to check if the option to be saved if from autoptimize and |
|
77 | + * in that case, take care of multisite case. |
|
78 | + */ |
|
79 | + public static function check_multisite_on_saving_options() |
|
80 | 80 | { |
81 | - // Ensure that is_plugin_active_for_network function is declared. |
|
82 | - self::maybe_include_plugin_functions(); |
|
81 | + // Ensure that is_plugin_active_for_network function is declared. |
|
82 | + self::maybe_include_plugin_functions(); |
|
83 | 83 | |
84 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
85 | - add_filter( 'pre_update_option', [$this, 'update_autoptimize_option_on_network'], 10, 3 ); |
|
86 | - } |
|
87 | - } |
|
84 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
85 | + add_filter( 'pre_update_option', [$this, 'update_autoptimize_option_on_network'], 10, 3 ); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - public static function update_autoptimize_option_on_network( $value, $option, $old_value ) { |
|
90 | - if( strpos( $option, 'autoptimize_' ) === 0 ) { |
|
89 | + public static function update_autoptimize_option_on_network( $value, $option, $old_value ) { |
|
90 | + if( strpos( $option, 'autoptimize_' ) === 0 ) { |
|
91 | 91 | |
92 | - // Ensure that is_plugin_active_for_network function is declared. |
|
93 | - self::maybe_include_plugin_functions(); |
|
92 | + // Ensure that is_plugin_active_for_network function is declared. |
|
93 | + self::maybe_include_plugin_functions(); |
|
94 | 94 | |
95 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
96 | - update_network_option( get_main_network_id(), $option, $value ); |
|
97 | - // Return old value, to stop update_option logic. |
|
98 | - return $old_value; |
|
99 | - } |
|
100 | - } |
|
101 | - return $value; |
|
102 | - } |
|
95 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
96 | + update_network_option( get_main_network_id(), $option, $value ); |
|
97 | + // Return old value, to stop update_option logic. |
|
98 | + return $old_value; |
|
99 | + } |
|
100 | + } |
|
101 | + return $value; |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | new autoptimizeOption(); |