options = $options; $this->init(); } /** * Start the engine running * * @return void */ private function init() { add_filter( 'adminoptimizer_settings_navtab', [ $this, 'add_settings_navtab' ] ); add_filter( 'adminoptimizer_settings_sections', [ $this, 'settings_fields' ] ); if ( ! empty( $this->options['enable_db_cleaner'] ) ) { $this->modules['db_cleaner'] = new DB_Cleaner(); } if ( ! empty( $this->options['enable_heartbeat_control'] ) ) { $this->modules['heartbeat'] = new Heartbeat_Control(); } if ( ! empty( $this->options['disable_emojis'] ) ) { remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); add_filter( 'wp_resource_hints', [ $this, 'disable_emojis_remove_dns_prefetch' ], 10, 2 ); } if ( ! empty( $this->options['disable_jquery_migrate'] ) ) { add_action( 'wp_default_scripts', [ $this, 'dequeue_jquery_migrate' ] ); } if ( ! empty( $this->options['disable_404_redirect'] ) ) { add_filter( 'do_redirect_guess_404_permalink', '__return_false' ); } if ( ! empty( $this->options['remove_oembed'] ) ) { remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); } } /** * Add settings navtab * * @param array $nav_tab List of nav tabs. * * @return array */ public function add_settings_navtab( $nav_tab ) { if ( empty( $nav_tab['performance'] ) ) { $nav_tab['performance'] = [ 'title' => __( 'Performance', 'admin-optimizer' ), 'slug' => 'adminoptim-performance-settings', ]; } return $nav_tab; } /** * List of Settings fields * * @param array $fields Settings fields. * * @return array */ public function settings_fields( $fields ) { if ( empty( $fields['performance-module'] ) ) { $fields['performance-module'] = [ 'id' => 'adminoptimizer-performance-module-settings', 'title' => __( 'Modules', 'admin-optimizer' ), 'description' => '', 'menu_slug' => 'adminoptim-performance-settings', 'option_name' => MODULES_OPTION, 'args' => [ 'before_section' => '
', 'after_section' => '
', 'section_class' => 'module', ], 'fields' => [ [ 'type' => 'slider-checkbox', 'title' => __( 'Database Cleaner (Pro option)', 'admin-optimizer' ), 'id' => 'enable-db-cleaner', 'name' => 'enable_db_cleaner', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Schedule regular optimization and cleaning up of the WP database to improve the performance of the site. (Comes with Pro options)%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Heartbeat Control', 'admin-optimizer' ), 'id' => 'enable-heartbeat-control', 'name' => 'enable_heartbeat_control', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Modify the interval of the WordPress heartbeat API to reduce CPU load on the server.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], ], ]; } if ( empty( $fields['performance-tweaks'] ) ) { $fields['performance-tweaks'] = [ 'id' => 'adminoptimizer-performance-tweaks-settings', 'title' => __( 'Tweaks', 'admin-optimizer' ), 'description' => __( 'Activate with a single click. No additional configuration required.', 'admin-optimizer' ), 'menu_slug' => 'adminoptim-performance-settings', 'option_name' => MODULES_OPTION, 'args' => [ 'before_section' => '
', 'after_section' => '
', 'section_class' => 'tweaks', ], 'fields' => [ [ 'type' => 'slider-checkbox', 'title' => __( 'Disable Emojis', 'admin-optimizer' ), 'id' => 'disable-emojis', 'name' => 'disable_emojis', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Disable emoji support and remove emoji scripts and styles from your site.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Disable jQuery Migrate', 'admin-optimizer' ), 'id' => 'disable-jquery-migrate', 'name' => 'disable_jquery_migrate', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Remove script bloat from your site.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Disable 404 URL Redirect', 'admin-optimizer' ), 'id' => 'disable-404-redirect', 'name' => 'disable_404_redirect', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'By default, WordPress will attempt to guess a redirect URL for a 404 request. This module disable the guessing and return the 404 page without performing a redirect.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], [ 'type' => 'slider-checkbox', 'title' => __( 'Remove oEmbed links', 'admin-optimizer' ), 'id' => 'remove-oembed', 'name' => 'remove_oembed', // translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag. 'label' => sprintf( __( 'Remove links used for embedding your content on other sites.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ), ], ], ]; } return $fields; } /** * Remove emoji CDN hostname from DNS prefetching hints. * * @param array $urls URLs to print for resource hints. * @param string $relation_type The relation type the URLs are printed for. * @return array Difference between the two arrays. */ public function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) { if ( 'dns-prefetch' === $relation_type ) { /** This filter is documented in wp-includes/formatting.php */ $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $urls = array_diff( $urls, [ $emoji_svg_url ] ); } return $urls; } /** * Disable jQuery Migrate * * @param \WP_Scripts $scripts WP_Scripts instance. * * @return void */ public function dequeue_jquery_migrate( $scripts ) { if ( ! is_admin() && ! empty( $scripts->registered['jquery'] ) ) { $scripts->registered['jquery']->deps = array_diff( $scripts->registered['jquery']->deps, [ 'jquery-migrate' ] ); } } }