@@ -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 | { |
@@ -12,70 +12,70 @@ |
||
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 | - * Retrieves the option in standalone and multisite instances. |
|
25 | - * |
|
26 | - * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
|
27 | - * @param mixed $default Optional. Default value to return if the option does not exist. |
|
28 | - * @return mixed Value set for the option. |
|
29 | - */ |
|
23 | + /** |
|
24 | + * Retrieves the option in standalone and multisite instances. |
|
25 | + * |
|
26 | + * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
|
27 | + * @param mixed $default Optional. Default value to return if the option does not exist. |
|
28 | + * @return mixed Value set for the option. |
|
29 | + */ |
|
30 | 30 | public static function get_option( $option, $default = false ) |
31 | 31 | { |
32 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
33 | - return get_network_option( get_main_network_id(), $option ); |
|
34 | - } else { |
|
35 | - return get_option( $option, $default ); |
|
36 | - } |
|
32 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
33 | + return get_network_option( get_main_network_id(), $option ); |
|
34 | + } else { |
|
35 | + return get_option( $option, $default ); |
|
36 | + } |
|
37 | 37 | } |
38 | 38 | |
39 | - /** |
|
40 | - * Saves the option in standalone and multisite instances. |
|
41 | - * |
|
42 | - * @param string $option Option name. Expected to not be SQL-escaped. |
|
43 | - * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. |
|
44 | - * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options, |
|
45 | - * `$autoload` can only be updated using `update_option()` if `$value` is also changed. |
|
39 | + /** |
|
40 | + * Saves the option in standalone and multisite instances. |
|
41 | + * |
|
42 | + * @param string $option Option name. Expected to not be SQL-escaped. |
|
43 | + * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. |
|
44 | + * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options, |
|
45 | + * `$autoload` can only be updated using `update_option()` if `$value` is also changed. |
|
46 | 46 | * Accepts 'yes'|true to enable or 'no'|false to disable. For non-existent options, |
47 | 47 | * the default value is 'yes'. Default null. |
48 | 48 | * @return bool False if value was not updated and true if value was updated. |
49 | - */ |
|
49 | + */ |
|
50 | 50 | public static function update_option( $option, $value, $autoload = null ) |
51 | 51 | { |
52 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
53 | - return update_network_option( get_main_network_id(), $option, $value ); |
|
54 | - } else { |
|
55 | - return update_option( $option, $value, $autoload ); |
|
56 | - } |
|
52 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
53 | + return update_network_option( get_main_network_id(), $option, $value ); |
|
54 | + } else { |
|
55 | + return update_option( $option, $value, $autoload ); |
|
56 | + } |
|
57 | 57 | } |
58 | 58 | |
59 | - /** |
|
60 | - * Use the pre_update_option filter to check if the option to be saved if from autoptimize and |
|
61 | - * in that case, take care of multisite case. |
|
62 | - */ |
|
63 | - public static function check_multisite_on_saving_options() |
|
59 | + /** |
|
60 | + * Use the pre_update_option filter to check if the option to be saved if from autoptimize and |
|
61 | + * in that case, take care of multisite case. |
|
62 | + */ |
|
63 | + public static function check_multisite_on_saving_options() |
|
64 | 64 | { |
65 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
66 | - add_filter( 'pre_update_option', [$this, 'update_autoptimize_option_on_network'], 10, 3 ); |
|
67 | - } |
|
68 | - } |
|
65 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
66 | + add_filter( 'pre_update_option', [$this, 'update_autoptimize_option_on_network'], 10, 3 ); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - public static function update_autoptimize_option_on_network( $value, $option, $old_value ) { |
|
71 | - if( strpos( $option, 'autoptimize_' ) === 0 ) { |
|
72 | - if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
73 | - update_network_option( get_main_network_id(), $option, $value ); |
|
74 | - // Return old value, to stop update_option logic. |
|
75 | - return $old_value; |
|
76 | - } |
|
77 | - } |
|
78 | - return $value; |
|
79 | - } |
|
70 | + public static function update_autoptimize_option_on_network( $value, $option, $old_value ) { |
|
71 | + if( strpos( $option, 'autoptimize_' ) === 0 ) { |
|
72 | + if ( is_multisite() && is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
73 | + update_network_option( get_main_network_id(), $option, $value ); |
|
74 | + // Return old value, to stop update_option logic. |
|
75 | + return $old_value; |
|
76 | + } |
|
77 | + } |
|
78 | + return $value; |
|
79 | + } |
|
80 | 80 | } |
81 | 81 | new autoptimizeOption(); |
@@ -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() |