settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http ); if ( $this->is_ao_meta_settings_active() ) { $meta_box = new autoptimizeMetabox(); } } // Adds the Autoptimize Toolbar to the Admin bar. // (we load outside the is_admin check so it's also displayed on the frontend toolbar). $toolbar = new autoptimizeToolbar(); } /** * Instantiates aoconfig. * * @return autoptimizeConfig */ static public function instance() { // Only one instance. if ( null === self::$instance ) { self::$instance = new autoptimizeConfig(); } return self::$instance; } public function show_network_message() { ?>

ao_admin_tabs(); ?>

ao_admin_tabs(); ?>
  • get( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/>
    ' . esc_html__( '(deprecated)', 'autoptimize' ) . ''; ?>
  • get( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/>
    ' . esc_html__( '(deprecated)', 'autoptimize' ) . ''; ?>
    ', '', '', '' ); ?>
  • get( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/>
  • 0 ) { $details = ', ~' . $ao_cache_size . ' total'; } // translators: Kilobytes + timestamp shown. printf( esc_html__( '%1$s files, totaling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, wp_date( 'H:i', $ao_stat_arr[2] ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date } ?>
  • get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) { $_min_excl_class = 'hidden'; } ?>

get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
%s', esc_html__( 'Settings' ) ); array_unshift( $links, $settings_link ); } else { // 2.8 and higher. // If it's us, add the link. if ( $file === $plugin ) { $newlink = array( sprintf( '%s', esc_html__( 'Settings' ) ) ); $links = array_merge( $links, $newlink ); } } return $links; } /** * Provides the default options. * * @return array */ public static function get_defaults() { static $config = array( 'autoptimize_html' => 1, 'autoptimize_html_keepcomments' => 0, 'autoptimize_html_minify_inline' => 0, 'autoptimize_enable_site_config' => 1, 'autoptimize_js' => 1, 'autoptimize_js_aggregate' => 0, 'autoptimize_js_defer_not_aggregate' => 1, 'autoptimize_js_defer_inline' => 1, 'autoptimize_js_exclude' => '', 'autoptimize_js_trycatch' => 0, 'autoptimize_js_justhead' => 0, 'autoptimize_js_include_inline' => 0, 'autoptimize_js_forcehead' => 0, 'autoptimize_css' => 1, 'autoptimize_css_aggregate' => 0, 'autoptimize_css_exclude' => '', 'autoptimize_css_justhead' => 0, 'autoptimize_css_include_inline' => 0, 'autoptimize_css_defer' => 0, 'autoptimize_css_defer_inline' => '', 'autoptimize_css_inline' => 0, 'autoptimize_css_datauris' => 0, 'autoptimize_cdn_url' => '', 'autoptimize_cache_nogzip' => 1, 'autoptimize_optimize_logged' => 1, 'autoptimize_optimize_checkout' => 0, 'autoptimize_minify_excluded' => 1, 'autoptimize_cache_fallback' => 1, 'autoptimize_enable_meta_ao_settings' => 1, 'autoptimize_installed_before_compatibility' => 0, ); return $config; } /** * Returns default option values for autoptimizeExtra. * * @return array */ public static function get_ao_extra_default_options() { $defaults = array( 'autoptimize_extra_checkbox_field_1' => '0', 'autoptimize_extra_checkbox_field_0' => '0', 'autoptimize_extra_radio_field_4' => '1', 'autoptimize_extra_text_field_2' => '', 'autoptimize_extra_text_field_3' => '', 'autoptimize_extra_text_field_7' => '', 'autoptimize_extra_checkbox_field_8' => '0', ); return $defaults; } /** * Returns default option values for autoptimizeExtra. * * @return array */ public static function get_ao_imgopt_default_options() { $defaults = array( 'autoptimize_imgopt_checkbox_field_1' => '0', // imgopt off. 'autoptimize_imgopt_select_field_2' => '2', // quality glossy. 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off. 'autoptimize_imgopt_checkbox_field_4' => '0', // avif off (might be removed). 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty. 'autoptimize_imgopt_text_field_6' => '', // optimization exclusions empty. 'autoptimize_imgopt_number_field_7' => '2', // lazy load from nth image (0 = lazyload all). ); return $defaults; } /** * Returns preload JS onload handler. * * @param string $media media attribute value the JS to use. * * @return string */ public static function get_ao_css_preload_onload( $media = 'all' ) { $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" ); return $preload_onload; } public function get( $key ) { if ( ! is_array( $this->config ) ) { // Default config. $config = self::get_defaults(); // Override with user settings. foreach ( array_keys( $config ) as $name ) { $conf = autoptimizeOptionWrapper::get_option( $name ); if ( false !== $conf ) { // It was set before! $config[ $name ] = $conf; } } // Save for next call. $this->config = apply_filters( 'autoptimize_filter_get_config', $config ); } if ( isset( $this->config[ $key ] ) ) { return $this->config[ $key ]; } return false; } private function get_futtta_feeds( $url ) { if ( $this->settings_screen_do_remote_http ) { $rss = fetch_feed( $url ); $maxitems = 0; if ( ! is_wp_error( $rss ) ) { $maxitems = $rss->get_item_quantity( 7 ); $rss_items = $rss->get_items( 0, $maxitems ); } ?> esc_html__( 'JS, CSS & HTML', 'autoptimize' ) ) ); $tab_content = ''; $tabs_count = count( $tabs ); if ( $tabs_count > 1 ) { if ( isset( $_GET['page'] ) ) { $current_id = $_GET['page']; } else { $current_id = 'autoptimize'; } $tab_content .= ''; } else { $tab_content = '
'; } return $tab_content; } /** * Returns true if in admin (and not in admin-ajax.php!) * * @return bool */ public static function is_admin_and_not_ajax() { return ( is_admin() && ! self::doing_ajax() ); } /** * Returns true if doing ajax. * * @return bool */ protected static function doing_ajax() { if ( function_exists( 'wp_doing_ajax' ) ) { return wp_doing_ajax(); } return ( defined( 'DOING_AJAX' ) && DOING_AJAX ); } /** * Returns true menu or tab is to be shown. * * @return bool */ public static function should_show_menu_tabs() { if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) || false === autoptimizeOptionWrapper::is_ao_active_for_network() ) { return true; } else { return false; } } /** * Returns the post meta AO settings for reuse in different optimizers. * * @param string $optim What optimization we need meta setting for. * * @return bool */ public static function get_post_meta_ao_settings( $optim ) { if ( ! autoptimizeConfig::is_ao_meta_settings_active() ) { // Per page/post settings not active, so always return true (as in; can be optimized). if ( in_array( $optim, apply_filters( 'autoptimize_filter_meta_inactive_return_false_for', array( 'ao_post_preload' ) ) ) ) { // but make sure to return false for text input. return false; } return true; } static $_meta_value = null; if ( null === $_meta_value ) { global $wp_query; if ( isset( $wp_query ) ) { $_meta_value = get_post_meta( get_the_ID(), 'ao_post_optimize', true ); } else { $_meta_value = false; } } // If autoptimize_post_optimize !== 'on' (except for ao_post_preload, which can have other values) then always return false as all is off. // fixme: need unit tests to ensure below logic is sane! if ( empty( $_meta_value ) || ! is_array( $_meta_value ) ) { // no metabox values so all optimizations are a go. if ( in_array( $optim, apply_filters( 'autoptimize_filter_meta_optim_nonbool', array( 'ao_post_preload' ) ) ) ) { // but make sure to return false for text input. return false; } return true; } else if ( array_key_exists( 'ao_post_optimize', $_meta_value ) && 'on' !== $_meta_value['ao_post_optimize'] ) { // ao entirely off for this page. return false; } else if ( in_array( $optim, apply_filters( 'autoptimize_filter_meta_optim_with_filters', array() ) ) ) { // if an $optim is registered as having a filter, apply filter and return that (default false). return apply_filters( 'autoptimize_filter_meta_filtered_optim', false, $optim, $_meta_value ); } else if ( array_key_exists( $optim, $_meta_value ) && empty( $_meta_value[ $optim ] ) ) { // sub-optimization off for this page. return false; } else if ( array_key_exists( $optim, $_meta_value ) && 'on' === $_meta_value[ $optim ] ) { // sub-optimization is explictly on. return true; } else if ( array_key_exists( $optim, $_meta_value ) && in_array( $optim, array( 'ao_post_preload' ) ) && ! empty( $_meta_value[ $optim ] ) ) { // a non-bool metabox optimization (currently only preload field), return value instead of bool. return $_meta_value[ $optim ]; } else if ( in_array( $optim, array( 'ao_post_preload' ) ) && ( ! array_key_exists( $optim, $_meta_value ) || empty( $_meta_value[ $optim ] ) ) ) { // a non-bool metabox optimization not found or empty, so returning false. return false; } else { // when in doubt "go" for optimization, but this should never happen? if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { error_log( 'AO meta box logic fallback; well, how did I get here? Maybe this helps: looking for ' . $optim . ' in ' . json_encode( $_meta_value ) ); } return true; } } /** * Are the post meta AO settings active (default: no)? * * @return bool */ public static function is_ao_meta_settings_active() { static $_meta_settings_active = null; if ( null === $_meta_settings_active ) { $_meta_settings_active = apply_filters( 'autoptimize_filter_enable_meta_ao_settings', autoptimizeOptionWrapper::get_option( 'autoptimize_enable_meta_ao_settings', '1' ) ); } return $_meta_settings_active; } }