thisclass = $thisclass; } public function get_optimizations() { $public_opts = $this->get_public_optimizations(); $private_opts = $this->get_private_optimizations(); return array_merge($public_opts, $private_opts); } protected function get_public_optimizations() { $thisclass = $this->thisclass; return [ 'page_cache' => [ 'slug' => 'page_cache', 'name' => 'Page Caching with W3 Total Cache', 'plugin' => 'W3 Total Cache', 'configured' => false, 'description' => 'Utilize W3 Total Cache to make the site faster by caching pages as static content. Cache: a copy of rendered dynamic pages will be saved by the server so that the next user does not need to wait for the server to generate another copy.', 'is_configured' => function (&$item) use (&$thisclass) { $w3tc = $thisclass->get_w3tc_config(); if ($w3tc['pgcache.enabled']) { $item['configured'] = true; $permalink_structure = get_option('permalink_structure'); $vars = []; if ($w3tc['pgcache.engine'] == 'apc') { if ($permalink_structure == '') { $vars['pgcache.engine'] = 'file'; } else { $vars['pgcache.engine'] = 'file_generic'; } } else { if ($permalink_structure == '' && $w3tc['pgcache.engine'] != 'file') { $vars['pgcache.engine'] = 'file'; } elseif ($permalink_structure != '' && $w3tc['pgcache.engine'] == 'file') { $vars['pgcache.engine'] = 'file_generic'; } } if (count($vars) != 0) { $thisclass->update_w3tc($vars); } $thisclass->set_install_status('page_cache', true); } else { $thisclass->set_install_status('page_cache', false); } }, 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix', 'disable' => function () use (&$thisclass) { $thisclass->disable_w3tc_page_cache(); }, 'enable' => function () use (&$thisclass) { $thisclass->enable_w3tc_page_cache(); } ], 'db_cache' => [ 'slug' => 'db_cache', 'name' => 'DB Caching with W3 Total Cache', 'plugin' => 'W3 Total Cache', 'configured' => false, 'description' => 'Speed up the site by storing the responses of common database queries in a cache.', 'is_configured' => function (&$item) use (&$thisclass) { $w3tc = $thisclass->get_w3tc_config(); if ($w3tc['dbcache.enabled']) { $vars = []; $item['configured'] = true; if (class_exists('W3_Config')) { if (class_exists('WooCommerce')) { if (array_search('_wc_session_', $w3tc['dbcache.reject.sql']) === false) { $vars['dbcache.reject.sql'] = $w3tc['dbcache.reject.sql']; $vars['dbcache.reject.sql'][] = '_wc_session_'; } } } if (count($vars) != 0) { $thisclass->update_w3tc($vars); } $thisclass->set_install_status('db_cache', true); } else { $thisclass->set_install_status('db_cache', false); } }, 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix', 'disable' => function () use (&$thisclass) { $thisclass->disable_w3tc_db_cache(); }, 'enable' => function () use (&$thisclass) { $thisclass->enable_w3tc_db_cache(); } ], 'object_cache' => [ 'slug' => 'object_cache', 'name' => 'Object Caching with W3 Total Cache', 'plugin' => 'W3 Total Cache', 'configured' => false, 'description' => 'Store a copy of widgets and menu bars in cache to reduce the time it takes to render pages.', 'is_configured' => function (&$item) use (&$thisclass) { $w3tc = $thisclass->get_w3tc_config(); if ($w3tc['objectcache.enabled']) { $item['configured'] = true; $thisclass->set_install_status('object_cache', true); } else { $thisclass->set_install_status('object_cache', false); } }, 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix', 'disable' => function () use (&$thisclass) { $thisclass->disable_w3tc_object_cache(); }, 'enable' => function () use (&$thisclass) { $thisclass->enable_w3tc_object_cache(); } ], 'browser_cache' => [ 'slug' => 'browser_cache', 'name' => 'Browser Caching with W3 Total Cache', 'plugin' => 'W3 Total Cache', 'configured' => false, 'description' => 'Add Rules to the web server to tell the visitor's browser to store a copy of static files to reduce the load time pages requested after the first page is loaded.', 'is_configured' => function (&$item) use (&$thisclass) { $w3tc = $thisclass->get_w3tc_config(); if ($w3tc['browsercache.enabled']) { $item['configured'] = true; $thisclass->set_install_status('browser_cache', true); } else { $thisclass->set_install_status('browser_cache', false); } }, 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix', 'disable' => function () use (&$thisclass) { $thisclass->disable_w3tc_browser_cache(); }, 'enable' => function () use (&$thisclass) { $thisclass->enable_w3tc_browser_cache(); } ], 'minify' => [ 'name' => 'Minify HTML Pages', 'slug' => 'minify', 'plugin' => 'W3 Total Cache', 'configured' => false, 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix', 'description' => 'Removes extra spaces,tabs and line breaks in the HTML to reduce the size of the files sent to the user.', 'is_configured' => function (&$item) use (&$thisclass) { $w3tc = $thisclass->get_w3tc_config(); if ($w3tc['minify.enabled'] && $w3tc['minify.html.enable']) { $item['configured'] = true; $thisclass->set_install_status('minify-html', true); } else { $thisclass->set_install_status('minify-html', false); } }, 'enable' => function () use (&$thisclass) { $thisclass->enable_html_minify(); }, 'disable' => function () use (&$thisclass) { $thisclass->disable_html_minify(); } ], 'css_minify' => [ 'name' => 'Minify CSS Files', 'slug' => 'css_minify', 'plugin' => 'W3 Total Cache', 'configured' => false, 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix', 'description' => 'Makes your site faster by condensing css files into a single downloadable file and by removing extra space in CSS files to make them smaller.', 'is_configured' => function (&$item) use (&$thisclass) { $w3tc = $thisclass->get_w3tc_config(); if ($w3tc['minify.css.enable']) { $item['configured'] = true; $thisclass->set_install_status('minify-css', true); } else { $thisclass->set_install_status('minify-css', false); } }, 'enable' => function () use (&$thisclass) { $thisclass->update_w3tc([ 'minify.css.enable' => true, 'minify.enabled' => true, 'minify.auto' => 0, 'minify.engine' => 'file' ]); }, 'disable' => function () use (&$thisclass) { $thisclass->update_w3tc([ 'minify.css.enable' => false, 'minify.auto' => 0 ]); } ], 'js_minify' => [ 'name' => 'Minify JS Files', 'slug' => 'js_minify', 'plugin' => 'W3 Total Cache', 'configured' => false, 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix', 'description' => 'Makes your site faster by condensing JavaScript files into a single downloadable file and by removing extra space in JavaScript files to make them smaller.', 'is_configured' => function (&$item) use (&$thisclass) { $w3tc = $thisclass->get_w3tc_config(); if ($w3tc['minify.js.enable']) { $item['configured'] = true; $thisclass->set_install_status('minify-js', true); } else { $thisclass->set_install_status('minify-js', false); } }, 'enable' => function () use (&$thisclass) { $thisclass->update_w3tc([ 'minify.js.enable' => true, 'minify.enabled' => true, 'minify.auto' => 0, 'minify.engine' => 'file' ]); }, 'disable' => function () use (&$thisclass) { $thisclass->update_w3tc([ 'minify.js.enable' => false, 'minify.auto' => 0 ]); } ], 'gzip' => [ 'name' => 'Gzip Compression Enabled', 'slug' => 'gzip', 'plugin' => 'W3 Total Cache', 'configured' => false, 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix', 'description' => 'Makes your site significantly faster by compressing all text files to make them smaller.', 'is_configured' => function (&$item) use (&$thisclass) { $w3tc = $thisclass->get_w3tc_config(); if ($w3tc['browsercache.other.compression']) { $item['configured'] = true; $thisclass->set_install_status('gzip', true); } else { $thisclass->set_install_status('gzip', false); } }, 'enable' => function () use (&$thisclass) { $thisclass->update_w3tc([ 'browsercache.other.compression' => true, 'browsercache.html.compression' => true, 'browsercache.cssjs.compression' => true ]); }, 'disable' => function () use (&$thisclass) { $thisclass->update_w3tc([ 'browsercache.other.compression' => false, 'browsercache.html.compression' => false, 'browsercache.cssjs.compression' => false ]); } ], 'htaccess' => [ 'name' => 'Deny Direct Access to Configuration Files and Comment Form', 'slug' => 'htaccess', 'plugin' => 'A2 Optimized', 'configured' => false, 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-the-a2-optimized-plugin', 'description' => 'Protects your configuration files by generating a Forbidden error to web users and bots when trying to access WordPress configuration files.
Also prevents POST requests to the site not originating from a user on the site.
note: if you are using a plugin to allow remote posts and comments, disable this option.', 'is_configured' => function (&$item) use (&$thisclass) { $htaccess = file_get_contents(ABSPATH . '.htaccess'); if (strpos($htaccess, '# BEGIN WordPress Hardening') === false) { if ($thisclass->get_deny_direct() == true) { $thisclass->set_deny_direct(false); } //make sure the basic a2-optimized rules are present $thisclass->set_install_status('htaccess-deny-direct-access', false); } else { if ($thisclass->get_deny_direct() == false) { $thisclass->set_deny_direct(true); } $item['configured'] = true; $thisclass->set_install_status('htaccess-deny-direct-access', true); } }, 'enable' => function () use (&$thisclass) { $thisclass->set_deny_direct(true); $thisclass->write_htaccess(); }, 'disable' => function () use (&$thisclass) { $thisclass->set_deny_direct(false); $thisclass->write_htaccess(); } ], 'lock' => [ 'name' => 'Lock Editing of Plugins and Themes from the WP Admin', 'slug' => 'lock', 'plugin' => 'A2 Optimized', 'configured' => false, 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-the-a2-optimized-plugin', 'description' => 'Prevents exploits that use the built in editing capabilities of the WP Admin', 'is_configured' => function (&$item) use (&$thisclass) { $wpconfig = file_get_contents(ABSPATH . 'wp-config.php'); if (strpos($wpconfig, '// BEGIN A2 CONFIG') === false) { if ($thisclass->get_lockdown() == true) { $thisclass->get_lockdown(false); } $thisclass->set_install_status('lock-editing', false); } else { if ($thisclass->get_lockdown() == false) { $thisclass->set_lockdown(true); } $item['configured'] = true; $thisclass->set_install_status('lock-editing', true); } }, 'enable' => function () use (&$thisclass) { $thisclass->set_lockdown(true); $thisclass->write_wp_config(); }, 'disable' => function () use (&$thisclass) { $thisclass->set_lockdown(false); $thisclass->write_wp_config(); } ], 'wp-login' => [ 'name' => 'Login URL Change', 'slug' => 'wp-login', 'premium' => true, 'plugin' => 'Rename wp-login.php', 'configured' => false, 'kb' => 'http://www.a2hosting.com/kb/security/application-security/wordpress-security#a-namemethodRenameLoginPageaMethod-3.3A-Change-the-WordPress-login-URL', 'description' => '

Change the URL of your login page to make it harder for bots to find it to brute force attack.

', 'is_configured' => function () { return false; } ], 'captcha' => [ 'name' => 'reCAPTCHA on comments and login', 'plugin' => 'reCAPTCHA', 'slug' => 'captcha', 'premium' => true, 'configured' => false, 'description' => 'Decreases spam and increases site security by adding a CAPTCHA to comment forms and the login screen. Without a CAPTCHA, bots will easily be able to post comments to you blog or brute force login to your admin panel.', 'is_configured' => function () { return false; } ], 'images' => [ 'name' => 'Compress Images on Upload', 'plugin' => 'EWWW Image Optimizer', 'slug' => 'images', 'premium' => true, 'configured' => false, 'description' => 'Makes your site faster by compressing images to make them smaller.', 'is_configured' => function () { return false; } ], 'turbo' => [ 'name' => 'Turbo Web Hosting', 'slug' => 'turbo', 'configured' => false, 'premium'=>true, 'description' => ' ', 'is_configured' => function () { return false; } ], 'memcached' => [ 'name' => 'Memcached Database and Object Cache', 'slug' => 'memcached', 'configured' => false, 'premium'=>true, 'description' => ' ', 'is_configured' => function () { return false; } ] ]; } protected function get_private_optimizations() { if (class_exists('A2_Optimized_Private_Optimizations')) { $a2opt_priv = new A2_Optimized_Private_Optimizations(); return $a2opt_priv->get_optimizations($this->thisclass); } else { return []; } } public function get_advanced() { $public_opts = $this->get_public_advanced(); $private_opts = $this->get_private_advanced(); return array_merge($public_opts, $private_opts); } protected function get_public_advanced() { $thisclass = $this->thisclass; return [ 'gtmetrix' => [ 'slug' => 'gtmetrix', 'name' => 'GTmetrix', 'plugin' => 'GTmetrix', 'plugin_slug' => 'gtmetrix-for-wordpress', 'file' => 'gtmetrix-for-wordpress/gtmetrix-for-wordpress.php', 'configured' => false, 'partially_configured' => false, 'required_options' => ['gfw_options' => ['authorized']], 'description' => '

Plugin that actively keeps track of your WP install and sends you alerts if your site falls below certain criteria. The GTMetrix plugin requires an account with gtmetrix.com

Use this plugin only if your site is experiencing issues with slow load times.
The GTMetrix plugin will slow down your site.

', 'not_configured_links' => [], 'configured_links' => [ 'Configure GTmetrix' => 'admin.php?page=gfw_settings', 'GTmetrix Tests' => 'admin.php?page=gfw_tests', ], 'partially_configured_links' => [ 'Configure GTmetrix' => 'admin.php?page=gfw_settings', 'GTmetrix Tests' => 'admin.php?page=gfw_tests', ], 'partially_configured_message' => 'Click "Configure GTmetrix" to enter your GTmetrix Account Email and GTmetrix API Key.', 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/optimizing-wordpress-with-w3-total-cache-and-gtmetrix', 'is_configured' => function (&$item) use (&$thisclass) { $gfw_options = get_option('gfw_options'); if (is_plugin_active($item['file']) && isset($gfw_options['authorized']) && $gfw_options['authorized'] == 1) { $item['configured'] = true; $thisclass->set_install_status('gtmetrix', true); } elseif (is_plugin_active($item['file'])) { $item['partially_configured'] = true; } else { $thisclass->set_install_status('gtmetrix', false); } }, 'enable' => function ($slug) use (&$thisclass) { $item = $thisclass->get_advanced_optimizations(); $item = $item[$slug]; if (!isset($thisclass->plugin_list[$item['file']])) { $thisclass->install_plugin($item['plugin_slug']); } if (!is_plugin_active($item['file'])) { $thisclass->activate_plugin($item['file']); } }, 'disable' => function ($slug) use (&$thisclass) { $item = $thisclass->get_advanced_optimizations(); $item = $item[$slug]; $thisclass->deactivate_plugin($item['file']); } ], 'P3' => [ 'slug' => 'P3', 'name' => 'P3 (Plugin Performance Profiler)', 'description' => '

See which plugins are slowing down your site. This plugin creates a performance report for your site.

Use this plugin only if your site is experiencing issues with slow load times.
The P3 plugin will slow down your site.

', 'plugin' => 'P3 Profiler', 'plugin_slug' => 'p3-profiler', 'file' => 'p3-profiler/p3-profiler.php', 'configured' => false, 'configured_links' => [ 'Test Performance' => 'tools.php?page=p3-profiler', ], 'kb' => 'http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/debugging-wordpress-with-p3-profiler', 'is_configured' => function (&$item) use (&$thisclass) { if (is_plugin_active($item['file'])) { $item['configured'] = true; $thisclass->set_install_status('P3', true); } else { $thisclass->set_install_status('P3', false); } }, 'enable' => function ($slug) use (&$thisclass) { $item = $thisclass->get_advanced_optimizations(); $item = $item[$slug]; if (!isset($thisclass->plugin_list[$item['file']])) { $thisclass->install_plugin($item['plugin_slug']); } if (!is_plugin_active($item['file'])) { $thisclass->activate_plugin($item['file']); } }, 'disable' => function ($slug) use (&$thisclass) { $item = $thisclass->get_advanced_optimizations(); $item = $item[$slug]; $thisclass->deactivate_plugin($item['file']); } ], 'cloudflare' => [ 'slug' => 'cloudflare', 'name' => 'CloudFlare', 'premium'=>true, 'description' => '

CloudFlare is a free global CDN and DNS provider that can speed up and protect any site online.

CloudFlare CDN
Distribute your content around the world so it's closer to your visitors (speeding up your site).
CloudFlare optimizer
Web pages with ad servers and third party widgets load snappy on both mobile and computers.
CloudFlare security
Protect your website from a range of online threats from spammers to SQL injection to DDOS.
CloudFlare analytics
Get insight into all of your website's traffic including threats and search engine crawlers.
Host with A2 Hosting to take advantage of one click CloudFlare configuration.
', 'configured' => false, 'is_configured' => function () { return false; }, 'not_configured_links' => ['Host with A2'=>'https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized'] ] ]; } protected function get_private_advanced() { if (class_exists('A2_Optimized_Private_Optimizations')) { $a2opt_priv = new A2_Optimized_Private_Optimizations(); return $a2opt_priv->get_advanced($this->thisclass); } else { return []; } } public function get_warnings() { $public_opts = $this->get_public_warnings(); $private_opts = $this->get_private_warnings(); return array_merge($public_opts, $private_opts); } protected function get_public_warnings() { return [ 'Bad WP Options' => [ 'posts_per_page' => [ 'title' => 'Recent Post Limit', 'description' => 'The number of recent posts per page is set greater than five. This could be slowing down page loads.', 'type' => 'numeric', 'threshold_type' => '>', 'threshold' => 5, 'config_url' => admin_url() . 'options-reading.php' ], 'posts_per_rss' => [ 'title' => 'RSS Post Limit', 'description' => 'The number of posts from external feeds is set greater than 5. This could be slowing down page loads.', 'type' => 'numeric', 'threshold_type' => '>', 'threshold' => 5, 'config_url' => admin_url() . 'options-reading.php' ], 'show_on_front' => [ 'title' => 'Recent Posts showing on home page', 'description' => 'Speed up your home page by selecting a static page to display.', 'type' => 'text', 'threshold_type' => '=', 'threshold' => 'posts', 'config_url' => admin_url() . 'options-reading.php' ], 'permalink_structure' => [ 'title' => 'Permalink Structure', 'description' => 'To fully optimize page caching with "Disk Enhanced" mode:
you must set a permalink structure other than "Default".', 'type' => 'text', 'threshold_type' => '=', 'threshold' => '', 'config_url' => admin_url() . 'options-permalink.php' ] ], 'Advanced Warnings' => [ 'themes' => [ 'is_warning' => function () { $themes = wp_get_themes(); switch (count($themes)) { case 1: return false; case 2: $theme = wp_get_theme(); if ($theme->get('Template') != '') { return false; } } return true; }, 'title' => 'Unused Themes', 'description' => 'One or more unused themes are installed. Unused themes should be deleted. For more information read the Wordpress.org Codex on WordPress Housekeeping', 'config_url' => admin_url() . 'themes.php' ], 'a2_hosting' => [ 'title' => 'Not Hosted with A2 Hosting', 'description' => 'Get faster page load times and more optimizations when you host with A2 Hosting.', 'is_warning' => function () { if (is_dir('/opt/a2-optimized')) { return false; } return true; }, 'config_url' => 'https://www.a2hosting.com/wordpress-hosting?utm_source=A2%20Optimized&utm_medium=Referral&utm_campaign=A2%20Optimized' ] ], 'Bad Plugins' => [ 'wp-super-cache', 'wp-file-cache', 'wordfence', 'wp-db-backup', //'WP DB Manager', //'BackupWordPress', //'Broken Link Checker', //'MyReviewPlugin', //'LinkMan', //'Google XML Sitemaps', //'Fuzzy SEO Booster', //'Tweet Blender', //'Dynamic Related Posts', //'SEO Auto Links & Related Posts', //'Yet Another Related Posts Plugin', //'Similar Posts', //'Contextual Related Posts', ] ]; } protected function get_private_warnings() { if (class_exists('A2_Optimized_Private_Optimizations')) { $a2opt_priv = new A2_Optimized_Private_Optimizations(); return $a2opt_priv->get_warnings($this->thisclass); } else { return []; } } }