Linux server.edchosting.com 4.18.0-553.79.1.lve.el7h.x86_64 #1 SMP Wed Oct 15 16:34:46 UTC 2025 x86_64
LiteSpeed
Server IP : 75.98.162.185 & Your IP : 216.73.216.163
Domains :
Cant Read [ /etc/named.conf ]
User : goons4good
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
opt /
a2-optimized /
wordpress /
Delete
Unzip
Name
Size
Permission
Date
Action
A2ReCaptcha
[ DIR ]
drwxr-xr-x
2025-04-30 04:08
bin
[ DIR ]
drwxr-xr-x
2025-04-30 04:08
LSCWP_Default_Configuration.data
7.4
KB
-rw-r--r--
2025-04-29 15:41
Optimizations.php
241
B
-rw-r--r--
2025-04-29 15:41
am-bundle.php
1010
B
-rw-r--r--
2025-04-29 15:41
class.A2_Optimized_Private_Optimizations.php
36.09
KB
-rw-r--r--
2025-04-29 15:41
class.A2_Optimized_Private_Optimizations_v3.php
35.31
KB
-rw-r--r--
2025-04-29 15:41
cron-job.php
2.39
KB
-rw-r--r--
2025-04-29 15:41
fix-w3tc.php
2.02
KB
-rw-r--r--
2025-04-29 15:41
hcaptcha_lib.php
2.1
KB
-rw-r--r--
2025-04-29 15:41
managedwp_functions.php
3.78
KB
-rw-r--r--
2025-04-29 15:41
opt-init-variables.txt
797
B
-rw-r--r--
2025-04-29 15:41
optimize.sh
12.29
KB
-rw-r--r--
2025-04-29 15:41
p2-wp-opt-v1.data
7.39
KB
-rw-r--r--
2025-04-29 15:41
p2-wp-opt-v1.sh
20.48
KB
-rwxr-xr-x
2025-04-29 15:41
pagespeed.php
3.2
KB
-rw-r--r--
2025-04-29 15:41
privkey
0
B
-rw-r--r--
2025-04-29 15:41
pubkey
0
B
-rw-r--r--
2025-04-29 15:41
recaptcha_autoload.php
1.14
KB
-rw-r--r--
2025-04-29 15:41
recaptchalib.php
9.36
KB
-rw-r--r--
2025-04-29 15:41
recaptchalib_v2.php
2.95
KB
-rw-r--r--
2025-04-29 15:41
turbo-default.txt
7.39
KB
-rw-r--r--
2025-04-29 15:41
warp-imagick.json
940
B
-rw-r--r--
2025-04-29 15:41
wp-opt-v1.sh
41.12
KB
-rwxr-xr-x
2025-04-29 15:41
Save
Rename
<?php /* Workaround for Easy Hide Login Password Reset */ if (function_exists('easy_hide_login_hidden_field')) { add_action('lostpassword_form', 'easy_hide_login_hidden_field'); add_filter('admin_email_check_interval', '__return_false'); // Compatiblity fix for Easy Hide Login breaking when the user is prompted to confirm their email address on login. } function a2_easy_hide_login_lostpassword_redirect($lostpassword_redirect) { if (!function_exists('easy_hide_login_lostpassword_redirect')) { $EHL_slug = get_option('wpseh_l01gnhdlwp'); return 'wp-login.php?checkemail=confirm&redirect=false&' . $EHL_slug; } } add_filter( 'lostpassword_redirect', 'a2_easy_hide_login_lostpassword_redirect', 100, 1 ); /* Workarounds for Elementor / Easy Hide Login issues. This needs to run ASAP. When classes are instantiated is too late. During install we choose to not enable Easy Hide Login and set a flag. Right now, we check for that flag and re-enable that plugin and unset the flag. This should fix our new redirect issue as elementor has done what it needs to do and is no longer hijacking the login process. */ add_action( 'admin_init', function () { if (get_option('a2_enable_easyhidelogin') == 1) { $login_page = get_option('a2_login_page'); if (!$login_page) { $login_page = get_random_string(4); update_option('a2_login_page', $login_page); } update_option('wpseh_l01gnhdlwp', $login_page); activate_plugin('easy-hide-login/wp-hide-login.php'); delete_option('a2_enable_easyhidelogin'); } $private_opt = new A2_Optimized_Private_Optimizations; if ($private_opt->is_redis_supported() && !get_option('a2_declined_redis') && get_option('litespeed.conf.object-kind') != 1) { add_action('admin_notices', ['A2_Optimized_Private_Optimizations', 'prompt_user_for_redis_caching']); } if (!$private_opt->is_redis_supported() && is_plugin_active('litespeed-cache/litespeed-cache.php') && !get_option('a2_declined_memcached') && get_option('a2_object_cache_enabled') != 0 && get_option('litespeed.confg.object-kind') != 0) { add_action('admin_notices', ['A2_Optimized_Private_Optimizations', 'prompt_user_for_memcached_caching']); } if ($private_opt->maybe_display_quiccloud_notice()) { add_action('admin_notices', ['A2_Optimized_Private_Optimizations', 'prompt_user_for_quiccloud']); } if ($private_opt->maybe_display_recaptcha_notice()) { // Set the captcha provider to hcaptcha, we're past the deadline for users to choose to migrate update_option('a2_captcha_provider', 'hcaptcha'); } if (isset($_REQUEST['a2_action']) && isset($_REQUEST['_wpnonce'])) { switch ($_REQUEST['a2_action']) { case 'enable_redis_caching': if (wp_verify_nonce( $_REQUEST['_wpnonce'], 'a2opt-redis-enable' )) { $private_opt->enable_redis_object_cache(); } break; case 'decline_redis_caching': if (wp_verify_nonce( $_REQUEST['_wpnonce'], 'a2opt-redis-enable' )) { //set option so we don't see prompt again update_option('a2_declined_redis', 1); } break; case 'enable_memcached_caching': if (wp_verify_nonce( $_REQUEST['_wpnonce'], 'a2opt-memcached-enable' )) { $private_opt->enable_memcached(); } break; case 'decline_memcached_caching': if (wp_verify_nonce( $_REQUEST['_wpnonce'], 'a2opt-memcached-enable' )) { //set option so we don't see prompt again update_option('a2_declined_memcached', 1); } break; case 'decline_quiccloud': if (wp_verify_nonce( $_REQUEST['_wpnonce'], 'a2opt-quiccloud' )) { //set option so we don't see prompt again update_option('a2_declined_quiccloud', 1); } break; case 'hcaptcha_migrate': if (wp_verify_nonce( $_REQUEST['_wpnonce'], 'a2opt-hcaptcha' )) { //set option so we don't see prompt again update_option('a2_captcha_provider', 'hcaptcha'); } break; } } }, 1 ); function a2_admin_notice_incompatible_cache_plugins() { if (is_plugin_active( 'litespeed-cache/litespeed-cache.php' )) { $active_plugins = []; if (is_plugin_active( 'autoptimize/autoptimize.php' )) { $active_plugins[] = 'Autoptimize'; } if (is_plugin_active( 'w3-total-cache/w3-total-cache.php' )) { $active_plugins[] = 'W3 Total Cache'; } if (is_plugin_active( 'wp-smushit/wp-smushit.php' )) { $active_plugins[] = 'Smush'; } if (is_plugin_active( 'wp-optimize/wp-optimize.php' )) { $active_plugins[] = 'WP-Optimize'; } if (is_plugin_active( 'sg-cachepress/sg-cachepress.php' )) { $active_plugins[] = 'SG Optimizer'; } if ($active_plugins) { ?> <div class="notice notice-error is-dismissible"> <p>We have detected another active caching plugin that could interfere with TurboCache. We recommend disabling it to ensure your site runs as expected.</p> <p><?php echo implode(', ', $active_plugins); ?></p> </div> <?php } } } add_action( 'admin_notices', 'a2_admin_notice_incompatible_cache_plugins' ); function get_random_string($length) { $private_opt = new A2_Optimized_Private_Optimizations; return $private_opt->get_random_string($length); } if (is_admin()) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; class A2_Plugin_Installer_Skin extends Plugin_Installer_Skin { /* * Suppress normal upgrader feedback / output */ public function feedback($string, ...$args) { /* no output */ } public function error($string, ...$args) { /* no output */ } } } class A2_Optimized_Private_Optimizations { public function __construct() { $this->disable_elementor_redirect(); } private function disable_elementor_redirect() { add_action( 'admin_init', function () { if ( did_action( 'elementor/loaded' ) ) { remove_action( 'admin_init', [ \Elementor\Plugin::$instance->admin, 'maybe_redirect_to_getting_started' ] ); } }, 1 ); } public function get_optimizations() { $recaptcha_name = 'CAPTCHA on comments and login'; $recaptcha_desc = '<strong>Benefit:</strong> Decreases spam and increase your site’s security. <br /> <strong>How-it-works:</strong> Adds CAPTCHA to comment forms and login screens to deter bots from posting comments to your blog or brute force login - a hacking method that uses trial and error to crack passwords, login credentials, and encryption keys - to your admin panel.'; if ($this->is_a2_managed()) { $recaptcha_name = 'CAPTCHA on comments'; $recaptcha_desc = 'Decreases spam and increases site security by adding a CAPTCHA to comment forms. Without a CAPTCHA, bots will easily be able to post comments to your blog.'; } $recaptcha_custom = get_option('a2_recaptcha_usecustom'); $recaptcha_site_key = get_option('a2_recaptcha_sitekey'); $recaptcha_secret_key = get_option('a2_recaptcha_secretkey'); if ($recaptcha_custom == '1' && (!$recaptcha_site_key || !$recaptcha_secret_key)) { $recaptcha_desc .= "<br /><strong>Please generate reCaptcha keys for this site.</strong> <a href='https://www.a2hosting.com/kb/security/obtaining-google-recaptcha-site-key-and-secret-key/' target='_blank'>Google ReCAPTCHA | How To Get Site Key & Secret Key</a>"; } $hcaptcha_custom = get_option('a2_hcaptcha_usecustom'); $hcaptcha_site_key = get_option('a2_hcaptcha_sitekey'); $hcaptcha_secret_key = get_option('a2_hcaptcha_secretkey'); if ($hcaptcha_custom == '1' && (!$hcaptcha_site_key || !$rhcaptcha_secret_key)) { $recaptcha_desc .= '<br /><strong>Please generate hCaptcha keys for this site.</strong>'; } $wp_cron_desc = '<strong>Benefit:</strong> Speeds up your website’s front-end performance.<br /> <strong>How it works:</strong> Cron jobs are used to schedule tasks on your WordPress site at fixed times, dates, or intervals. Examples would be scheduling a post to publish, checking for updates, or a backup plugin running on a predefined schedule. This happens when a user visits your site.<br /> <strong>What does this impact:</strong> It will move WordPress cron tasks to the system cron.'; if ($this->get_cron_command('doing_wp_cron')) { $wp_cron_desc .= '<br /><br />If you would like to further customize when your cron task runs please refer to our KB article on <a href="https://www.a2hosting.com/kb/cpanel/advanced-features/cron-jobs" target="_blank">Cron Jobs</a>'; } if ($this->wp_config_cron_disabled() && !$this->get_cron_command('doing_wp_cron')) { $wp_cron_desc .= '<br /><br /><strong>WARNING:</strong> You have disabled the WordPress cron in your wp-config.php file, but do not currently have a system cron job setup. You can create one automatically by enabling this feature.'; } $optimizations = [ 'captcha' => [ 'name' => $recaptcha_name, 'slug' => 'captcha', 'premium' => true, 'configured' => $this->is_active('captcha'), 'category' => 'security', 'description' => $recaptcha_desc, ], 'cron_disable' => [ 'name' => 'Use System Cron Instead of WordPress Cron', 'slug' => 'cron_disable', 'premium' => true, 'configured' => $this->is_active('cron_disable'), 'category' => 'performance', 'description' => $wp_cron_desc, ], 'compress_images' => [ 'name' => 'Compress Images on Upload', 'slug' => 'compress_images', 'premium' => true, 'configured' => $this->is_active('compress_images'), 'category' => 'performance', ], 'hide_login' => [ 'name' => 'Login URL Change', 'slug' => 'hide_login', 'premium' => true, 'configured' => $this->is_active('hide_login'), 'category' => 'security', ], 'turbo' => [ 'name' => 'Turbo Web Hosting', 'slug' => 'turbo', 'premium' => true, 'configured' => $this->is_active('turbo'), 'compatibility' => ['caching'], 'category' => 'performance', ] ]; if (is_plugin_active( 'litespeed-cache/litespeed-cache.php' )) { $optimizations['a2_page_cache_gzip'] = [ 'slug' => 'a2_page_cache_gzip', 'name' => 'Gzip Compression Enabled', 'category' => 'performance', 'configured' => true, ]; $optimizations['a2_page_cache_minify_html'] = [ 'slug' => 'a2_page_cache_minify_html', 'name' => 'Minify HTML Pages', 'category' => 'performance', 'configured' => true, ]; $optimizations['a2_page_cache_minify_jscss'] = [ 'slug' => 'a2_page_cache_minify_jscss', 'name' => 'Minify CSS and Javascript', 'category' => 'performance', 'configured' => true, ]; $optimizations['a2_object_cache'] = [ 'name' => 'Object Cache', 'category' => 'performance', 'slug' => 'a2_object_cache', 'configured' => $this->is_active('a2_object_cache_litespeed'), 'premium' => true, ]; } /* If the webserver is nginx, we want to recommend that the Nginx Helper plugin is active */ if ($this->is_nginx()) { $optimizations['a2_nginx'] = [ 'slug' => 'a2_nginx', 'name' => 'Nginx Helper', 'configured' => $this->is_active('nginx'), 'description' => 'Purge the Nginx cache (FastCGI, Proxy, uWSGI) automatically when content changes or manually within WordPress.', ]; } if (!$this->is_turbo_available()) { // We're on a A2 Server, but not a litespeed server. Even if the user installs the litespeed plugin, we should not reflect that Turbo is active. $optimizations['turbo'] = [ 'configured' => false, 'premium' => true, 'disabled' => '1', ]; } return $optimizations; } /*** * check if a given optimization is currently active */ private function is_active($optimization, $value_only = true) { $result = [ 'value' => false, 'is_warning' => false, 'current' => '' ]; switch ($optimization) { case 'captcha': if (get_option('A2_Optimized_Plugin_recaptcha') == '1') { $captcha_provider = get_option('a2_captcha_provider'); if (!$captcha_provider) { update_option('a2_captcha_provider', 'recaptcha'); } $result['value'] = true; } break; case 'cron_disable': if ($this->is_wp_cron_disabled()) { $result['value'] = true; } break; case 'compress_images': if (is_plugin_active('warp-imagick/index.php') || is_plugin_active('ewww-image-optimizer/ewww-image-optimizer.php')) { $result['value'] = true; } break; case 'hide_login': if (is_plugin_active('easy-hide-login/wp-hide-login.php')) { $result['value'] = true; } break; case 'turbo': if (is_plugin_active('litespeed-cache/litespeed-cache.php') && $this->is_turbo_available()) { $result['value'] = true; } break; case 'a2_object_cache': if (wp_using_ext_object_cache()) { $result['value'] = true; } break; case 'a2_object_cache_litespeed': if (wp_using_ext_object_cache() || get_option('litespeed.conf.object') == 1) { $result['value'] = true; } break; case 'nginx': if (is_plugin_active('nginx-helper/nginx-helper.php')) { $result['value'] = true; } break; } $result['is_warning'] = !$result['value']; if ($value_only) { return $result['value']; } else { return $result; } } public function apply_optimization($optimization, $value) { switch ($optimization) { case 'captcha': if ($value == 'true') { $captcha_provider = get_option('a2_captcha_provider'); if (!$captcha_provider) { update_option('a2_captcha_provider', 'hcaptcha'); } update_option('A2_Optimized_Plugin_recaptcha', 1); } else { update_option('A2_Optimized_Plugin_recaptcha', 0); } break; case 'cron_disable': if ($value == 'true') { if (!$this->is_wp_cron_disabled()) { // Only try to enable if it's disabled $minute = rand(0, 59); // random minute so all sites aren't going off at the same time $this->update_wp_config('wp_cron', 'enable'); $this->disable_cron('doing_wp_cron'); // remove any other existing cron tasks $this->enable_cron($minute, '*', '*', '*', '*', 'wget -q -O - ' . get_site_url() . '/wp-cron.php?doing_wp_cron >/dev/null 2>&1'); } } else { $this->update_wp_config('wp_cron', 'disable'); $this->disable_cron('doing_wp_cron'); } break; case 'compress_images': if ($value == 'true') { $this->install_plugin('ewww-image-optimizer', true); } else { if (is_plugin_active('warp-imagick/index.php')) { $this->uninstall_plugin('warp-imagick/index.php', false); } if (is_plugin_active('ewww-image-optimizer/ewww-image-optimizer.php')) { $this->uninstall_plugin('ewww-image-optimizer/ewww-image-optimizer.php', false); } } break; case 'hide_login': if ($value == 'true') { $this->activate_hide_login(); } else { $this->uninstall_plugin('easy-hide-login/wp-hide-login.php'); delete_option('wpseh_l01gnhdlwp'); } break; case 'turbo': if ($value == 'true') { $this->install_plugin('litespeed-cache', true); } else { $this->uninstall_plugin('litespeed-cache/litespeed-cache.php', false); } break; case 'nginx': if ($value == 'true') { $this->install_plugin('nginx-helper', true); update_option('rt_wp_nginx_helper_options', $this->get_default_nginx_settings()); } else { $nginx_helper_settings = get_option('rt_wp_nginx_helper_options'); $nginx_helper_settings['enable_purge'] = 0; update_option('rt_wp_nginx_helper_options', $nginx_helper_settings); } break; } } public function get_advanced() { return []; } public function get_warnings() { return []; } /* Is this a (plesk) MWP server? */ protected function is_a2_managed() { return file_exists('/opt/a2-optimized/wordpress/a2managed'); } /* Is this an nginx server? */ protected function is_nginx() { $webserver = strtolower($_SERVER['SERVER_SOFTWARE']); if (strpos($webserver, 'nginx') === false) { return false; } else { return true; } } /* Default settings for purging nginx cache */ protected function get_default_nginx_settings() { $settings_json = '{"enable_purge":"1","cache_method":"enable_fastcgi","purge_method":"get_request","enable_map":null,"enable_log":null,"log_level":"INFO","log_filesize":"5","enable_stamp":null,"purge_homepage_on_edit":"1","purge_homepage_on_del":"1","purge_archive_on_edit":"1","purge_archive_on_del":"1","purge_archive_on_new_comment":null,"purge_archive_on_deleted_comment":null,"purge_page_on_mod":"1","purge_page_on_new_comment":"1","purge_page_on_deleted_comment":"1","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:","purge_url":"","redis_enabled_by_constant":0,"smart_http_expire_form_nonce":"f2de3ffc41"}'; return json_decode($settings_json, true); } protected function is_turbo_available() { if (defined( 'LITESPEED_ALLOWED')) { return true; } } /** * is wp cron disabled * * check if everything is setup for this site to use system cron * */ protected function is_wp_cron_disabled() { if (is_dir('/opt/a2-optimized')) { // Check wp-config.php if ($this->wp_config_cron_disabled() === false) { return false; } // Check user cron if ($this->get_cron_command('doing_wp_cron') === false) { return false; } return true; } return false; } /** * enable cron * * use the cpanel live API v2 to create a cron if called from within * cpanel or use crontab if called from command line. * command is not sanitized, make sure it is well written and * sanitized if it uses variables from an external source. * * @param int|string $minute * @param int|string $hour * @param int|string $day * @param int|string $month * @param int|string $weekday * @param string $command */ private function enable_cron($minute, $hour, $day, $month, $weekday, $command) { $jobs = $this->get_cron_jobs(); $jobs[] = "{$minute} {$hour} {$day} {$month} {$weekday} $command"; $this->save_cron_jobs($jobs); } /** * wp config cron disabled * * check if the disable wp cron constant is present in wp-config.php * */ private function wp_config_cron_disabled() { $wpconfig = file_get_contents(ABSPATH . 'wp-config.php'); if (strpos($wpconfig, "define('DISABLE_WP_CRON', true)")) { return true; } return false; } /** * disable cron * * search the crontab and remove a cron * * @param string $search */ private function disable_cron($search) { $jobs = $this->get_cron_jobs(); foreach ($jobs as $line) { if (strpos($line, $search) && strpos($line, get_site_url() . '/wp-cron.php?')) { unset($jobs[array_search($line, $jobs)]); } } $this->save_cron_jobs($jobs); } /** * save cronjobs * * save cronjobs passed in from jobs array * * @param array $jobs */ private function save_cron_jobs($jobs) { $job_string = implode("\n", $jobs); $hash = md5(rand() . time()); $file_name = '/tmp/cron-' . $hash . '.txt'; if (file_exists($file_name)) { unlink($file_name); } file_put_contents($file_name, $job_string . "\n"); shell_exec('cat ' . $file_name . ' | crontab -'); unlink($file_name); } /** * get cron tabs * * get all the cron jobs for this user */ private function get_cron_jobs() { exec('crontab -l', $jobs); return $jobs; } /** * get cron command * * search for a cron that has been set and return the string representing it. * this pulls from the users crontab * * @param string $search * @return string */ private function get_cron_command($search) { $jobs = $this->get_cron_jobs(); foreach ($jobs as $i => $line) { if (!(strpos($line, $search) === false) && strpos($line, get_site_url() . '/wp-cron.php?')) { return $line; } } return false; } /** * update wp config * * utility function to add and remove items from wp-config.php * * @param string $option_name * @param string $action */ private function update_wp_config($option_name, $action = 'disable') { copy(ABSPATH . 'wp-config.php', ABSPATH . 'wp-config.bak-a2.php'); $wpconfig = file_get_contents(ABSPATH . 'wp-config.php'); $a2_config = ''; if ($option_name == 'wp_cron') { if ($action == 'enable') { // add line to wp-config $a2_config = <<<PHP // BEGIN A2 CRON DISABLE define('DISABLE_WP_CRON', true); // END A2 CRON DISABLE PHP; } if ($action == 'disable') { $a2_config = <<<PHP // BEGIN A2 CRON DISABLE define('DISABLE_WP_CRON', false); // END A2 CRON DISABLE PHP; } } $wpconfig = file_get_contents(ABSPATH . 'wp-config.php'); $pattern = "/[\r\n]*[\/][\/] BEGIN A2 CRON DISABLE.*[\/][\/] END A2 CRON DISABLE[\r\n]*/msU"; $wpconfig = preg_replace($pattern, '', $wpconfig); $wpconfig = str_replace('<?php', "<?php{$a2_config}", $wpconfig); //Write the rules to wp-config $fh = fopen(ABSPATH . 'wp-config.php', 'w+'); fwrite($fh, $wpconfig); fclose($fh); } /* Determine if this site can use Redis */ public function is_redis_supported() { if (file_exists('/opt/redis/conf/example.conf') && class_exists('Redis')) { return true; } /* Redis not supported */ update_option('a2_optimized_objectcache_type', 'memcached'); // Change our type to Memcached to avoid issues if Redis is set return false; } /* Steps to enable Redis object caching */ public function enable_redis_object_cache() { // Create .redis.on file touch('/home/' . $this->get_username() . '/.redis.on'); // install plugin if (!is_plugin_active('litespeed-cache/litespeed-cache.php')) { $this->install_plugin('litespeed-cache', true); } // configure plugin $socket_path = $this->get_redis_socket(); update_option('a2_optimized_objectcache_type', 'redis'); update_option('a2_optimized_redis_server', $socket_path); update_option('litespeed.conf.object', 1); // Enable object cache update_option('litespeed.conf.object-kind', 1); // Kind is redis update_option('litespeed.conf.object-host', $socket_path); // Server host update_option('litespeed.conf.object-port', '0'); // Port is 0 for socket connections update_option('a2_object_cache_enabled', 1); // Flag that we have this enabled for A2 Optimized } public function enable_memcached() { // Create .redis.on file touch('/home/' . $this->get_username() . '/.memcached.on'); // install plugin if (!is_plugin_active('litespeed-cache/litespeed-cache.php')) { $this->install_plugin('litespeed-cache', true); } // configure plugin $socket_path = $this->get_memcached_socket(); update_option('a2_optimized_objectcache_type', 'memcached'); update_option('a2_optimized_memcached_server', $socket_path); update_option('litespeed.conf.object', 1); // Enable object cache update_option('litespeed.conf.object-kind', 0); // Kind is redis update_option('litespeed.conf.object-host', $socket_path); // Server host update_option('litespeed.conf.object-port', '0'); // Port is 0 for socket connections update_option('a2_object_cache_enabled', 1); // Flag that we have this enabled for A2 Optimized } /* Hopefully get the username of this account */ public function get_username() { $file_path = get_home_path(); $path_parts = explode('/', $file_path); $username = $path_parts[2]; return $username; } /* Get the redis socket path */ public function get_redis_socket() { $user = $this->get_username(); return "/home/$user/.redis/redis.sock"; } public function get_memcached_socket() { $user = $this->get_username(); return "/opt/memcached/run/$user/memcached-1.sock"; } /* Display alert to user if Redis caching is available */ public static function prompt_user_for_redis_caching() { $nonce = wp_create_nonce('a2opt-redis-enable'); ?> <div class="notice notice-info"> <p>Hey, we've detected that Redis Object Caching is supported for your site. Would you like to set it up?</p> <p><a href="<?php echo get_admin_url(); ?>/admin.php?page=a2-optimized&_wpnonce=<?php echo esc_attr( $nonce ); ?>&a2_action=enable_redis_caching" class="button button-primary">Yes, please!</a> <a href="<?php echo get_admin_url(); ?>/admin.php?page=a2-optimized&_wpnonce=<?php echo esc_attr( $nonce ); ?>&a2_action=decline_redis_caching" class="button button-secondary">No, thank you</a></p> </div> <?php } /* Display alert to user if Redis caching is available */ public static function prompt_user_for_memcached() { $nonce = wp_create_nonce('a2opt-memcached-enable'); ?> <div class="notice notice-info"> <p>Hey, we've detected that Memcached is supported for your site. Would you like to set it up?</p> <p><a href="<?php echo get_admin_url(); ?>/admin.php?page=a2-optimized&_wpnonce=<?php echo esc_attr( $nonce ); ?>&a2_action=enable_memcached_caching" class="button button-primary">Yes, please!</a> <a href="<?php echo get_admin_url(); ?>/admin.php?page=a2-optimized&_wpnonce=<?php echo esc_attr( $nonce ); ?>&a2_action=decline_memcached_caching" class="button button-secondary">No, thank you</a></p> </div> <?php } /* Display alert to user if quic.cloud is available */ public static function prompt_user_for_quiccloud() { setcookie('litespeed_tab', 'auto_setup', time() + 3600); // Set cookie so Litespeed plugin redirects to proper tab during process $nonce = wp_create_nonce('a2opt-quiccloud'); ?> <div class="notice notice-info"> <p>Uh-oh. Looks like you don’t have QUIC.cloud set up! To get the best speeds possible with our A2 Optimized plugin, we suggest using the QUIC.cloud CDN. Learn how to install it <a href="https://www.a2hosting.com/kb/add-on-services/quic.cloud/using-the-quic-cloud-cdn-with-wordpress" target="_blank">here</a>.</p> <p><a href="<?php echo get_admin_url(); ?>admin.php?page=litespeed-cdn#auto_setup" class="button button-primary">Get Started</a> <a href="<?php echo get_admin_url(); ?>admin.php?page=a2-optimized&_wpnonce=<?php echo esc_attr( $nonce ); ?>&a2_action=decline_quiccloud" class="button button-secondary">Not right now</a></p> </div> <?php } /* Should the notice for quic.cloud be displayed? */ public function maybe_display_quiccloud_notice() { global $pagenow; $lsc_quiccloud = get_option('litespeed.conf.cdn-quic'); $declined_quiccloud = get_option('a2_declined_quiccloud'); $no_display_pages = ['edit.php', 'edit-tags.php', 'themes.php']; $current_page = ''; $current_action = ''; if (isset($_GET['page'])) { $current_page = $_GET['page']; } if (isset($_GET['a2_action'])) { $current_action = $_GET['a2_action']; } if ( is_plugin_active('litespeed-cache/litespeed-cache.php') && //litespeed is active current_user_can('manage_options') && // user is an admin $lsc_quiccloud != '1' && // quic.cloud is not currently enabled !$declined_quiccloud && // not previously declined !in_array($pagenow, $no_display_pages) && // Not currently on a page where we don't want to display the notice $current_page != 'litespeed-cdn' && // Not currently on quiccloud config page $current_action != 'decline_quiccloud') { // Not just declined quiccloud return true; } } /* Should the notice for recaptcha be displayed? */ public function maybe_display_recaptcha_notice() { $current_captcha = get_option('a2_captcha_provider'); $recaptcha_custom = get_option('a2_recaptcha_usecustom'); $recaptcha_site_key = get_option('a2_recaptcha_sitekey'); $recaptcha_secret_key = get_option('a2_recaptcha_secretkey'); $current_page = ''; $current_action = ''; if (isset($_GET['page'])) { $current_page = $_GET['page']; } if (isset($_GET['a2_action'])) { $current_action = $_GET['a2_action']; } if ( current_user_can('manage_options') && // user is an admin get_option('A2_Optimized_Plugin_recaptcha') == '1' && // captcha optimization is enabled $current_captcha != 'hcaptcha' && // captcha provider is not hcaptcha (!$recaptcha_custom || $recaptcha_custom == '') && // User has not set up custom recaptcha keys (!$recaptcha_site_key || $recaptcha_site_key == '') && (!$recaptcha_secret_key || $recaptcha_secret_key == '') && $current_action != 'hcaptcha_migrate') { // Not just tried to fix the issue return true; } } private function install_plugin($slug, $activate = false) { require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); $api = plugins_api( 'plugin_information', [ 'slug' => $slug, 'fields' => [ 'short_description' => false, 'requires' => false, 'sections' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'compatibility' => false, 'homepage' => false, 'donate_link' => false, ], ] ); $skin = new A2_Plugin_Installer_Skin( ['api' => $api] ); $response = true; $found = false; if ($slug == 'a2-w3-total-cache') { $file = 'a2-w3-total-cache/a2-w3-total-cache.php'; } $plugins = get_plugins(); foreach ($plugins as $file => $plugin) { if ($plugin['Name'] == $api->name) { $found = true; } } if (!$found) { $upgrader = new Plugin_Upgrader( $skin ); if ($slug == 'a2-w3-total-cache') { $api->download_link = 'https://wp-plugins.a2hosting.com/wp-content/uploads/rkv-repo/a2-w3-total-cache.zip'; } if ($slug == 'a2-warp-imagick') { $api->download_link = 'https://wp-plugins.a2hosting.com/wp-content/uploads/rkv-repo/warp-imagick.zip'; } // Plugin_Upgrader will output html and make our json invalid. Catch the output here and discard. ob_start(); $response = $upgrader->install($api->download_link); ob_end_clean(); } if ($activate) { $plugins = get_plugins(); foreach ($plugins as $file => $plugin) { if ($plugin['Name'] == $api->name) { $this->activate_plugin($file); } } } return $response; } private function activate_plugin($file) { require_once(ABSPATH . 'wp-admin/includes/plugin.php'); activate_plugin($file); } private function deactivate_plugin($file) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; if (is_plugin_active($file)) { deactivate_plugins($file); } } private function uninstall_plugin($file, $delete = false) { require_once(ABSPATH . 'wp-admin/includes/plugin.php'); require_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); $this->deactivate_plugin($file); uninstall_plugin($file); if ($delete) { delete_plugins([$file]); } } private function activate_hide_login() { $this->install_plugin('easy-hide-login', true); if (get_option('a2_login_page') === false) { if (get_option('wpseh_l01gnhdlwp') === false || get_option('wpseh_l01gnhdlwp') == 'root') { // 'root' is set as the login page by default when 'easy-hide-login' is installed, we want to change that $length = 4; $rwl_page = $this->get_random_string($length); update_option('a2_login_page', $rwl_page); update_option('wpseh_l01gnhdlwp', $rwl_page); } else { update_option('a2_login_page', get_option('wpseh_l01gnhdlwp')); } } else { update_option('wpseh_l01gnhdlwp', get_option('a2_login_page')); } delete_option('rwl_redirect'); //Send Email with new login address $email_to = get_bloginfo('admin_email'); $site_url = get_site_url(); $new_admin_url = get_option('a2_login_page'); $subject = 'WordPress Login URL Changed'; $message = "You have changed your login for:\n\n" . $site_url . "\n\nYou can now log in to the administrator account at the following URL:\n\n" . $site_url . '?' . $new_admin_url . "\n\n - A2 Optimized"; wp_mail( $email_to, $subject, $message); } public function get_random_string($length) { $output = ''; $valid_chars = 'abcdefghijklmnopqrstuvwxyz'; $num_valid_chars = strlen($valid_chars); for ($i = 0; $i < $length; $i++) { $random_pick = mt_rand(1, $num_valid_chars); $random_char = $valid_chars[$random_pick - 1]; $output .= $random_char; } return $output; } public function get_baseline_results() { $response = [ 'name' => 'A2 Hosting', 'explanation' => 'Avg. of all Plans', 'php' => [ 'benchmark' => [ 'math' => '0.178', 'string' => '0.296', 'loop' => '0.368', 'ifelse' => '0.493', ], 'total' => '2.19', ], 'mysql' => '1.95', 'wordpress_db' => [ 'time' => '2.32', 'queries_per_second' => '862', ], 'filesystem' => '7', ]; return $response; } public function apply_recommendation($action) { $allowed_actions = [ 'find_conflicts', 'fix_conflicts' ]; if (!in_array($action, $allowed_actions)) { return 'Invalid action'; } switch ($action) { case 'find_conflicts': $found = $this->plugin_theme_conflicts(false); if ($found > 0) { WP_CLI::warning('The above plugins and themes need to have their settings updated'); } else { WP_CLI::success('No plugin or theme conflicts found'); } break; case 'fix_conflicts': $found = $this->plugin_theme_conflicts(true); if ($found == 0) { WP_CLI::success('No plugin or theme conflicts found'); } break; } } private function plugin_theme_conflicts($apply = false) { $response = 0; /* Plugins */ /* Jetpack modules */ if (is_plugin_active( 'jetpack/jetpack.php' )) { $to_disable = ['photon', 'photon-cdn', 'lazy-images', 'google-fonts']; $modules = Jetpack::get_available_modules(); foreach ($modules as $module_slug) { if (in_array($module_slug, $to_disable) && Jetpack::is_module_active($module_slug)) { if ($apply) { Jetpack::deactivate_module($module_slug); WP_CLI::success( 'Jetpack module ' . $module_slug . ' has been Disabled'); } else { WP_CLI::warning( 'Jetpack module ' . $module_slug . ' should be Disabled'); } $response++; } } } /* Elementor */ if (is_plugin_active( 'elementor/elementor.php' )) { $elementor_options = [ // Option names and expected value 'elementor_css_print_method' => 'internal', 'elementor_font_display' => 'auto', 'elementor_load_fa4_shim' => 'yes', 'elementor_experiment-e_optimized_css_loading' => 'active', 'elementor_experiment-e_font_icon_svg' => 'active', 'elementor_experiment-e_dom_optimization' => 'active', 'elementor_experiment-e_optimized_assets_loading' => 'active', 'elementor_experiment-additional_custom_breakpoints' => 'active', ]; foreach ($elementor_options as $option => $value) { if (!get_option($option) || get_option($option) != $value) { if ($apply) { update_option($option, $value); WP_CLI::success( $option . ' - Changed to ' . $value ); } else { WP_CLI::warning( $option . ' - Should be set to ' . $value ); } $response++; } } } /* Plugins to disable */ $plugins = [ 'wp-optimize/wp-optimize.php', 'w3-total-cache/w3-total-cache.php', 'wp-fastest-cache/wpFastestCache.php', 'wp-super-cache/wp-cache.php', 'hummingbird-performance/wp-hummingbird.php', 'wp-rocket/wp-rocket.php', 'comet-cache/comet-cache.php', 'autoptimize/autoptimize.php', 'wp-smushit/wp-smush.php', 'imagify/imagify.php', 'ewww-image-optimizer/ewww-image-optimizer.php', 'shortpixel-image-optimiser/wp-shortpixel.php', ]; foreach ($plugins as $plugin) { if (is_plugin_active($plugin)) { if ($apply) { deactivate_plugins($plugin); WP_CLI::success( $plugin . ' has been Disabled'); } else { WP_CLI::warning( $plugin . ' should be Disabled'); } $response++; } } /* Themes */ /* GeneratePress */ if (get_template() == 'generatepress') { $gp_settings = get_option('generate_settings'); if ($gp_settings['dynamic_css_cache'] == true) { if ($apply) { $gp_settings['dynamic_css_cache'] = false; update_option('generate_settings', $gp_settings); WP_CLI::success( 'GeneratePress - dynamic_css_cache has been Disabled' ); } else { WP_CLI::warning( 'GeneratePress - dynamic_css_cache should be Disabled' ); } $response++; } } /* Return output */ return $response; } }