@@ -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,103 +12,103 @@ |
||
| 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 | - // This is always a network setting. |
|
| 45 | - if( 'autoptimize_enable_site_config' === $option ) { |
|
| 46 | - return get_network_option( get_main_network_id(), $option ); |
|
| 47 | - } |
|
| 44 | + // This is always a network setting. |
|
| 45 | + if( 'autoptimize_enable_site_config' === $option ) { |
|
| 46 | + return get_network_option( get_main_network_id(), $option ); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - // If the plugin is network activated and our per site setting is not on, use the network configuration. |
|
| 50 | - $configuration_per_site = get_network_option( get_main_network_id(), 'autoptimize_enable_site_config' ); |
|
| 51 | - if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) && 'on' !== $configuration_per_site ) { |
|
| 52 | - return get_network_option( get_main_network_id(), $option ); |
|
| 53 | - } |
|
| 49 | + // If the plugin is network activated and our per site setting is not on, use the network configuration. |
|
| 50 | + $configuration_per_site = get_network_option( get_main_network_id(), 'autoptimize_enable_site_config' ); |
|
| 51 | + if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) && 'on' !== $configuration_per_site ) { |
|
| 52 | + return get_network_option( get_main_network_id(), $option ); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - return get_option( $option, $default ); |
|
| 55 | + return get_option( $option, $default ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Saves the option in standalone and multisite instances. |
|
| 60 | - * |
|
| 61 | - * @param string $option Option name. Expected to not be SQL-escaped. |
|
| 62 | - * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. |
|
| 63 | - * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options, |
|
| 64 | - * `$autoload` can only be updated using `update_option()` if `$value` is also changed. |
|
| 58 | + /** |
|
| 59 | + * Saves the option in standalone and multisite instances. |
|
| 60 | + * |
|
| 61 | + * @param string $option Option name. Expected to not be SQL-escaped. |
|
| 62 | + * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. |
|
| 63 | + * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options, |
|
| 64 | + * `$autoload` can only be updated using `update_option()` if `$value` is also changed. |
|
| 65 | 65 | * Accepts 'yes'|true to enable or 'no'|false to disable. For non-existent options, |
| 66 | 66 | * the default value is 'yes'. Default null. |
| 67 | 67 | * @return bool False if value was not updated and true if value was updated. |
| 68 | - */ |
|
| 68 | + */ |
|
| 69 | 69 | public static function update_option( $option, $value, $autoload = null ) |
| 70 | 70 | { |
| 71 | 71 | |
| 72 | - // Ensure that is_plugin_active_for_network function is declared. |
|
| 73 | - self::maybe_include_plugin_functions(); |
|
| 74 | - $blog_id = get_current_blog_id(); |
|
| 72 | + // Ensure that is_plugin_active_for_network function is declared. |
|
| 73 | + self::maybe_include_plugin_functions(); |
|
| 74 | + $blog_id = get_current_blog_id(); |
|
| 75 | 75 | |
| 76 | - if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) && 1 === $blog_id ) { |
|
| 77 | - return update_network_option( get_main_network_id(), $option, $value ); |
|
| 78 | - } else { |
|
| 79 | - return update_option( $option, $value, $autoload ); |
|
| 80 | - } |
|
| 76 | + if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) && 1 === $blog_id ) { |
|
| 77 | + return update_network_option( get_main_network_id(), $option, $value ); |
|
| 78 | + } else { |
|
| 79 | + return update_option( $option, $value, $autoload ); |
|
| 80 | + } |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Use the pre_update_option filter to check if the option to be saved if from autoptimize and |
|
| 85 | - * in that case, take care of multisite case. |
|
| 86 | - */ |
|
| 87 | - public static function check_multisite_on_saving_options() |
|
| 83 | + /** |
|
| 84 | + * Use the pre_update_option filter to check if the option to be saved if from autoptimize and |
|
| 85 | + * in that case, take care of multisite case. |
|
| 86 | + */ |
|
| 87 | + public static function check_multisite_on_saving_options() |
|
| 88 | 88 | { |
| 89 | - // Ensure that is_plugin_active_for_network function is declared. |
|
| 90 | - self::maybe_include_plugin_functions(); |
|
| 91 | - $blog_id = get_current_blog_id(); |
|
| 89 | + // Ensure that is_plugin_active_for_network function is declared. |
|
| 90 | + self::maybe_include_plugin_functions(); |
|
| 91 | + $blog_id = get_current_blog_id(); |
|
| 92 | 92 | |
| 93 | - if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) && 1 === $blog_id ) { |
|
| 94 | - add_filter( 'pre_update_option', [$this, 'update_autoptimize_option_on_network'], 10, 3 ); |
|
| 95 | - } |
|
| 96 | - } |
|
| 93 | + if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) && 1 === $blog_id ) { |
|
| 94 | + add_filter( 'pre_update_option', [$this, 'update_autoptimize_option_on_network'], 10, 3 ); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - public static function update_autoptimize_option_on_network( $value, $option, $old_value ) { |
|
| 99 | - if( strpos( $option, 'autoptimize_' ) === 0 ) { |
|
| 98 | + public static function update_autoptimize_option_on_network( $value, $option, $old_value ) { |
|
| 99 | + if( strpos( $option, 'autoptimize_' ) === 0 ) { |
|
| 100 | 100 | |
| 101 | - // Ensure that is_plugin_active_for_network function is declared. |
|
| 102 | - self::maybe_include_plugin_functions(); |
|
| 103 | - $blog_id = get_current_blog_id(); |
|
| 101 | + // Ensure that is_plugin_active_for_network function is declared. |
|
| 102 | + self::maybe_include_plugin_functions(); |
|
| 103 | + $blog_id = get_current_blog_id(); |
|
| 104 | 104 | |
| 105 | - if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) && 1 === $blog_id ) { |
|
| 106 | - update_network_option( get_main_network_id(), $option, $value ); |
|
| 107 | - // Return old value, to stop update_option logic. |
|
| 108 | - return $old_value; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - return $value; |
|
| 112 | - } |
|
| 105 | + if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) && 1 === $blog_id ) { |
|
| 106 | + update_network_option( get_main_network_id(), $option, $value ); |
|
| 107 | + // Return old value, to stop update_option logic. |
|
| 108 | + return $old_value; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + return $value; |
|
| 112 | + } |
|
| 113 | 113 | } |
| 114 | 114 | new autoptimizeOption(); |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | public function run() |
| 98 | 98 | { |
| 99 | 99 | if ( is_admin() ) { |
| 100 | - if ( 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_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(); |
@@ -877,9 +877,9 @@ discard block |
||
| 877 | 877 | ); |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | - public function registersettings() { |
|
| 881 | - register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' ); |
|
| 882 | - } |
|
| 880 | + public function registersettings() { |
|
| 881 | + register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' ); |
|
| 882 | + } |
|
| 883 | 883 | |
| 884 | 884 | public function add_imgopt_tab( $in ) |
| 885 | 885 | { |
@@ -492,7 +492,7 @@ |
||
| 492 | 492 | 'autoptimize_css_exclude', |
| 493 | 493 | 'autoptimize_html', |
| 494 | 494 | 'autoptimize_html_keepcomments', |
| 495 | - 'autoptimize_enable_site_config', |
|
| 495 | + 'autoptimize_enable_site_config', |
|
| 496 | 496 | 'autoptimize_js', |
| 497 | 497 | 'autoptimize_js_aggregate', |
| 498 | 498 | 'autoptimize_js_exclude', |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | { |
| 16 | 16 | if ( is_admin() ) { |
| 17 | 17 | // Add the admin page and settings. |
| 18 | - if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
| 19 | - add_action( 'network_admin_menu', array( $this, 'addmenu' ) ); |
|
| 20 | - } |
|
| 18 | + if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
| 19 | + add_action( 'network_admin_menu', array( $this, 'addmenu' ) ); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - add_action( 'admin_menu', array( $this, 'addmenu' ) ); |
|
| 22 | + add_action( 'admin_menu', array( $this, 'addmenu' ) ); |
|
| 23 | 23 | add_action( 'admin_init', array( $this, 'registersettings' ) ); |
| 24 | 24 | |
| 25 | 25 | // Set meta info. |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | return self::$instance; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - public function show_message() { |
|
| 63 | - ?> |
|
| 62 | + public function show_message() { |
|
| 63 | + ?> |
|
| 64 | 64 | <h1>Autoptimize enabled in network</h1> |
| 65 | 65 | <p>If you want to enable per site configutation for Autoptimize, please contact your network administrator.</p> |
| 66 | 66 | <?php |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | public function show() |
| 70 | 70 | { |
@@ -654,14 +654,14 @@ discard block |
||
| 654 | 654 | |
| 655 | 655 | public function addmenu() |
| 656 | 656 | { |
| 657 | - if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
| 658 | - $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show' ) ); |
|
| 659 | - } |
|
| 660 | - if ( ! is_multisite() || 'on' === autoptimizeOption::get_option('autoptimize_enable_site_config') ) { |
|
| 661 | - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show' ) ); |
|
| 662 | - } else { |
|
| 663 | - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_message' ) ); |
|
| 664 | - } |
|
| 657 | + if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) { |
|
| 658 | + $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show' ) ); |
|
| 659 | + } |
|
| 660 | + if ( ! is_multisite() || 'on' === autoptimizeOption::get_option('autoptimize_enable_site_config') ) { |
|
| 661 | + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show' ) ); |
|
| 662 | + } else { |
|
| 663 | + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_message' ) ); |
|
| 664 | + } |
|
| 665 | 665 | |
| 666 | 666 | add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) ); |
| 667 | 667 | add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) ); |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | public function registersettings() { |
| 683 | 683 | register_setting( 'autoptimize', 'autoptimize_html' ); |
| 684 | 684 | register_setting( 'autoptimize', 'autoptimize_html_keepcomments' ); |
| 685 | - register_setting( 'autoptimize', 'autoptimize_enable_site_config' ); |
|
| 685 | + register_setting( 'autoptimize', 'autoptimize_enable_site_config' ); |
|
| 686 | 686 | register_setting( 'autoptimize', 'autoptimize_js' ); |
| 687 | 687 | register_setting( 'autoptimize', 'autoptimize_js_aggregate' ); |
| 688 | 688 | register_setting( 'autoptimize', 'autoptimize_js_exclude' ); |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | static $config = array( |
| 742 | 742 | 'autoptimize_html' => 0, |
| 743 | 743 | 'autoptimize_html_keepcomments' => 0, |
| 744 | - 'autoptimize_enable_site_config' => 0, |
|
| 744 | + 'autoptimize_enable_site_config' => 0, |
|
| 745 | 745 | 'autoptimize_js' => 0, |
| 746 | 746 | 'autoptimize_js_aggregate' => 1, |
| 747 | 747 | 'autoptimize_js_exclude' => 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js', |
@@ -33,12 +33,12 @@ discard block |
||
| 33 | 33 | public function run() |
| 34 | 34 | { |
| 35 | 35 | if ( is_admin() ) { |
| 36 | - if ( 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_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 | { |