From c47da889f3233485d22ae13e3833b58ac9fced75 Mon Sep 17 00:00:00 2001 From: thanghv Date: Thu, 4 Apr 2024 21:48:33 +0700 Subject: [PATCH 1/9] Update for version 5.0.3 --- class/class-mainwp-backup.php | 32 +- class/class-mainwp-child-back-up-buddy.php | 10 +- class/class-mainwp-child-branding-render.php | 3 +- class/class-mainwp-child-branding.php | 3 +- class/class-mainwp-child-cache-purge.php | 69 +- class/class-mainwp-child-callable.php | 2 +- class/class-mainwp-child-keys-manager.php | 2 +- class/class-mainwp-child-misc.php | 4 +- class/class-mainwp-child-posts.php | 9 +- class/class-mainwp-child-stats.php | 26 +- class/class-mainwp-child-timecapsule.php | 4 +- class/class-mainwp-child-updates.php | 2 +- ...lass-mainwp-child-updraft-plus-backups.php | 11 +- class/class-mainwp-child-wp-rocket.php | 27 +- class/class-mainwp-clone-install.php | 6 +- class/class-mainwp-clone.php | 4 +- class/class-mainwp-custom-post-type.php | 4 +- class/class-mainwp-helper.php | 4 +- class/class-mainwp-system.php | 1 + class/class-mainwp-utility.php | 2 +- class/class-tar-archiver.php | 18 +- readme.txt | 1215 +---------------- 22 files changed, 211 insertions(+), 1247 deletions(-) diff --git a/class/class-mainwp-backup.php b/class/class-mainwp-backup.php index d6f61723..414f5931 100644 --- a/class/class-mainwp-backup.php +++ b/class/class-mainwp-backup.php @@ -231,7 +231,7 @@ public function create_full_backup( } elseif ( $this->check_zip_support() ) { $success = $this->create_zip_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); } elseif ( $this->check_zip_console() ) { - $success = $this->create_zip_console_full_backup(); + $success = $this->create_zip_console_full_backup(); // NOSONAR . } else { $success = $this->create_zip_pcl_full_backup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); } @@ -239,7 +239,7 @@ public function create_full_backup( return ( $success ) ? array( 'timestamp' => $timestamp, 'file' => $fileurl, - 'filesize' => filesize( $filepath ), + 'filesize' => filesize( $filepath ), // NOSONAR . ) : false; } @@ -265,7 +265,7 @@ public function backup_poll() { $dirs = MainWP_Helper::get_mainwp_dir( 'backup' ); $backupdir = $dirs[0]; - $result = glob( $backupdir . $backupFile . '*' ); + $result = glob( $backupdir . $backupFile . '*' ); // NOSONAR . // Check if archive, set $archiveFile = $file & break. $archiveFile = false; @@ -288,7 +288,7 @@ public function backup_poll() { $backupFile = 'dbBackup-' . $fileNameUID . '-*.sql.php'; $dirs = MainWP_Helper::get_mainwp_dir( 'backup' ); $backupdir = $dirs[0]; - $result = glob( $backupdir . $backupFile . '*' ); + $result = glob( $backupdir . $backupFile . '*' ); // NOSONAR . if ( 0 === count( $result ) ) { MainWP_Helper::write( array() ); @@ -598,12 +598,12 @@ public function backup_db( $fileName = '', $ext = 'zip' ) { $result = $this->create_backup_db( $filepath_prefix, $ext ); - MainWP_Helper::update_option( 'mainwp_child_last_db_backup_size', filesize( $result['filepath'] ) ); + MainWP_Helper::update_option( 'mainwp_child_last_db_backup_size', filesize( $result['filepath'] ) ); // NOSONAR . return ( ! $result ) ? false : array( 'timestamp' => $timestamp, 'file' => basename( $result['filepath'] ), - 'filesize' => filesize( $result['filepath'] ), + 'filesize' => filesize( $result['filepath'] ), // NOSONAR . ); } @@ -784,7 +784,7 @@ public function create_zip_full_backup( $return = $this->zip->close(); foreach ( $db_files as $db_file ) { - wp_delete_file( $db_file ); + wp_delete_file( $db_file ); // NOSONAR . } return true; @@ -937,7 +937,7 @@ public function copy_dir( $nodes, $excludes, $backupfolder, $excludenonwp ) { continue; } - copy( $node, str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated. + copy( $node, str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated - // NOSONAR . } } } @@ -1019,8 +1019,8 @@ public function create_zip_pcl_full_backup2( $filepath, $excludes, $addConfig, $ $this->copy_dir( $nodes, $excludes, $backupFolder, $excludenonwp, true ); foreach ( $db_files as $db_file ) { - copy( $db_file, $backupFolder . basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated. - wp_delete_file( $db_file ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated. + copy( $db_file, $backupFolder . basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated // NOSONAR . + wp_delete_file( $db_file ); // phpcs:ignore -- required to achieve desired results. Pull requests appreciated // NOSONAR. } unset( $nodes ); @@ -1128,7 +1128,7 @@ public function add_file_from_string_to_pcl_zip( $file, $str, $filepath ) { PCLZIP_OPT_ADD_PATH, $localpath ); - wp_delete_file( $tmpfilename ); + wp_delete_file( $tmpfilename ); // NOSONAR . if ( ! empty( $add ) ) { return true; } @@ -1160,13 +1160,13 @@ public function add_file_to_zipp( $path, $zipEntryName ) { $this->zipArchiveSizeCount += filesize( $path ); ++$this->gcCnt; - if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) { + if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) { // NOSONAR . ++$this->zipArchiveFileCount; $added = $this->zip->add_file( $path, $zipEntryName ); } else { ++$this->zipArchiveFileCount; - $this->testContent = file_get_contents( $path ); //phpcs:ignore WordPress.WP.AlternativeFunctions + $this->testContent = file_get_contents( $path ); //phpcs:ignore WordPress.WP.AlternativeFunctions -- // NOSONAR . if ( false === $this->testContent ) { return false; } @@ -1261,7 +1261,7 @@ public function create_backup_db( $filepath_prefix, $archiveExt = false, &$archi if ( file_exists( $currentfile ) ) { continue; } - $fh = fopen( $currentfile . '.tmp', 'w' ); + $fh = fopen( $currentfile . '.tmp', 'w' ); // NOSONAR . $protect_content_string = ''; @@ -1302,10 +1302,10 @@ public function create_backup_db( $filepath_prefix, $archiveExt = false, &$archi $rows = null; fflush( $fh ); fclose( $fh ); - rename( $currentfile . '.tmp', $currentfile ); + rename( $currentfile . '.tmp', $currentfile ); // NOSONAR . } - fclose( fopen( $filepath_prefix . '.sql', 'w' ) ); + fclose( fopen( $filepath_prefix . '.sql', 'w' ) ); // NOSONAR . $db_files[] = $filepath_prefix . '.sql'; $archivefilePath = null; diff --git a/class/class-mainwp-child-back-up-buddy.php b/class/class-mainwp-child-back-up-buddy.php index 3177f9d5..448cd3c0 100644 --- a/class/class-mainwp-child-back-up-buddy.php +++ b/class/class-mainwp-child-back-up-buddy.php @@ -950,7 +950,7 @@ public function delete_backup( $type = 'default', $subsite_mode = false ) { $deleted_files = array(); foreach ( $item_ids as $item ) { if ( file_exists( \backupbuddy_core::getBackupDirectory() . $item ) ) { - if ( wp_delete_file( \backupbuddy_core::getBackupDirectory() . $item ) === true ) { + if ( wp_delete_file( \backupbuddy_core::getBackupDirectory() . $item ) === true ) { // NOSONAR . $deleted_files[] = $item; // Cleanup any related fileoptions files. @@ -1205,7 +1205,7 @@ public function zip_viewer() { $fileoptions_file = \backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '-filetree.txt'; // Purge cache if too old. - if ( file_exists( $fileoptions_file ) && ( ( time() - filemtime( $fileoptions_file ) ) > $max_cache_time ) ) { + if ( file_exists( $fileoptions_file ) && ( ( time() - filemtime( $fileoptions_file ) ) > $max_cache_time ) ) { // NOSONAR . if ( false === wp_delete_file( $fileoptions_file ) ) { $alerts[] = 'Error #456765545. Unable to wipe cached fileoptions file `' . $fileoptions_file . '`.'; } @@ -1910,7 +1910,7 @@ public function view_log() { return array( 'error' => 'Error #858733: Log file `' . $logFile . '` not found or access denied.' ); } - $lines = file_get_contents( $logFile ); //phpcs:ignore WordPress.WP.AlternativeFunctions + $lines = file_get_contents( $logFile ); //phpcs:ignore WordPress.WP.AlternativeFunctions -- // NOSONAR . $lines = explode( "\n", $lines ); ob_start(); ?> @@ -1938,7 +1938,7 @@ public function view_log() { Log file:
Last modified: ' . \pb_backupbuddy::$format->date( filemtime( $logFile ) ) . ' (' . \pb_backupbuddy::$format->time_ago( filemtime( $logFile ) ) . ' ago)'; + echo 'Last modified: ' . \pb_backupbuddy::$format->date( filemtime( $logFile ) ) . ' (' . \pb_backupbuddy::$format->time_ago( filemtime( $logFile ) ) . ' ago)'; // NOSONAR . ?>

'Disabled', - 'action' => 'SUCCESS', + 'status' => 'Disabled', + 'action' => 'SUCCESS', + 'do_purge' => $do_purge, ); } @@ -454,11 +459,14 @@ public function wp_optimize_auto_purge_cache() { // Clear Cache. $purge = self::wp_optimize_purge_cache(); + // Purge Minified files. + $minify = self::wp_optimize_purge_minify(); + // Preload cache. $preload = self::wp_optimize_preload_cache(); // Check response & return results. - if ( true === $purge && true === $preload ) { + if ( ( true === $purge && true === $preload ) || ( true === $minify && true === $purge && true === $preload ) ) { update_option( 'mainwp_cache_control_last_purged', time() ); return $this->purge_result( $success_message, 'SUCCESS' ); @@ -485,33 +493,47 @@ public function wp_optimize_preload_cache() { } /** - * Check if WP Optimize is installed and cache is enabled. + * Purge WP Optimize minified files. + * + * @return bool True if successful, false if not. */ - public function wp_optimize_activated_check() { + public function wp_optimize_purge_minify() { if ( class_exists( '\WP_Optimize' ) ) { - $cache = WP_Optimize()->get_page_cache(); - if ( ! $cache->is_enabled() ) { - return false; - } + $cache = \WP_Optimize()->get_page_cache()->purge(); + + // $cache returns true if successful, false if not. + return true; } + return false; } /** - * Preload WP Optimize cache after purge. + * Purge WP Optimize cache. * * @return bool True if successful, false if not. */ public function wp_optimize_purge_cache() { - if ( class_exists( '\WP_Optimize_Cache_Commands' ) && class_exists( '\WP_Optimize_Page_Cache_Preloader' ) ) { + if ( class_exists( '\WP_Optimize' ) ) { + $cache = \WP_Optimize()->get_page_cache(); + $cache->purge(); - // Clear Cache. - $purge = new \WP_Optimize_Cache_Commands(); - $purge->purge_page_cache(); return true; } return false; } + /** + * Check if WP Optimize is installed and cache is enabled. + */ + public function wp_optimize_activated_check() { + if ( class_exists( '\WP_Optimize' ) ) { + $cache = WP_Optimize()->get_page_cache(); + if ( ! $cache->is_enabled() ) { + return false; + } + } + } + /** * Purge WP Super Cache. * @@ -977,27 +999,30 @@ public function breeze_auto_purge_cache() { */ public function wprocket_auto_cache_purge() { - $success_message = 'WP Rocket => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'WP Rocket => There was an issue purging your cache.'; - // Purge Cache if action is set to "1". - $action = get_option( 'mainwp_child_auto_purge_cache', false ); + $do_purge = get_option( 'mainwp_child_auto_purge_cache', false ); $purge_result = array(); - if ( 1 === (int) $action ) { + if ( 1 === (int) $do_purge ) { $purge_result = MainWP_Child_WP_Rocket::instance()->purge_cache_all(); } - // Save last purge time to database on success. + // Record results & return response. if ( 'SUCCESS' === $purge_result['result'] ) { + + // Save last purge time to database on success. update_option( 'mainwp_cache_control_last_purged', time() ); // Return success message. + $success_message = 'WP Rocket => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; return $this->purge_result( $success_message, 'SUCCESS' ); } else { + // Return error message. + $error_message = 'WP Rocket => There was an issue purging your cache.'; return $this->purge_result( $error_message, 'ERROR' ); + } } diff --git a/class/class-mainwp-child-callable.php b/class/class-mainwp-child-callable.php index a02f9cf4..b0a2b110 100644 --- a/class/class-mainwp-child-callable.php +++ b/class/class-mainwp-child-callable.php @@ -987,7 +987,7 @@ public function delete_backup() { // phpcs:enable if ( file_exists( $backupdir . $file ) ) { - wp_delete_file( $backupdir . $file ); + wp_delete_file( $backupdir . $file ); // NOSONAR . } MainWP_Helper::write( array( 'result' => 'ok' ) ); diff --git a/class/class-mainwp-child-keys-manager.php b/class/class-mainwp-child-keys-manager.php index 3f5e97f5..b7b67628 100644 --- a/class/class-mainwp-child-keys-manager.php +++ b/class/class-mainwp-child-keys-manager.php @@ -98,7 +98,7 @@ public function get_sodium_key() { * @return string Encrypted value. */ public function encrypt_string( $keypass ) { - + MainWP_Connect_Lib::autoload_files(); // to fix. if ( ! $this->valid_phpseclib3_supported() ) { if ( is_callable( 'sodium_crypto_secretbox' ) ) { $nonce = $this->get_key_val( 'nonce', 24 ); // $nonce A Number to be used Once; must be 24 bytes. diff --git a/class/class-mainwp-child-misc.php b/class/class-mainwp-child-misc.php index 0c46296f..4a9dbe62 100644 --- a/class/class-mainwp-child-misc.php +++ b/class/class-mainwp-child-misc.php @@ -814,9 +814,9 @@ public function snippet_update_wp_config( $action, $slug, $code = '' ) { $wpConfig = file_get_contents( $config_file ); //phpcs:ignore WordPress.WP.AlternativeFunctions if ( 'delete' === $action ) { - $wpConfig = preg_replace( '/' . PHP_EOL . '{1,2}\/\*\*\*snippet_' . $slug . '\*\*\*\/(.*)\/\*\*\*end_' . $slug . '\*\*\*\/' . PHP_EOL . '/is', '', $wpConfig ); + $wpConfig = preg_replace( '/' . PHP_EOL . '{1,2}\/\*\*\*snippet_' . $slug . '\*\*\*\/(.*)\/\*\*\*end_' . $slug . '\*\*\*\/' . PHP_EOL . '/is', '', $wpConfig ); // NOSONAR . } elseif ( 'save' === $action ) { - $wpConfig = preg_replace( '/(\$table_prefix *= *[\'"][^\'|^"]*[\'"] *;)/is', '${1}' . PHP_EOL . PHP_EOL . '/***snippet_' . $slug . '***/' . PHP_EOL . $code . PHP_EOL . '/***end_' . $slug . '***/' . PHP_EOL, $wpConfig ); + $wpConfig = preg_replace( '/(\$table_prefix *= *[\'"][^\'|^"]*[\'"] *;)/is', '${1}' . PHP_EOL . PHP_EOL . '/***snippet_' . $slug . '***/' . PHP_EOL . $code . PHP_EOL . '/***end_' . $slug . '***/' . PHP_EOL, $wpConfig ); // NOSONAR . } MainWP_Helper::file_put_contents( $config_file, $wpConfig ); //phpcs:ignore WordPress.WP.AlternativeFunctions return true; diff --git a/class/class-mainwp-child-posts.php b/class/class-mainwp-child-posts.php index 721a60fe..65ede51a 100644 --- a/class/class-mainwp-child-posts.php +++ b/class/class-mainwp-child-posts.php @@ -572,7 +572,7 @@ private function get_post_edit( $id ) { $categories = ''; foreach ( $categoryObjects as $cat ) { if ( '' !== $categories ) { - $categories .= ', '; + $categories .= ','; } $categories .= $cat->name; } @@ -583,7 +583,7 @@ private function get_post_edit( $id ) { if ( is_array( $tagObjects ) ) { foreach ( $tagObjects as $tag ) { if ( '' !== $tags ) { - $tags .= ', '; + $tags .= ','; } $tags .= $tag->name; } @@ -1086,7 +1086,8 @@ private function update_wp_rocket_custom_post( &$post_custom ) { private function update_found_images( &$new_post, $upload_dir, $check_image_existed ) { // Some images have a href tag to click to navigate to the image.. we need to replace this too. - $foundMatches = preg_match_all( '/(]+href=\"(.*?)\"[^>]*>)?(\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER ); + $foundMatches = preg_match_all( '/(]+href=\"(.*?)\"[^>]*>)?(\/]*src=\"((.*?)(png|gif|jpg|jpeg|avif))\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER ); + if ( $foundMatches > 0 ) { // We found images, now to download them so we can start balbal. foreach ( $matches as $match ) { @@ -1157,7 +1158,7 @@ public static function replace_advanced_image( $content, $upload_dir, $withslash $dashboard_url = str_replace( '/', '\/', $dashboard_url ); } - $foundMatches = preg_match_all( '#(' . preg_quote( $site_url_destination, null ) . ')[^\.]*(\.(png|gif|jpg|jpeg))#ix', $content, $matches, PREG_SET_ORDER ); + $foundMatches = preg_match_all( '#(' . preg_quote( $site_url_destination, null ) . ')[^\.]*(\.(png|gif|jpg|jpeg|avif))#ix', $content, $matches, PREG_SET_ORDER ); if ( 0 < $foundMatches ) { diff --git a/class/class-mainwp-child-stats.php b/class/class-mainwp-child-stats.php index 6771e8a6..1fda1b36 100644 --- a/class/class-mainwp-child-stats.php +++ b/class/class-mainwp-child-stats.php @@ -250,8 +250,9 @@ public function get_site_stats( $information = array(), $exit_done = true ) { $information['securityStats'] = MainWP_Child_Misc::get_instance()->get_security_stats( true ); // Directory listings! - $information['directories'] = isset( $_POST['scan_dir'] ) && ! empty( $_POST['scan_dir'] ) ? $this->scan_dir( ABSPATH, 3 ) : ''; - $information['categories'] = $this->stats_get_categories(); + $information['directories'] = isset( $_POST['scan_dir'] ) && ! empty( $_POST['scan_dir'] ) ? $this->scan_dir( ABSPATH, 3 ) : ''; + $information['categories'] = $this->stats_get_categories( false ); // to compatible. + $information['categories_list'] = $this->stats_get_categories(); $totalsize = $this->stats_get_total_size(); if ( ! empty( $totalsize ) ) { @@ -704,27 +705,40 @@ private function stats_plugin_update( $premiumPlugins ) { /** * Ger category stats. * + * @param bool $full_data to support compatible data. + * * @return array $categories Available Child Site Categories. */ - private function stats_get_categories() { + private function stats_get_categories( $full_data = true ) { // phpcs:disable WordPress.Security.NonceVerification $number = isset( $_POST['categories_number'] ) ? intval( $_POST['categories_number'] ) : 300; // phpcs:ignore WordPress.Security.NonceVerification if ( 300 >= $number ) { $number = 300; } - $cats = get_categories( + $cats = get_categories( array( 'hide_empty' => 0, 'hierarchical' => true, 'number' => $number, ) ); + $categories = array(); + foreach ( $cats as $cat ) { - $categories[] = $cat->name; + if ( $full_data ) { + $categories[] = array( + 'term_id' => $cat->term_id, + 'name' => $cat->name, + 'slug' => $cat->slug, + 'taxonomy' => $cat->taxonomy, + 'parent' => $cat->parent, + ); + } else { + $categories[] = $cat->name; + } } - return $categories; } diff --git a/class/class-mainwp-child-timecapsule.php b/class/class-mainwp-child-timecapsule.php index 14e4aded..4c265965 100644 --- a/class/class-mainwp-child-timecapsule.php +++ b/class/class-mainwp-child-timecapsule.php @@ -1720,7 +1720,7 @@ private function save_settings_backup_auto_tab( $config, $data, $is_general ) { $config->set_option( 'backup_before_update_setting', $data['backup_before_update_setting'] ); $current = $config->get_option( 'wptc_auto_update_settings' ); $current = unserialize( $current ); // phpcs:ignore -- safe internal value, third party. - $new = unserialize( $data['wptc_auto_update_settings'] ); // phpcs:ignore -- safe internal value, third party. + $new = unserialize( $data['wptc_auto_update_settings'] ); // phpcs:ignore -- compatible third party // NOSONARR . $current['update_settings']['status'] = $new['update_settings']['status']; $current['update_settings']['schedule']['enabled'] = $new['update_settings']['schedule']['enabled']; $current['update_settings']['schedule']['time'] = $new['update_settings']['schedule']['time']; @@ -1755,7 +1755,7 @@ private function save_settings_backup_auto_tab( $config, $data, $is_general ) { private function save_settings_vulns_update_tab( $config, $data, $is_general ) { $current = $config->get_option( 'vulns_settings' ); $current = unserialize( $current ); // phpcs:ignore -- safe internal value, third party. - $new = unserialize( $data['vulns_settings'] ); // phpcs:ignore -- safe internal value, third party. + $new = unserialize( $data['vulns_settings'] ); // phpcs:ignore -- third party compatible // NOSONARR . $current['status'] = $new['status']; $current['core']['status'] = $new['core']['status']; diff --git a/class/class-mainwp-child-updates.php b/class/class-mainwp-child-updates.php index 14d9dbbc..efc59bfe 100644 --- a/class/class-mainwp-child-updates.php +++ b/class/class-mainwp-child-updates.php @@ -319,7 +319,7 @@ private function check_update_requires( $plugins ) { ); if ( file_exists( $readme_file ) ) { - $plugin_data = get_file_data( + $plugin_data = get_file_data( // NOSONAR . $readme_file, array( 'requires' => 'Requires at least', diff --git a/class/class-mainwp-child-updraft-plus-backups.php b/class/class-mainwp-child-updraft-plus-backups.php index f13b5eee..e5c4372c 100644 --- a/class/class-mainwp-child-updraft-plus-backups.php +++ b/class/class-mainwp-child-updraft-plus-backups.php @@ -582,6 +582,9 @@ public function save_settings() { $settings = isset( $_POST['settings'] ) ? json_decode( base64_decode( wp_unslash( $_POST['settings'] ) ), true ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible.. $keys_filter = $this->get_settings_keys(); + + /** @global object $updraftplus UpdraftPlus instance. */ + global $updraftplus; $updated = false; if ( is_array( $settings ) ) { @@ -777,6 +780,9 @@ public function save_settings() { $opts['settings'][ $settings_key ]['backup_path'] = $bpath; \UpdraftPlus_Options::update_updraft_option( $key, $opts ); } + } elseif ( 'updraft_interval_increments' === $key ) { + $value = $updraftplus->schedule_backup_increments( $settings[ $key ] ); + \UpdraftPlus_Options::update_updraft_option( $key, $value ); } else { \UpdraftPlus_Options::update_updraft_option( $key, $settings[ $key ] ); } @@ -787,10 +793,7 @@ public function save_settings() { if ( ! isset( $settings['do_not_save_remote_settings'] ) || empty( $settings['do_not_save_remote_settings'] ) ) { \UpdraftPlus_Options::update_updraft_option( 'updraft_service', $settings['updraft_service'] ); } - - /** @global object $updraftplus UpdraftPlus instance. */ - global $updraftplus; - + if ( isset( $settings['updraft_interval'] ) ) { // fix for premium version. $_POST['updraft_interval'] = $settings['updraft_interval']; diff --git a/class/class-mainwp-child-wp-rocket.php b/class/class-mainwp-child-wp-rocket.php index 813e1c52..a029cc0a 100644 --- a/class/class-mainwp-child-wp-rocket.php +++ b/class/class-mainwp-child-wp-rocket.php @@ -423,14 +423,18 @@ public function all_plugins( $plugins ) { * @uses \MainWP\Child\MainWP_Helper::write() */ public function action() { + + // Check if the WP Rocket plugin is installed on the child website. if ( ! $this->is_plugin_installed ) { MainWP_Helper::write( array( 'error' => esc_html__( 'Please install WP Rocket plugin on child website', $this->plugin_translate ) ) ); return; } - $information = array(); - + // Action to be performed. $mwp_action = MainWP_System::instance()->validate_params( 'mwp_action' ); + + // Run specific wprocket method based on the passed action. + $information = array(); if ( ! empty( $mwp_action ) ) { try { switch ( $mwp_action ) { @@ -526,6 +530,12 @@ public function purge_cloudflare() { } } + private function require_file_path($functionName, $fileName) { + if ( ! function_exists( $functionName ) && defined( 'WP_ROCKET_FUNCTIONS_PATH' ) ) { + require_once WP_ROCKET_FUNCTIONS_PATH . $fileName; + } + } + /** * Method purge_cache_all() * @@ -538,22 +548,35 @@ public function purge_cloudflare() { public function purge_cache_all() { if ( function_exists( 'rocket_clean_domain' ) || function_exists( 'rocket_clean_minify' ) || function_exists( 'create_rocket_uniqid' ) ) { set_transient( 'rocket_clear_cache', 'all', HOUR_IN_SECONDS ); + + // Require files to make sure the functions are available. + $this->require_file_path('get_rocket_i18n_uri', 'i18n.php'); + $this->require_file_path('get_rocket_parse_url', 'formatting.php'); + $this->require_file_path('create_rocket_uniqid', 'admin.php'); + rocket_clean_domain(); rocket_clean_minify(); + if ( function_exists( 'rocket_clean_cache_busting' ) ) { rocket_clean_cache_busting(); } + if ( ! function_exists( 'rocket_dismiss_boxes' ) && defined( 'WP_ROCKET_ADMIN_PATH' ) ) { require_once WP_ROCKET_ADMIN_PATH . 'admin.php'; } + include_once ABSPATH . '/wp-admin/includes/template.php'; + $options = get_option( WP_ROCKET_SLUG ); $options['minify_css_key'] = create_rocket_uniqid(); $options['minify_js_key'] = create_rocket_uniqid(); + remove_all_filters( 'update_option_' . WP_ROCKET_SLUG ); update_option( WP_ROCKET_SLUG, $options ); rocket_dismiss_box( 'rocket_warning_plugin_modification' ); + return array( 'result' => 'SUCCESS' ); + } else { return array( 'error' => 'function_not_exist' ); } diff --git a/class/class-mainwp-clone-install.php b/class/class-mainwp-clone-install.php index 9929bfb3..18e91677 100644 --- a/class/class-mainwp-clone-install.php +++ b/class/class-mainwp-clone-install.php @@ -477,13 +477,13 @@ public function extract_backup() { $this->archiver->read( $this->file ); } return $this->archiver->extract_to( ABSPATH ); - } elseif ( ( filesize( $this->file ) >= 50000000 ) && $this->check_wp_zip() ) { + } elseif ( ( filesize( $this->file ) >= 50000000 ) && $this->check_wp_zip() ) { // NOSONAR. return $this->extract_wp_zip_backup(); } elseif ( $this->check_zip_console() ) { return $this->extract_zip_console_backup(); } elseif ( $this->check_zip_support() ) { return $this->extract_zip_backup(); - } elseif ( ( filesize( $this->file ) < 50000000 ) && $this->check_wp_zip() ) { + } elseif ( ( filesize( $this->file ) < 50000000 ) && $this->check_wp_zip() ) { // NOSONAR. return $this->extract_wp_zip_backup(); } else { return $this->extract_zip_pcl_backup(); @@ -532,7 +532,7 @@ public function extract_wp_zip_backup() { $tmpdir = str_replace( ABSPATH, $ftpBase, $tmpdir ); } - \unzip_file( $this->file, $tmpdir ); + \unzip_file( $this->file, $tmpdir ); // NOSONAR. return true; } diff --git a/class/class-mainwp-clone.php b/class/class-mainwp-clone.php index 9d60bc6d..c39cb98a 100644 --- a/class/class-mainwp-clone.php +++ b/class/class-mainwp-clone.php @@ -257,7 +257,7 @@ public function request_clone_funct() { // phpcs:ignore -- Current complexity is $f = isset( $_POST['f'] ) ? sanitize_text_field( wp_unslash( $_POST['f'] ) ) : ''; $archiveFile = false; if ( ! empty( $f ) ) { - $result = glob( $backupdir . 'backup-' . $f . '-*' ); + $result = glob( $backupdir . 'backup-' . $f . '-*' ); // NOSONAR . foreach ( $result as $file ) { if ( self::is_archive( $file, 'backup-' . $f . '-' ) ) { $archiveFile = $file; @@ -782,7 +782,7 @@ private function clone_backup_get_file( $file, &$testFull ) { * @return bool true|false If the file is archive, return true, if not, return false. */ public static function is_archive( $file_name, $prefix = '', $suffix = '' ) { - return preg_match( '/' . $prefix . '(.*).(zip|tar|tar.gz|tar.bz2)' . $suffix . '$/', $file_name ); + return preg_match( '/' . $prefix . '(.*).(zip|tar|tar.gz|tar.bz2)' . $suffix . '$/', $file_name ); // NOSONAR . } /** diff --git a/class/class-mainwp-custom-post-type.php b/class/class-mainwp-custom-post-type.php index 4cfbbd23..20b209a5 100644 --- a/class/class-mainwp-custom-post-type.php +++ b/class/class-mainwp-custom-post-type.php @@ -145,7 +145,7 @@ private function import_custom_post() { * @uses \MainWP\Child\MainWP_Utility::upload_image() */ private function search_images( $post_content, $upload_dir, $check_image = false ) { - $foundMatches = preg_match_all( '/(]+href=\"(.*?)\"[^>]*>)?(\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $post_content, $matches, PREG_SET_ORDER ); + $foundMatches = preg_match_all( '/(]+href=\"(.*?)\"[^>]*>)?(\/]*src=\"((.*?)(png|gif|jpg|jpeg|avif))\")/ix', $post_content, $matches, PREG_SET_ORDER ); if ( $foundMatches > 0 ) { foreach ( $matches as $match ) { $hrefLink = $match[2]; @@ -439,7 +439,7 @@ private function insert_postmeta( $post_id, $data, $check_image_existed, $is_woo } } - $meta_value = maybe_unserialize( $meta_value ); + $meta_value = maybe_unserialize( $meta_value ); // NOSONARR . if ( add_post_meta( $post_id, $key['meta_key'], $meta_value ) === false ) { return array( 'error' => esc_html__( 'Error when adding post meta', $this->plugin_translate ) . ' `' . esc_html( $key['meta_key'] ) . '`' ); } diff --git a/class/class-mainwp-helper.php b/class/class-mainwp-helper.php index 216c10a5..32e593d7 100644 --- a/class/class-mainwp-helper.php +++ b/class/class-mainwp-helper.php @@ -173,7 +173,7 @@ public static function file_put_contents( $file, $content ) { global $wp_filesystem; return $wp_filesystem->put_contents( $file, $content, FS_CHMOD_FILE ); } else { - return file_put_contents( $file, $content );// phpcs:ignore WordPress.WP.AlternativeFunctions + return file_put_contents( $file, $content );// phpcs:ignore WordPress.WP.AlternativeFunctions -- // NOSONAR . } } @@ -586,7 +586,7 @@ public static function is_dir_empty( $dir ) { * @param string $dir Contains the directory location path. */ public static function delete_dir( $dir ) { - $nodes = glob( $dir . '*' ); + $nodes = glob( $dir . '*' ); // NOSONAR . if ( is_array( $nodes ) ) { foreach ( $nodes as $node ) { diff --git a/class/class-mainwp-system.php b/class/class-mainwp-system.php index 328dd44c..608a3ff7 100644 --- a/class/class-mainwp-system.php +++ b/class/class-mainwp-system.php @@ -86,6 +86,7 @@ public function validate_params( $name = '', $def_value = '' ) { */ public static function wp_mainwp_version_check() { add_filter( 'automatic_updater_disabled', '__return_true' ); // to prevent auto update on this version check. + remove_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' ); wp_version_check(); } } diff --git a/class/class-mainwp-utility.php b/class/class-mainwp-utility.php index 9f693411..988fae47 100644 --- a/class/class-mainwp-utility.php +++ b/class/class-mainwp-utility.php @@ -385,7 +385,7 @@ public function check_image_file_name( $filename ) { return false; } - $allowed_files = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico' ); + $allowed_files = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'avif' ); $names = explode( '.', $filename ); $file_ext = strtolower( end( $names ) ); if ( ! in_array( $file_ext, $allowed_files ) ) { diff --git a/class/class-tar-archiver.php b/class/class-tar-archiver.php index 7dc90bf6..c7c2e10d 100644 --- a/class/class-tar-archiver.php +++ b/class/class-tar-archiver.php @@ -827,8 +827,8 @@ private function add_file( $path, $entryName ) { // phpcs:ignore -- Current comp $this->gcCnt = 0; } - $stat = stat( $path ); - $fp = fopen( $path, 'rb' ); + $stat = stat( $path ); // NOSONAR . + $fp = fopen( $path, 'rb' ); // NOSONAR . if ( ! $fp ) { return; } @@ -1241,7 +1241,7 @@ public function create( $filepath ) { if ( 'tar.bz2' === $this->type ) { $this->archive = bzopen( $filepath, 'w' ); } else { - $this->archive = fopen( $filepath, 'wb+' ); + $this->archive = fopen( $filepath, 'wb+' ); // NOSONAR . } return; @@ -1252,7 +1252,7 @@ public function create( $filepath ) { } elseif ( 'tar.bz2' === $this->type ) { $this->archive = bzopen( $filepath, 'w' ); } else { - $this->archive = fopen( $filepath, 'wb+' ); + $this->archive = fopen( $filepath, 'wb+' ); // NOSONAR . } } @@ -1267,7 +1267,7 @@ public function append( $filepath ) { if ( 'tar.bz2' === $this->type ) { $this->archive = bzopen( $filepath, 'a' ); } else { - $this->archive = fopen( $filepath, 'ab+' ); + $this->archive = fopen( $filepath, 'ab+' ); // NOSONAR . } return; @@ -1278,7 +1278,7 @@ public function append( $filepath ) { } elseif ( 'tar.bz2' === $this->type ) { $this->archive = bzopen( $filepath, 'a' ); } else { - $this->archive = fopen( $filepath, 'ab+' ); + $this->archive = fopen( $filepath, 'ab+' ); // NOSONAR . } } @@ -1302,7 +1302,7 @@ public function prepare_append( $filepath ) { if ( $this->debug ) { if ( 'tar.gz' === substr( $filepath, - 6 ) ) { $text = chr( 31 ) . chr( 139 ) . chr( 8 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ); - $fh = fopen( $filepath, 'rb' ); + $fh = fopen( $filepath, 'rb' ); // NOSONAR . $read = ''; $lastCorrect = 0; try { @@ -1329,7 +1329,7 @@ public function prepare_append( $filepath ) { fclose( $fh ); } catch ( \Exception $e ) { fclose( $fh ); - $fh = fopen( $filepath, 'ab+' ); + $fh = fopen( $filepath, 'ab+' ); // NOSONAR . fseek( $fh, $lastCorrect ); ftruncate( $fh, $lastCorrect ); fclose( $fh ); @@ -1364,7 +1364,7 @@ public function read( $filepath ) { $this->archiveSize = $lastPos; $this->type = 'tar'; - $this->archive = fopen( $filepath, 'rb' ); + $this->archive = fopen( $filepath, 'rb' ); // NOSONAR . } } diff --git a/readme.txt b/readme.txt index e4a69d53..54b30ff1 100644 --- a/readme.txt +++ b/readme.txt @@ -1,153 +1,100 @@ -=== MainWP Child - Securely Connects Sites to the MainWP WordPress Manager Dashboard === +=== MainWP Child - Securely Connects to the MainWP Dashboard to Manage Multiple Sites === Contributors: mainwp -Tags: Manage Multiple Sites, Maintenance, Client, Admin, Update, Monitoring, Dashboard, Backup, Performance, Lighthouse, Analytics, Security +Tags: update, backups, security, monitoring, site management Author: mainwp Author URI: https://mainwp.com Plugin URI: https://mainwp.com Requires at least: 6.2 -Tested up to: 6.4.2 +Tested up to: 6.5 Requires PHP: 7.4 Stable tag: 5.0 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html -Securely connects Unlimited WordPress sites to your MainWP Dashboard, allowing you to control them from a single screen +MainWP Child establishes a secure link between your WordPress sites and your self-hosted MainWP Dashboard, simplifying site management. == Description == -This is a Child Plugin for [β€œMainWP Dashboard”](https://wordpress.org/plugins/mainwp/) that connects your WordPress sites to the MainWP Dashboard. +**The MainWP Child Plugin securely connects the WordPress sites you want to manage to the [MainWP Dashboard](https://wordpress.org/plugins/mainwp/).** -The [MainWP](https://mainwp.com/), a complete WordPress Management solution, is self-hosted, open source, and private, allowing you to control multiple WordPress websites (even those on different hosting) from your own WordPress website. +The MainWP Child plugin creates a secure connection between your WordPress sites and your self-hosted MainWP Dashboard, enabling you to efficiently manage WP installations from a single, centralized location. -MainWP is the **perfect solution for** -- Agencies -- Freelancers -- Developers -- Designers -- Consultants -- Marketers -- In fact, anyone who wants to manage multiple WordPress sites +With MainWP Child and the MainWP Dashboard, you can update themes, plugins, and WordPress core across all connected sites, perform backups and security scans, manage posts, pages, users, and comments in bulk, and integrate with popular plugins like WooCommerce, Yoast SEO, and Wordfence. -== Here’s Why WordPress Managers Love MainWP! == +The [MainWP Dashboard](https://wordpress.org/plugins/mainwp/) also offers features for cost tracking and client management, making it an all-in-one solution for agencies and freelancers looking to manage WP sites efficiently. The functionality can be further extended with a growing library of [MainWP extensions](https://mainwp.com/mainwp-extensions/). -πŸ’° Free Forever -πŸ… White Label -♾️ Connect Unlimited Websites -🌐 Track Updates via Browser with MainWP Browser Extension -πŸ§‘β€πŸ’» Manage all Sites, Users, Plugins, Themes, Updates -πŸ‘₯ Full Client Management -🏷️ Organize Sites & Clients via Colorful Tags -πŸ•’ Uptime & Site Health Monitoring -🚩 1-Click Lighthouse Stats for all Sites -πŸ”„ Effortless Bulk Updates -🚧 Staging, Cloning -πŸ“ Professional Reports for Clients -πŸ’¬ Bulk Manage Comments -πŸ›‘οΈ Bulk Manage Security -πŸš€ Purge Cache from the Dashboard -✏️ Fully Customizable -πŸ” Domain & SSL Certificate Monitoring -πŸ”‘ Passwordless 1-click Login to all Connected Sites -πŸ”’ Full Privacy, Self-hosted, Lock Your Dashboard -😌 Bulk Content Management (Draft, Publish, Edit, Trash) -βž• Perform Pressable hosting-specific tasks +[MainWP](https://mainwp.com/) is the ideal solution for freelancers and agencies managing client sites, developers and designers working on multiple projects, marketers and content managers overseeing various websites, and anyone responsible for maintaining multiple WordPress sites. -With MainWP, you can **easily manage & control settings** for several plugins/services directly from the dashboard. += Why Choose MainWP for WordPress Management? = +MainWP is 100% free and open-source, with no monthly fees, even for unlimited sites. -πŸ—ƒοΈ UpdraftPlus, WPvivid, WP Staging, BackWPup, BackupBuddy, Time Capsule -πŸ”’ Termageddon, Wordfence, Jetpack Protect & Scan, Sucuri, iThemes Security, Virusdie, Activity Log, Security Ninja -πŸš€ WP Rocket, WP Compress, Google Lighthouse Stats -βœ… Atarim, WooCommerce, Database Updater -πŸ“ˆ Yoast, SEOPress, Google Analytics (GA4), Matomo Stats -🌐 Uptime Robot, NodePing, Site24x7, Better Uptime +As a self-hosted solution, it offers maximum control and privacy. MainWP provides comprehensive site management features and is highly customizable with extensions and developer hooks. The MainWP Child plugin even comes with its own privacy policy to guarantee your [privacy while using MainWP](https://mainwp.com/mainwp-plugin-privacy-policy/). -And a lot more. πŸ‘‰ [Free vs. Pro: Know the Difference](https://mainwp.com/free-vs-pro/) +All of this makes MainWP the best non-SaaS alternative to ManageWP, InfiniteWP, WPRemote, and WP Umbrella. -== HOW DOES THE MAINWP WORK? == += Key Features = +MainWP Child, combined with the MainWP Dashboard, offers secure management of unlimited WordPress sites, one-click updates for plugins, themes, and WordPress core, automated backups and security monitoring, bulk management of posts, pages, users, and comments, white-labeling and custom branding options, and [powerful extensions](https://mainwp.com/mainwp-extensions/) for WooCommerce, Yoast SEO, Wordfence, and more. -First, Install and Activate the [MainWP WordPress Manager Dashboard](https://wordpress.org/plugins/mainwp/) plugin on a WordPress site you will use for controlling all other sites; this is your Dashboard Site. += Expand Your MainWP Dashboard with Extensions = +MainWP offers a growing library of extensions that add advanced functionality to your Dashboard. From client reporting to SEO management, MainWP extensions provide the tools you need to deliver top-notch service to your clients. -We highly recommend this be a new, clean WordPress installation and not on one of your production sites. Using a clean site helps to eliminate any unnecessary plugin conflicts or security issues. += Join the MainWP Community = +MainWP is more than just a plugin; it's a thriving community of WordPress professionals. Join our [MainWP Users Facebook Group](https://www.facebook.com/groups/MainWPUsers/) to connect with other users, share advice, and stay updated on the latest features and extensions. -Next, Install and Activate the MainWP Child plugin (this plugin) on all the WordPress sites you want to connect to your MainWP Dashboard. WordPress sites connected to your Dashboard are referred to as Child Sites. += Developer-Friendly = +MainWP is built with developers in mind. We provide extensive documentation, hooks, and an API to help you create custom extensions and integrations for the MainWP platform. We have a site at [MainWP.dev](https://mainwp.dev) dedicated to MainWP developers. -Once connected, you can manage them from your MainWP Dashboard. += Get Started with MainWP Today = +Take control of your WordPress site management with MainWP and the MainWP Child plugin. With its powerful features, unlimited site connections, and user-friendly interface, MainWP is the smart choice for anyone managing multiple WordPress sites. -Still not sure how MainWP works? [Review these detailed steps on installing your Dashboard and connecting your first Child Site.](https://mainwp.com/getting-started-with-mainwp/) - -== Features Include: == - -- Connect and control all your WordPress installs, even those on different hosts! -- Update all WordPress installs, Plugins, and Themes from one location -- Manage and Add all your Posts from one location -- Manage and Add all your Pages from one location -- Run everything from one Dashboard! -- One-click login to your Child Sites -- Easy plugin management (Bulk update, add, remove, etc.) -- Fully customizable -- Self-Hosted, Private, and Open Source - -πŸ‘‰ [View all features](https://mainwp.com/free-vs-pro/) - -To know more about the MainWP WordPress management system, take a look at the [MainWP Dashboard.](https://wordpress.org/plugins/mainwp/) - -= More Information = -- [MainWP Documentation](https://kb.mainwp.com/) -- [MainWP Community](https://managers.mainwp.com/) -- [MainWP Support](https://mainwp.com/support/) -- [MainWP Videos](https://www.youtube.com/user/MyMainWP) -- [MainWP Extensions](https://mainwp.com/mainwp-extensions/) -- [Develop MainWP Extensions](https://mainwp.com/develop-mainwp/) -- [MainWP on Github](https://mainwp.com/github/) += Learn More About MainWP = +- [MainWP Website](https://mainwp.com) +- [MainWP Documentation](https://kb.mainwp.com) +- [MainWP Support](https://managers.mainwp.com/c/support/mainwp-support/) +- [MainWP Blog](https://mainwp.com/blog/) +- [MainWP on GitHub](https://github.com/mainwp/) == Installation == -Install & Activate this (MainWP Child) plugin on all your WordPress sites (called Child Sites) that you want to control directly from your Dashboard site. - -This acts as a bridge to communicate with the Dashboard site. +How the MainWP Child Plugin Works +Install and activate the [MainWP Dashboard](https://wordpress.org/plugins/mainwp/) plugin on a dedicated WordPress site. -Or, [Review these detailed steps on setting up MainWP](https://mainwp.com/getting-started-with-mainwp/) +Install the MainWP Child plugin (this plugin) on the WordPress sites you want to connect to your MainWP Dashboard. +Activate the plugin. +Follow the [Getting Started Guide](https://mainwp.com/getting-started-with-mainwp/) to connect your sites to your MainWP Dashboard. == Frequently Asked Questions == -= Do I need any other plugins for MainWP? = -Yes, you need to install the [MainWP Child Plugin](https://wordpress.org/plugins/mainwp-child/) on the sites you want to control with the Dashboard plugin. -= Do you have any documentation? = -Yes, please review the [documentation site](https://kb.mainwp.com). += Is the MainWP Child Plugin required to use MainWP? = +Yes, the MainWP Child plugin must be installed on each WordPress site you want to connect to your MainWP Dashboard. -= I just want to start using MainWP, do you have a Quick Start Guide? = -Yes, please read the [Quick Start – Setting up your MainWP](https://mainwp.com/install-mainwp/). += Can I hide the MainWP Child plugin from the WordPress admin? = +Yes, you can use the MainWP White Label extension to hide the MainWP Child plugin from the WordPress admin on your connected sites. -= Where do I go for support or to ask for help? = -Please post in the [MainWP Community](https://managers.mainwp.com), or feel free to [contact us](https://mainwp.com/support/). += How does MainWP compare to ManageWP? = +While MainWP and ManageWP offer similar features, MainWP is self-hosted and open-source, providing more control and flexibility. Learn more about the differences between [MainWP and ManageWP](https://mainwp.com/managewp-vs-mainwp/). -= What is the difference between ManageWP and MainWP? = -Essentially MainWP and ManageWP provide the same type of service but with different philosophies on WordPress management. += How does MainWP compare to WP Umbrella? = +Both MainWP and WP Umbrella offer features for managing multiple WordPress sites, but MainWP is self-hosted and open-source, while WP Umbrella is a SaaS platform hosted on their servers. MainWP's open architecture provides greater control and flexibility. Discover more differences between [MainWP and WP Umbrella](https://mainwp.com/wp-umbrella-vs-mainwp/). -ManageWP is a Service as a Solution (SaaS) property owned by GoDaddy. The SaaS system makes ManageWP a type of "Walled Garden" with limited customization options. += How does MainWP compare to InfiniteWP? = +MainWP and InfiniteWP are both self-hosted WordPress management solutions. However, MainWP is open-source, allowing for code review and extensibility, while InfiniteWP's Admin Panel is not open-source and obfuscates its code. MainWP also offers a comprehensive set of features tailored for agencies and freelancers managing client sites. Explore the differences between [MainWP and InfiniteWP](https://mainwp.com/infinitewp-vs-mainwp/). -MainWP follows the tradition of WordPress and is [open source](https://github.com/mainwp/mainwp), [private](https://mainwp.com/protect-your-data/), and [fully extendable](https://mainwp.dev). The fact that MainWP is open source and extendable means you have almost unlimited customization options, allowing you to run your WordPress management business as you see fit. += How does MainWP compare to WPRemote? = +MainWP and WPRemote are both WordPress management solutions, but they differ in their approach and feature set. MainWP is a self-hosted, open-source plugin that gives you full control over your data and offers a wide range of features. WP Remote is a cloud-based service that stores your data on its servers, which may be a concern for some users who prioritize data ownership, security, and GDPR. Learn more about the differences between [MainWP and WPRemote](https://mainwp.com/wpremote-vs-mainwp/). -πŸ‘‰ [ManageWP vs. MainWP: Know the Difference](https://mainwp.com/managewp-vs-mainwp/) += Is MainWP secure? = +Yes, security is a top priority for MainWP. We adhere to WordPress security best practices, and our code is open-source and available for review on GitHub. We also offer a bug bounty program to encourage responsible disclosure of any security issues. Read more about [MainWP Security](https://mainwp.com/how-secure-is-mainwp/) practices. -= How do I know my sites are secure using MainWP? = -We take security very seriously at MainWP. We welcome any peer review of our [100% open source code](https://github.com/mainwp/mainwp) to ensure nobody's MainWP management system is ever compromised or hacked. += Can I contribute to MainWP? = +Absolutely! MainWP is open-source, and we welcome community contributions. Visit our [GitHub repository](https://github.com/mainwp/) to get started. -We participate in the [HackerOne](https://www.hackerone.com) bug bounty program; this allows ethical hackers to review MainWP code and directly share any vulnerability information with us in return for a monetary reward. += How can I submit an idea for MainWP? = +Please follow the steps outlined in the [MainWP Feature Requests](https://feedback.mainwp.com/) to submit your idea and allow the MainWP Community to vote on it. -We are also a part of the [Patchstack Vulnerability Disclosure Program](https://patchstack.com/database/vdp/mainwp/), which assists in enhancing the security of MainWP plugins. += Where can I find more information about MainWP? = +We have an extensive FAQ with more questions and answers [here](https://mainwp.com/preinstall-faq/). -= Where do I report security bugs found in MainWP? = -You can report any security bugs found in the source code of MainWP plugins through the [Patchstack Vulnerability Disclosure Program](https://patchstack.com/database/vdp/mainwp/). The Patchstack team will assist you with verification, CVE assignment and take care of notifying us. - -= How do I customize MainWP for my needs? = -If you want to make some basic changes to the look of your Dashboard, you can use our prebuilt [Custom Dashbboard](https://mainwp.com/extension/mainwp-custom-dashboard-extension/) Extension, or if you want to dig in and build Extensions, you can learn all about developing Extension at [MainWP.dev](https://mainwp.dev) - -= I have an idea for MainWP; how do I let you know? = -Please follow the steps outlined in the [MainWP Feature Requests](https://feedback.mainwp.com/) so you can add your idea to the MainWP Community to be voted on. - -= I have more questions, do you have any other information? = -Yes, we have a quick FAQ with a lot more questions and answers [here](https://mainwp.com/preinstall-faq/). == Screenshots == @@ -168,1056 +115,4 @@ Yes, we have a quick FAQ with a lot more questions and answers [here](https://ma * Added: Support for the new API Backups providers - cPanel and Plesk * Updated: Updated the phpSecLib library to enhance security and performance. -= 4.6 - 1-3-2024 = -* Refactored: Updated and optimized the plugin codebase to align with the latest WordPress coding standards, contributing to better compatibility and performance. - -[See Video Changelog](https://www.youtube.com/watch?v=_wmDS3_c_T0) - -= 4.5.3 - 11-6-2023 = -* Fixed: Compatibility with the MainWP WooCommerce Status Extension to fully support WooCommerce HPOS. -* Fixed: Potential functionality issues arising from the disabled state of the php_uname function within PHP environments. -* Added: Support for the `%do-not-update%` token within the MainWP BackWPup Extension to improve update management. - -[See Video Changelog](https://www.youtube.com/watch?v=TA2YSualmkQ) - -= 4.5.2 - 10-16-2023 = -* Added: Support for the Dashboard Insights logging -* Added: Encryption process for the connection Dashboard URL info -* Updated: Unique Security ID random string generate process - -[See Video Changelog](https://www.youtube.com/watch?v=6rA2Ub0xYxU) - -= 4.5.1 - 9-5-2023 = -* Fixed: Problem with loading tabs content on the MainWP Child settings page -* Fixed: An issue with selecting Clone options -* Fixed: Usability problem with file name sanitation for the File Uploader -* Updated: Removed clone options for all users except for the Admin user that is used for establishing the connection with the MainWP Dashboard - -= 4.5 - 8-15-2023 = -* Added: Support for alternative OpenSSL signature verification algorithm -* Added: PHPSecLib as a fallback for missing or Misconfigured OpenSSL -* Added: New encryption & decryption system for safer storing sensitive data -* Added: Support for searching for Not installed plugins -* Added: New PHPCodeSniffer rulesets -* Updated: Removed MD5 as a fallback for setups where OpenSSL is not available - -= 4.4.1.3 - 6-19-2023 = -* Fixed: File Uploader extension-related issue where underscore replaces dots in a file path -* Fixed: An issue with the negative search feature -* Updated: Plugin info in readme.txt - -= 4.4.1.2 - 6-8-2023 = -* Fixed: Potential issues caused by incorrect FileSystem settings -* Updated: Logging system related to the Cache-Control Extension -* Updated: Database export process related to the Cloning feature - -= 4.4.1.1 - 5-9-2023 = -* Fixed: Potential conflict with the Oxygen Builder 4.6 -* Fixed: WP Rocket plugin compatibility problems - -= 4.4.1 - 4-18-2023 = -* Fixed: An issue with saving code snippets -* Fixed: A problem with removing allowed tags in post titles -* Fixed: Multiple PHP warnings -* Added: Check for specific hosts that disable WordPress Core updates for users - -= 4.4.0.4 - 3-30-2023 = -* Fixed: JS conflict caused by the Hide Jetpack plugin feature - -= 4.4.0.3 - 3-30-2023 = -* Fixed: An issue with adding sites caused by incompatible filesystem -* Updated: Support for the Jetpack Scan extension -* Updated: Compatibility for older WordPress versions - -= 4.4.0.2 - 3-16-2023 = -* Fixed: Problem with downloading backup files from Child sites -* Fixed: PHP 7.0 compatibility issue -* Added: Elementor Pro support for the Database Updater Extension -* Added: Support for new caching plugins for the Cache-Control Extension -* Updated: Delete Non-MainWP changes process to delete actions from child sites - -= 4.4.0.1 - 3-9-2023 = -* Fixed: PHP 7.0 compatibility warning -* Fixed: Incorrect Wordfence scans count -* Fixed: Cosmetic issues caused by escaping HTML tags in notifications -* Updated: Increased the PHP version minimal requirement to PHP 7.4 - -= 4.4 - 2-20-2023 = -* Added: support for new extensions -* Preventative: Multiple security enhancements - -= 4.3.1 - 12-14-2022 = -* Fixed: An issue with repeating Non-MainWP changes -* Updated: PHP 8.1 compatibility improvements -* Preventative: Multiple security enhancements - -= 4.3.0.1 - 11-24-2022 = -* Fixed: An issue with logging Non-MainWP changes for the connected admin user -* Removed: Unused DB field - -= 4.3 - 11-16-2022 = -* Fixed: Multiple PHP warnings -* Added: Support for new security checks -* Added: Support for the Non-MainWP Changes feature -* Removed: Unused code - -= 4.2.6 - 8-26-2022 = -* Fixed: An issue with support for the new extension - -= 4.2.5 - 8-25-2022 = -* Added: Support for the new extension -* Fixed: An issue with displaying PHP errors -* Fixed: A problem with the database optimization process related to the Maintenance extension - -= 4.2.4 - 7-14-2022 = -* Fixed: An issue with falling back to the Filesystem API in chrooted configurations -* Fixed: Compatibility issues with the new version of the WP Staging plugin -* Fixed: A problem with overwriting page attributes - -= 4.2.3 - 5-16-2022 = -* Added: Swift Performance Pro to the Purge Cache system - -= 4.2.2 - 5-10-2022 = -* Fixed: An issue with detecting abandoned plugins and themes on specific setups -* Fixed: An issue with running scheduled events on specific setups -* Added: Nginx Helper to the Purge Cache system -* Added: Nitropack to the Purge Cache system -* Added: Autoptimize to the Purge Cache system -* Updated: Tested up to tag to WP 6.0 - -= 4.2.1 - 4-14-2022 = -* Fixed: An issue with setting BackupBuddy plugin Settings -* Fixed: An issue with generating client reports on setups with large amounts of data -* Updated: `meta.mainwp.com` URLs changed to `managers.mainwp.com` -* Updated: `privacy-policy.txt` file - -= 4.2 - 4-5-2022 = -* Fixed: An issue with detecting abandoned plugins and themes on some setups -* Fixed: An issue with the update process getting stuck on specific server configurations -* Fixed: An issue with syncing Wordfence extension data -* Added: Plugin privacy policy file to the plugin directory -* Added: Support for the Negative Search feature -* Added: Support for the feature that prevents the parent theme of the active child theme from being deleted -* Added: Support for the automatic cache clearing after updates feature - -= 4.1.10 - 2-16-2022 = -* Fixed: Problem with loading UpdrafPlus data when `$updraftplus_admin` returns an empty value -* Fixed: Problem with posting images -* Fixed: Problem with loading Wordfence Scan data in reports -* Updated: Multiple error messages -* Updated: Incorrect links - -= 4.1.9 - 12-28-2021 = -* Fixed: Problem with saving UpdraftPlus settings -* Fixed: Error with posting images -* Fixed: Error with recording Wordfence scans for reports -* Fixed: Version comparison issue for OpenSSL version -* Updated: PHP 8 compatibility -* Updated: Added `authorEmail` to the sync output ([PR284](https://github.com/mainwp/mainwp-child/pull/284) - thanks [Kim Vinberg](https://github.com/websitecareio)) - -= 4.1.8 - 10-21-2021 = -* Fixed: An error with missing metadata in the posting process -* Fixed: An error with logging Wordfence scans -* Fixed: New iThemes Security version compatibility problems -* Fixed: New WP Staging version compatibility problems -* Added: Support to define MAINWP_CHILD_UNIQUEID constant -* Added: Custom CSS classes to the White Label support form elements -* Added: 'mainwp_child_before_update' action to hook in before the update process starts -* Added: 'mainwp_child_after_update' action to hook in after the update process completes -* Updated: Disconnected site warning message style -* Updated: Reworded error messages -* Preventative: Multiple security improvements - -= 4.1.7.1 - 10-1-2021 = -* Updated: OpenSSL version requirement to 1.1.0 or greater - -= 4.1.7 - 6-29-21 = -* Added: Support for the new Vulnerability Checker API - -= 4.1.6.1 - 4-16-21 = -* Fixed: An issue with disconnecting sites -* Fixed: An issue with applying custom branding - -= 4.1.6 - 4-15-21 = -* Added: Support for the function to trigger the Check for Abandoned plugins and themes process -* Updated: Multiple performance improvements - -= 4.1.5 - 3-18-21 = -* Fixed: An issue with uploading files with an underscore in the file name -* Fixed: Multiple PHP Warnings -* Updated: Compatibility with the latest UpdraftPlus plugin version -* Updated: Compatibility with the latest BackWPup plugin version -* Updated: Compatibility with the latest WP Rocket plugin version - -= 4.1.4 - 1-21-21 = -* Updated: Compatibility with the latest WP Staging plugin version -* Updated: Compatibility with the latest WP Time Capsule plugin version -* Updated: Multiple DocBlock comments -* Preventative: Multiple security improvements - -= 4.1.3.1 - 12-30-20 = -* Fixed: An issue with uploading images in posts and pages -* Updated: New WP Rocket plugin version compatibility -* Updated: Support for new UpdraftPlus Backups plugin options -* Preventative: Multiple security improvements - -= 4.1.3 - 12-3-20 = -* Fixed: An issue with publishing custom post type content -* Fixed: An issue with loading BackWPup backups -* Fixed: An issue with searching Posts and Pages -* Fixed: Multiple usability issues -* Fixed: An issue with saving custom branding settings -* Updated: Support for new Wordfence options - - -= 4.1.2 - 10-8-20 = -* Removed: unused system information check - -= 4.1.1 - 10-7-20 = -* Fixed: An issue with creating new users -* Fixed: An issue with cloning sites -* Fixed: An issue with creating post tags -* Updated: Multiple database query improvements -* Preventative: Multiple security improvements - -= 4.1 - 9-9-20 = -* Fixed: An issue with posting Custom Post Types -* Fixed: Multiple PHP Warnings -* Added: New actions and filters -* Added: phpDocs blocks for code documentation -* Updated: refactored the code to meet WordPress coding standards -* Updated: WordPress 5.5 compatibility -* Preventative: Multiple security improvements - -= 4.0.7.2 - 8-6-20 = -* Updated: WordPress 5.5 compatibility - -= 4.0.7.1 - 4-30-20 = -* Fixed: JSON decoding issues on specific setups -* Fixed: An issue with incorrect image URL -* Fixed: Conflict with the Download Manager plugin -* Fixed: Multiple PHP warnings -* Fixed: MySQL query compatibility problems -* Fixed: An issue with saving Wordfence settings -* Fixed: An issue with showing the correct post and page creating time -* Fixed: An issue with displaying the correct author in reports -* Added: Support for WPVivid backups in the reporting system -* Preventative: Security improvements - -= 4.0.7 - 2-25-20 = -* Fixed: An issue with saving Bulk Setting Manager keys -* Fixed: An issue with saving Wordfence extension settings -* Fixed: An issue with overwriting PHP error reporting configuration -* Added: Pull request #9 to add an action to allow additional post customization when a new post is created - Thanks [joshlabau](https://github.com/joshlabau) -* Added: Pull request #13 to replace __autoload() with spl_autoload_register - Thanks [Christian Foellmann](https://github.com/cfoellmann) -* Added: Pull request #23 to fix a typo - Thanks [Marco Frodl](https://github.com/marcofrodl) -* Added: Pull request #24 to prevent overwriting PHP error reporting configuration - Thanks [Stanislav Khromov](https://github.com/khromov) -* Updated: Improved premium plugins and themes updates detection system -* Removed: Unused database options - -= 4.0.6.2 - 2-3-20 = -* Fixed: Connection problems caused by issues with json_encode function - -= 4.0.6.1 - 1-20-20 = -* Updated: MainWP_Child_WPvivid_BackupRestore class - -= 4.0.6 - 1-17-20 = -* Fixed: Encoding problem in error messages -* Added: Site ID parameter in the sync request -* Updated: MainWP_Child_WPvivid_BackupRestore class -* Preventative: Security improvements - -= 4.0.5.1 - 12-13-19 = -* Fixed: Child Reports data conversion problem - -= 4.0.5 - 12-9-19 = -* Added: support for the Pro Reports extension -* Fixed: MainWP Child Reports version 2 compatibility - -= 4.0.4 - 11-11-19 = -* Fixed: WordPress 5.3 compatibility problems -* Fixed: An issue with managing BackWPup backups -* Updated: Multiple error messages -* Removed: Unused code - -= 4.0.3 - 10-1-19 = -* Added: 'mainwp_child_branding_init_options' filter for disabling custom branding -* Updated: Support for the WPVulnDB API v3 -* Removed: Unused code and files - -= 4.0.2 - 9-6-19 = -* Fixed: An issue with incorrect backups count in the Client Reports system - -= 4.0.1 - 9-3-19 = -* Fixed: An issue with clearing and preloading WP Rocket cache - -= 4.0 - 8-28-19 = -* Fixed: Various functionality problems -* Added: Support for upcoming 3rd party extensions -* Added: .htaccess file with custom redirect to rule the MainWP Child plugin directory to hide the plugin from search engines -* Updated: Support for the MainWP Dashboard 4.0 -* Updated: Notifications texts -* Removed: Unused code - -= 3.5.7 - 5-6-19 = -* Fixed: Multiple PHP Warnings -* Fixed: Multiple conflicts with 3rd party products -* Fixed: An issue with Page Speed data for custom URLs -* Fixed: An issue with logging WP Time Capsule backups on specific setups -* Fixed: An issue with short login session -* Added: Multiple security enhancements -* Added: Support for the WP Staging Pro (free features only) -* Added: Support for plugin/theme installation requests to HTTP Basic Auth protected MainWP Dashboards - -= 3.5.6 - 3-25-19 = -* Fixed: An issue with checking Page Speed data -* Fixed: An issue with empty update data -* Fixed: An issue with incorrect plugin update data -* Added: Send From field in the Branding support form -* Updated: Compatibility with the latest Yoast SEO plugin version - -= 3.5.5 - 3-6-19 = -* Fixed: An issue with the hook for controlling branding options for specific roles -* Fixed: Branding issues -* Fixed: Multiple PHP Warnings -* Fixed: Multiple typos -* Fixed: MainWP UpdraftPlus Extension performance issues -* Fixed: An issue with creating double media files when editing posts and pages from MainWP Dashboard -* Fixed: An issue with creating duplicate Boilerplate posts and pages -* Updated: Added improvements for detecting premium plugin updates on specific setups - -= 3.5.4.1 - 2-19-19 = -* Added: Proper attribution to plugin code used for Extensions -* Removed: Unused code - -= 3.5.4 - 2-14-19 = -* Fixed: Issues with displaying broken links data for specific setups -* Fixed: Compatibility issues with the latest PageSpeed Insights plugin version -* Fixed: An issue with publishing "future" posts -* Fixed: An issue with sending email alerts in specific setups -* Fixed: An issue with saving code snippets in wp-config.php when the file is in a custom location -* Fixed: An issue with clearing unused scheduled Cron jobs -* Added: Support for the new PageSpeed Insights plugin options -* Updated: Disabled the "Remove readme.html" security check feature for WPEngine-hosted child sites -* Updated: Support for detecting premium themes updates - -= 3.5.3 - 12-19-18 = -* Fixed: An issue with the X-Frame-Options configuration -* Fixed: An issue with clearing WP Rocket cache -* Fixed: An issue with saving BackWPup settings -* Fixed: Multiple compatibility issues for the Bulk Settings Manager Extension -* Fixed: An issue with submitting the Bulk Settings Manager keys on child sites protected with the HTTP Basic Authentication -* Fixed: An issue with creating buckets in Backblaze remote option caused by disallowed characters -* Fixed: An issue with tokens usage in the UpdraftPlus Webdav remote storage settings -* Added: Support for new WP Staging plugin options -* Updated: Update detection process to improve performance on some hosts -* Updated: Disabled site size calculation function as the default state -* Updated: Support for the latest Wordfence version - -= 3.5.2 - 11-27-18 = -* Fixed: An issue with detecting updates when a custom branding is applied -* Fixed: An issue with passing WebDav remote storage info for the UpdraftPlus Extension -* Fixed: An issue with grabbing fresh child site favicons -* Updated: Process to skip WooCommerce order notes in the comments section for Client Reports - -= 3.5.1 - 11-14-18 = -* Fixed: An issue with detecting the Wordfence status info -* Fixed: An issue with loading UpdraftPlus existing backups -* Fixed: The File Uploader extension issue with renaming special files -* Fixed: An issue with syncing BackupBuddy data -* Fixed: An issue with logging BackWPup backups -* Fixed: An issue with detecting premium plugin updates -* Added: New options for the MainWP Staging Extension -* Added: Multiple security enhancements -* Added: Support for the upcoming 3rd party extension -* Updated: Improved the updating process - -= 3.5 - 9-27-18 = -* Fixed: compatibility issues caused by the recent UpdraftPlus update -* Fixed: issues with the WooCommerce Status information -* Fixed: issues with Bulk Settings Manager for specific plugins -* Added: mainwp_child_mu_plugin_enabled hook to allow MainWP Child usage as a must-use plugin -* Added: support for recording WP Time Capsule backups for Client Reports -* Added: mainwp_branding_role_cap_enable_contact_form hook to allow users to show Support Form (Branding extension option) to specific roles -* Added: support for the new BackUpWordPrress Extension feature -* Added: Support for the new MainWP Buddy Extension feature -* Updated: reporting system to determine backup type for BackWPup backups -* Improved: connection stability for sites hosted on hosts with small execution time limits -* Improved: detecting updates for premium plugins - -= 3.4.9 - 7-23-18 = -* Fixed: MainWP iThemes Security Extension issues caused by the latest iThemes Security plugin version - -= 3.4.8 - 6-26-18 = -* Fixed: issues caused by deprecated functions -* Added: mainwp_before_post_update hook -* Added: support for the new extension -* Added: conditional checks to prevent possible conflicts with certain pluginsΒ  -* Added: support for the new MainWP Branding Extension feature -* Improved: PHP 7.2 compatibility - -= 3.4.7.1 - 5-25-18 = -* Fixed: UpdraftPlus 1.14.10 compatibility issue that caused child sites to disconnect -* Added: support for the new MainWP Branding Extension option -* Updated: compatibility with the new Wordfence plugin version -* Updated: compatibility with the new WP Rocket plugin version - -= 3.4.7 - 4-17-18 = -* Fixed: multiple cloning issues -* Fixed: timezone issue backup timestamp -* Fixed: MainWP Branding Extension conflict that caused issues with hooking WP-Admin menu items -* Fixed: MainWP Branding Extension issue with hiding WordPress update nag -* Fixed: MainWP Branding Extension issue with updating WordPress footer content -* Fixed: issues with loading broken links data -* Fixed: multiple PHP 7.2 warnings -* Added: Support for the Backblaze backup remote destination (UpdraftPlus Extension) -* Added: support for recording Live Stash updates for Client Reporting -* Updated: recent Wordfence plugin version compatibility -* Updated: recent WP Staging plugin version compatibility - -= 3.4.6 - 2-21-18 = -* Fixed: Wordfence 7 compatibility issues -* Added: multiple security enhancements -* Updated: admin notice text - -= 3.4.5 - 1-22-18 = -* Fixed: Multiple issues with cloning sites -* Fixed: An issue with passing metadata for featured images -* Fixed: An issue with the sync process caused by syncing an extremely large amount of data -* Fixed: Multiple PHP Warnings -* Added: Support for the new MainWP Wordfence Extension options -* Added: multiple security enhancements -* Updated: new BackWPup version compatibility - -= 3.4.4 - 12-4-17 = -* Fixed: compatibility issue with the latest UpdraftPlus Backups plugin version -* Fixed: compatibility issue with the latest iThemes Security plugin version -* Fixed: An issue with updating certain plugins -* Fixed: An issue with installing certain plugins -* Fixed: An issue with logging the BackupBuddy backups for client reports -* Fixed: An issue with syncing sites that run older versions of the BackupBuddy plugin -* Fixed: An issue with calculating site size on Windows servers -* Fixed: An issue with disabling Pro modules for the iThemes Security plugin -* Fixed: An issue with saving Amazon S3 settings for the UpdraftPlus extension -* Added: Support for the upcoming extension -* Added: Support for the new MainWP iThemes Security Extension options -* Added: Support for the search by Title option -* Added: Support for the new MainWP UpdraftPlus Extension options -* Added: Support for the new MainWP Buddy Extension options -* Added: support for the new version of the MainWP WooCommerce Status extension -* Added: the mainwp-child-get-total-size hook for disabling the get total size of a site function -* Updated: the process for displaying info for scheduled posts and pages - -= 3.4.3 - 8-24-17 = -* Fixed: An issue with saving Bulk Setting Manager keys on some HTTPS sites -* Fixed: timeout issues for the Bulk Settings Manager Extension -* Fixed: multiple issues with saving remote storage settings for the UpdraftPlus extension -* Fixed: An issue with 404 email notification templates for the Maintenance extension -* Fixed: An issue with saving Post and Page status as Private -* Fixed: An issue with displaying the incorrect number of updates caused by server conflict -* Fixed: An issue with displaying the locked status for Posts and Pages while the Post/Page is being edited in MainWP Dashboard -* Added: a function to check if a post or a page is being edited before saving changes from MainWP Dashboard -* Added: the new 'mainwp_child_after_newpost' hook -* Updated: compatibility for the new version of the Bulk Settings Manager Extension -* Updated: compatibility with the new version of the BackupBuddy plugin -* Updated: compatibility with the new version of the Wordfence plugin -* Updated: compatibility with the new version of the UpdraftPlus plugin -* Updated: compatibility with the new version of the Yoast SEO plugin -* Updated: compatibility with the new version of the iThemes Security extension -* Updated: reduced number of database queries to improve performance -* Updated: display options for the Custom Post Types extension -* Updated: header response to 403 for the applied security fix preventing directory listing - -= 3.4.2 - 7-11-17 = -* Fixed: An issue with saving BackWPup job files -* Fixed: conflict with the Color Picker library -* Fixed: An issue with executing multiple updates at once on a site detected on some setups -* Fixed: An issue with cloning sites from a backup file detected on some setups -* Updated: support for the new Google PageSpeed Insights plugin version -* Updated: the Contact Support branding feature will be visible only to Administrator users - -= 3.4.1 - 6-12-17 = -* Fixed: An issue with the update process on some setups -* Fixed: An issue with cloning sites from a backup file -* Updated: support for the new WP Rocket settings for the new version of the Rocket extension - -= 3.4 - 5-11-17 = -* Fixed: An issue with updating plugins and themes on some server setups -* Fixed: An issue with the child site connection after cloning the site -* Fixed: An issue with saving iThemes Security settings -* Fixed: An issue with recording empty values for the Client Reports -* Fixed: An issue with creating a custom post type posts -* Fixed: An issue with incorrect slugs created after publishing drafts -* Fixed: An issue with showing correct tabs if a custom branding applied -* Fixed: An issue with syncing sites when the MainWP Buddy extension is used -* Fixed: An issue with saving BackupBuddy settings -* Added: support for new Wordfence features - -= 3.3 - 2-22-17 = -* Fixed: An issue with syncing sites when the Client Reports Extension is activated -* Fixed: minor issues with Wordfence Extension support -* Added: Support for the MainWP Vulnerability Checker Extension - -= 3.2.7 - 1-19-17 = -* Fixed: An issue with removing Scripts and Stylesheets version number -* Fixed: Multiple PHP Warnings -* Fixed: JS issue that occurs when a MainWP Child plugin update is available and the plugin has been rebranded - -= 3.2.6 - 1-5-17 = -* Added: support for the Divi (Elegant Themes) themes updates - -= 3.2.5 - 12-30-16 = -* Added: support for the new WP Rocket options -* Added: support for the new display favicon process -* Updated: site connection process (MD5 encryption not supported) -* Updated: multiple functions refactored -* Preventative: Security improvements - -= 3.2.4 - 12-09-16 = -* Fixed: Conflict with SendGrid - -= 3.2.3 - 12-08-16 = -* Fixed: Compatibility issues with PHP versions -* Preventative: Security improvements - -= 3.2.2 - 12-01-16 = -* Fixed: An issue with activating the BackUpWordPress plugin -* Fixed: An issue with the edit user feature -* Fixed: An issue with activating the WP Rocket plugin -* Fixed: An issue with displaying Scheduled Posts and Pages in the Recent Posts and Recent Pages widget -* Fixed: An issue with false alert with PHP Max Execution time set to -1 -* Fixed: incorrect links to the MainWP Child Setting page -* Fixed: An issue with UpdraftPlus Pro version updates -* Fixed: An issue with showing the MainWP Child Plugin updates in client reports when the MainWP Child Plugin is hidden -* Added: support for %sitename% and %site_url% tokens for directory path settings for the UpdraftPlus extension -* Added: Support for the new Edit Posts and Pages process -* Added: 'mainwp_create_post_custom_author' hook -* Added: Support for the Reload remote destination function (MainWP Buddy Extension) -* Added: Support for the new Wordfence options -* Updated: PHP recommendation bumped to 5.6 - -= 3.2.1 - 10-26-16 = -* Added: Support for PHP 5.4 and below - -= 3.2 - 10-26-16 = -* Fixed: An issue with installing plugins and themes on HTTP Basic Authentication protected sites -* Fixed: An issue with Themes search on the Auto Update themes page -* Fixed: An issue with getting the child site favicon -* Fixed: An issue where BackUpWordPress schedules couldn't be found -* Fixed: An issue with recording BackWPup, BackUpWordPress, and BackupBuddy backups for Client Reports -* Fixed: An issue with dismissing warning message if the WordPress All Import plugin is installed -* Fixed: An issue with publishing Drafts from the Post Plus extension -* Added: Support for the new Edit User feature -* Added: Connection details tab -* Added: Support for deleting active plugins -* Updated: Number of categories pulled from child sites (from 50 to 300) - -= 3.1.7 - 8-18-16 = -* Fixed: Issues with PHP 7 - The MainWP Child is now PHP 7-friendly! :-) -* Added: Support for an upcoming extension (BacukpBuddy Extension) - -= 3.1.6 - 8-2-16 = -* Fixed: An issue with loading too much data from the Broken Links Checker -* Fixed: An issue with saving UpdraftPlus extension settings -* Fixed: An issue with extracting URL for the MainWP URL Extractor Extension -* Fixed: An issue with including new tables in database backup for individual BackWPup Extension jobs -* Updated: support for new iThemes Security options - -= 3.1.5 - 7-12-16 = -* Fixed: Incompatibility with the new version of the iThemes Security version -* Added: Support for the new iThemes Security features -* Added: Support for the new WP Rocket features -* Added: "Currently connected to" check in the Server Information -* Fixed: PHP Notice -* Removed: Unnecessary checks in the Server Information page - -= 3.1.4 - 5-9-16 = -* Updated: function execute_snippet() extracted to a separate file - -= 3.1.3 - 4-28-16 = -* Fixed: Issue with repeating the delete process of the readme.html file -* Fixed: PHP Warning -* Fixed: Issue with replacing image source -* Fixed: Incorrect replacement of the href attribute for image external links -* Fixed: Issue with saving Wordfence option on Dreamhost hosting -* Fixed: Issue with saving PageSpeed Settings and syncing PageSpeed data -* Fixed: Secure login issue with some plugin/theme updates -* Fixed: Connection timeouts due to large sites -* Added: MU-Plugins support -* Added: Support for publishing Image Galleries in Posts and Pages -* Updated: MainWP Child plugin pages layout -* Updated: Support for the new version of the BackUpWordPress plugin -* Removed: Plugin and Theme Conflicts check feature - -= 3.1.2 - 3-15-16 = -* Fixed: False connection issue warning -* Fixed: Smart Manager For WP eCommerce not updating -* Fixed: Multiple mixed content warnings -* Added: Support for Wordfence performance options - -= 3.1.1 - 3-3-16 = -* Fixed: Checking abandoned plugins not in the WP repository -* Fixed: Bug when running BackupWordPress backup -* Fixed: Bug adding cache settings for WordFence Extension -* Added: Feature to generate server information -* Added: Server Information items -* Added: New Subject text box to support email in Branding Extension -* Added: Support themes using invalid screen functions -* Tweaked: Support new version of BackupWordPress plugin version -* Updated: Added support in Client Reports Extension for BackWPup backups - -= 3.1 - 2-17-16 = -* Fixed: PHP notices -* Fixed: Escape HTML error for the contact support feature of the Branding Extension -* Fixed: The issue with removing the generator version -* Fixed: Update issue for the iThemes Security Pro and the Monarch plugin -* Fixed: Compatibility issue with the BackUpWordPress plugin -* Added: Auto detect manually removed script/style versions feature -* Added: WordPress translation updates -* Added: New Branding option to turn off theme switching -* Enhancement: Removed ctype_digit requirement -* Enhancement: Install plugin error message - -= 3.0.2 - 1-22-16 = -* Fixed: Issue with scheduled BackupWordPress when running from Dashboard -* Fixed: Issue with Heatmap tracker JavaScript -* Added: Support for hosts with PHP with disabled mb_regex -* Tweaked: Code snippet result message - -= 3.0.1 - 1-18-16 = -* Fixed: HTML output of branding contact form -* Added: Auto retry install plugin/theme if the installation fails -* Fixed: Issue with rendering CSS used in the Branding extension - -= 3.0 - 1-12-16 = -* Fixed: Refactored code to meet WordPress Coding standards -* Fixed: Deprecated Function -* Fixed: Fatal Error caused by the MainWP Rocket Extension -* Fixed: Issue introduced with the new version of the iThemes Security plugin -* Fixed: Link Manager Extension bug with special characters in URL -* Fixed: MainWP Client Reports Extension bug caused by a high number of posts logged in the database -* Fixed: Generator meta tag issue -* Fixed: Wordfence Extension issue with displaying incorrect last scan time -* Fixed: Broken Link Extension bug -* Fixed: MainWP Heatmaps Extension bug -* Fixed: Abandoned Plugins/Themes function bug with registering multiple cron jobs -* Fixed: CSS issue -* Fixed: Escaped HTML -* Fixed: PHP error reporting security alert -* Added: Support for the MainWP Rocket Extension to load existing WP Rocket settings -* Added: Support for Export/Import settings for the Wordfence Extension -* Added: Support new Wordfence settings options for the Wordfence Extension -* Added: Force Check Pages function for the MainWP PageSpeed Extensions -* Added: Allow to see MainWP child plugin in MainWP Dashboard plugins search -* Updated: MainWP URL Extractor Extension logic to extract URLs by Post published date instead of last change date - -= 2.0.29 - 9-22-15 = -* Fixed: 404 error that occurs in case Links Manager extension is in use when child plugin is hidden -* Fixed: Bug with detecting updates of hidden plugins (UpdraftPlus, BackUpWordPress, WP Rocket) -* Fixed: Bug with overwriting Amazon S3 settings in the BackUpWordPress plugin -* Fixed: Bug with empty values for Text Link and Link Source options in Broken Links Checker Extension -* Fixed: Bug with bulk repair action in Wordfence Extension -* Fixed: Bug with incorrect File System Method detection -* Added: Support for an upcoming Extension - -= 2.0.28 - 9-7-15 = -* Fixed: Security Issue (MainWP White Hat Reward Program) -* Fixed: Support for the Stream 3 plugin -* Fixed: Client Reports issues with recording autosaves for Posts and Pages -* Fixed: An issue with detection for Abandoned Plugins & Themes that are not hosted on WP.org - -= 2.0.27 - 9-2-15 = -* Fixed: Security Issue (MainWP White Hat Reward Program) - -= 2.0.26 - 9-1-15 = -* Fixed: Conflict with Stream 3 (Thanks to Luke Carbis of Stream) - -= 2.0.25 - 8-31-15 = -* Fixed: Issue with Client Reports extension where comments records were not displayed correctly -* Added: Support for missing Client Report records - -= 2.0.24 - 8-20-15 = -* Fixed: Incorrect last update value for abandoned plugins & themes feature -* Fixed: Branding for Server Information page and Clone page title -* Fixed: Incorrect heatmap data and warnings -* Fixed: Can not add child site because get favicon timeout -* Fixed: Hiding UpdraftPlus, WP Rocket toolbar, and their notices when set to hide plugins - -= 2.0.23 - 8-7-15 = -* Fixed: An issue with Heatmaps not loading -* Added: Support for the Establish New Connection feature -* Added: Support for the Abandoned plugins detection feature -* Added: Support for the Abandoned themes detection feature - -= 2.0.22 - 7-22-15 = -* Fixed: Bug where the OptmizePress theme has not been updated properly -* Fixed: Bug where the Client Report extension recorded incorrect time -* Added: Support for the upcoming extension - -= 2.0.21 - 7-9-15 = -* Fixed: Bug with the time schedule for the UpdraftPlus extension -* Added: Support for the upcoming extension - -= 2.0.20 - 7-6-15 = -* Fixed: Bug with the time schedule for the UpdraftPlus extension -* Fixed: Bug in the Scan for backups feature for the UpdraftPlus extension -* Fixed: Bug with saving email report option for the free version of the UpdraftPuls plugin -* Fixed: Bug that was causing the BackupBuddy updates to fail -* Updated: Only users with the Administrator role can see the MainWP Child menu - -= 2.0.19 - 6-10-15 = -* Added: Filesystem Check on the Server Information page -* Added: Support for the MainWP Child Report plugin -* Added: Support for the new UpdraftPlus Extension options -* Enhancement: Speed up directory listing by using fewer resources, reducing timeout issues -* Fixed: Plugin/theme upgrade issue when no file system method is specified -* Fixed: X-Frame-Options - ALLOWALL bug -* Fixed: Timeout error for the stats child data function -* Fixed: An error with the Synchronous XMLHttpRequest for tracker.js -* Fixed: Expert settings options for the UpdraftPlus Extension -* Fixed: Calculation error for the PHP Memory Limit, PHP Max Upload Filesize, and PHP Post Max Size checks - -= 2.0.18 - 5-30-15 = -* Fixed: False malware alert - -= 2.0.17 - 5-23-15 = -* Fixed: Bug where some premium plugins didn't update -* Fixed: Bug where some Favicons didn't display correctly -* Fixed: Bug where relative links didn't show correctly in posts - -= 2.0.16 - 5-15-15 = -* Fixed: Issue with sites running PHP 5.2 and lower -* Fixed: Sync error on some sites with UpdraftPlus installed -* Fixed: PHP Warning -* Changed: Server page to reflect a requested minimum of PHP 5.3 - -= 2.0.15 - 5-14-15 = -* Added: Support for the upcoming extension -* Fixed: Post categories not showing on Dashboard -* Fixed: Potential malware false alert issue -* Fixed: Spelling error -* Updated: Required values on the Server Information page -* Updated: Layout of the Server Information page -* Removed: Unnecessary checks from the Server Information page -* Enhancement: Reduced page load time by autoloading common options - -= 2.0.14 - 4-28-15 = -* Fixed: Handling of updates when plugins change folder structure or name - -= 2.0.13 - 4-22-15 = -* Fixed: Security Issue with add_query_arg and remove_query_arg - -= 2.0.12 - 4-16-15 = -* Fixed: Bug for the MainWP iThemes Security Extension -* Fixed: Bug for the MainWP WordFence Extension -* Fixed: Bug where the MainWP Child plugin was breaking Cron jobs on child sites - -= 2.0.11 - 4-12-15 = -* Fixed: Upcoming extension bug - -= 2.0.10 - 4-06-15 = -* Added: Support for the display Favicon for child sites feature -* Added: Support for upcoming extension -* Fixed: Plugin conflicts with WordPress SEO by Yoast and Backupbuddy - -= 2.0.9.2 - 3-06-15 = -* Fixed: Bug where SEO values are not being set for Boilerplate Pages and Posts -* Added: Function for removing keywords and Links Manager extension settings -* Fixed: Security issue allowing some users to log on to the child site - -= 2.0.9.1 - 3-05-15 = -* Added: Allow Extension to work with IThemes Security Pro - -= 2.0.9 - 3-01-15 = -* Added: Support for the Polish language -* Added: Support for the Greek language -* Added: Support for the upcoming extension -* Fixed: Bug that was causing plugin bulk installation to fail caused by disabled functions (e.g., curl_multi_exec) -* Tweaked: Fewer PHP notices - -= 2.0.8 - 2-11-15 = -* Fixed: Not all site references updated after clone -* Fixed: Fixed some PHP warnings - -= 2.0.7.1 - 2-05-15 = -* Fixed: Hostgator detection caused issues on some hosts -* Fixed: Russian/Arabic not shown properly -* Tweak: Heatmap tracker now consumes less memory when uploading the tracked clicks - -= 2.0.7 - 2-01-15 = -* Fixed: Backup issues on Windows-hosts -* Fixed: PHP Warning message when cloning -* Added: Detect Hostgator-host to enhance settings while backing up - -= 2.0.6 - 1-14-15 = -* Fixed: Uploading tar.bz2 to clone from is no longer blocked -* Fixed: Saving heatmap options process -* Fixed: Branding extension options - hiding child plugin pages -* Added: A new Branding extension option - hiding the child plugin server information page - -= 2.0.5 - 1-07-15 = -* Fixed: Links Manager Extension: Now using the WordPress home option instead of The Site URL for the links - -= 2.0.4 - 12-26-14 = -* Fixed: Backups for hosts having issues with "compress.zlib://" stream wrappers from PHP causing corrupt backup archives -* Fixed: "Another backup is running" message displaying incorrectly - -= 2.0.3 - 12-15-14 = -* Fixed: Possible security issue - -= 2.0.2 - 12-11-14 = -* Added: Support hosts with PHP Heap classes -* Fixed: JavaScript issue disabling the popup menu on the admin menu - -= 2.0.1 - 12-10-14 = -* Fixed: Restore/Clone from Tar via server upload - -= 2.0 - 12-09-14 = -* Added: Tar GZip as a backup file format -* Added: Tar Bzip2 as a backup file format -* Added: Tar as a backup file format -* Added: Feature to resume unfinished or stalled backups -* Added: Feature to detect if backup is already running -* Added: New feature for the new Branding extension - Preserve branding option if child site gets disconnected -* Fixed: Bug where the Stream plugin update was showing if the plugin was hidden -* Fixed: MainWP Child Server Information page layout fixed -* Fixed: Restore issue in case the child plugin is hidden with the Branding Extension -* Tweak: New feature for the File Uploader extension - wp-content folder auto-detected if renamed -* Tweak: Heatmap tracker script disabled by default -* Tweak: Updated the Warning message in case the child site is disconnected -* Tweak: Updated the Warning message in case the child site is disconnected -* Redesign: CSS updated to match the Dashboard style -* Redesign: MainWP Child Settings page layout updated -* Redesign: MainWP Child Clone/Restore layout updated -* Refactor: Added MainWP Child menu added in the WP Admin Menu -* Refactor: MainWP Child Settings, MainWP Clone/Restore, and MainWP Child Server Information pages removed from the WP Settings menu and added to MainWP Child - -= 1.3.3 - 9-21-14 = -* Added new hooks for Wordfence Extension -* Fixed issue with WooCommerce Extension - -= 1.3.2 - 9-16-14 = -* Fixed Permission denied issue when restoring from a backup on the Dashboard - -= 1.3.1 = -* Fixed Issue with a new post that sometimes returned no child -* Fixed Removed duplicate restore link in the Tools section - -= 1.3 = -* Added: Better error reporting on backup fail -* Added: Future support for the auto-detection of file descriptors -* Added: Support for new Client Report Extension features -* Added: Support for new Branding Extension features -* Added: Additional Hooks for new Extensions -* Fixed: Issue with some hosts not supporting garbage collection functions - -= 1.2 = -* Added Additional tweaks for fewer Backup timeouts -* Added A new option to enable more IO instead of memory approach for Backups -* Fixed Dropbox error when directory ends with space -* Fixed deprecated theme calls -* Fixed issues with self-signed SSL certificates -* Fixed some user interface issues -* Removed incorrect "This site may to connect to your dashboard or may have other issues" when there are SSL warnings - -= 1.0 = -* Added: Communication to Dashboard during backups to locate common backup locations -* Added: Communication to Dashboard during backups to locate common cache locations -* Added: Communication to Dashboard during backups to locate non-WordPress folders -* Added: Communication to Dashboard during backups to locate Zip Archives -* Added: Several new subtasks to increase performance and reduce timeouts on Backups -* Added: New Hooks for Extensions -* Fixed: Restore on Child site not timing out -* Additional CSS and Cosmetic Tweaks - -= 0.29.13 = -* Enhancement: Faster backups by using fewer file descriptors - -= 0.29.12 = -* Added: Attempt to overwrite site time limit settings to help prevent timeouts -* Added: Attempt to reset site time-out timer at intervals to help prevent timeouts - -= 0.29.11 = -* Changes for an update to Client Reports Extension -* Changes for an update to Heat Map Extension -* Changes for an update to Maintenance Extension -* Fixed verbiage for restore popup - -= 0.29.10 = -* Fixed: Admin not accessible with invalid upload directory -* Added new hooks for upcoming extensions - -= 0.29.9 = -* Added new hooks for upcoming extensions - -= 0.29.8 = -* Fix for uploads path outside the conventional path for backups -* Added new hooks for upcoming extensions - -= 0.29.7 = -* Server Information page added for troubleshooting -* Added server warning messages when minimum requirements not met -* Added warning messages when child plugin detects possible conflict plugins -* Added new hooks for upcoming extensions - -= 0.29.6 = -* Fixed plugin conflict with Maintenance plugin -* Added zip support to database backups - -= 0.29.5 = -* Update for File Uploader Extension -* Added new hooks for upcoming extensions - -= 0.29.4 = -* Fixed performance issue with autoloaded options -* File Uploader Extension Bug Fix -* Added new hooks for upcoming extensions - -= 0.29.3 = -* Added new hooks for upcoming extensions - -= 0.29.2 = -* Fix for ini_set warning when this has been disabled on the host - -= 0.29.1 = -* Backups now use structure tags on child sites too -* Small fixes for the maintenance extension - -= 0.29 = -* Added ability to view Child site error logs on MainWP Dashboard -* Added ability to view Child site wp-config.php on MainWP Dashboard -* Added new Hooks for Branding Extension -* Added tweak for Code Snippet Extension - -= 0.28.4 = -* More Extension Hooks to extend Code Snippet functionality - -= 0.28.3 = -* Fixed some issues with the Code Snippets extension - -= 0.28.2 = -* Fixed update conflict with child plugin installed on Dashboard -* Fixed some warnings with debugging enabled - -= 0.28.1 = -* Fixed a bug on line 3269 when debug is on - -= 0.28 = -* Hooks added for Code Snippets Extensions - -= 0.27.2 = -* Additional hooks added - -= 0.27.1 = -* Incorrect text fixed -* New Text re-coded for translation -* Tweaked writable directory checks -* Added more hooks for upcoming Extensions - -= 0.27 = -* Code Changes for WP 3.9 Compatibility -* Added Select from Server option for larger Backups -* Added additional hooks for upcoming Extensions - -= 0.26 = -* Minor fix for heatmap extension - -= 0.25 = -* Fix for premium plugins - -= 0.24 = -* Added support for premium plugins -* Fixed the restore functionality disappearing without Clone Extension -* Fixed some deprecated calls - -= 0.23 = -* Fixed some deprecated warnings -* Fixed issues with the Keyword Links extension - -= 0.22 = -* Added extra functionality for keyword link extension - -= 0.21 = -* Fixed clone issue for some hosts with FTP settings -* German translations added -* Support for 1.0.0 major version of the main Dashboard - -= 0.20 = -* Fixed the BPS-conflict where plugins were not upgrading - -= 0.19 = -* Fixed issue for upgrading core/themes/plugins without FTP credentials - -= 0.18 = -* Fixed issue for sending correct roles to the main Dashboard -* Added teh htaccess file backup (backed up as mainwp-htaccess to prevent restore conflicts) - -= 0.17 = -* Tuned for faster backup -* Added extension support for Maintenance extension - -= 0.16 = -* Fixed some plugin conflicts preventing updates to themes/plugins/core - -= 0.15 = -* Fixed issue with mismatching locale on core update - -= 0.14 = -* Fixed redirection issue with wrongly encoded HTTP request - -= 0.13 = -* Added restore function - -= 0.12 = -* Fixed conflict with the main Dashboard on the same site - -= 0.11 = -* Plugin localization -* Extra check for readme.html file -* Added child server information -* Fixed restore issue: not all previous plugins/themes were removed -* Fixed backup issue: not all files are being backed up - -= 0.10 = -* Fixed plugin conflict -* Fixed backup issue with database names with dashes -* Fixed date formatting -* Tags are now being saved to new posts -* Fixed issue when posting an image with a link - -= 0.9 = -* Fixed delete permanently bug -* Fixed plugin conflict - -= 0.8 = -* Fixed issue with Content Extension -* Added feature to add sticky posts - -= 0.7 = -* Fixed the message "This site already contains a link" even after reactivating the plugin - -= 0.6 = -* Fixed plugin conflict with WooCommerce plugin for cloning -* Fixed backups having double the size - -= 0.5 = -* Fixed issue with importing database with custom foreign key references -* Fixed issue with disabled functions from the "Suhosin" extension -* Fixed issue with click-heatmap - -= 0.4 = -Fixed cloning issue with a custom prefix - -= 0.3 = -* Fixed issues with cloning (not cloning the correct source if the source was cloned) - -= 0.2 = -* Added unfix option for security issues - -= 0.1 = -* Initial version - -== Upgrade Notice == - -= 4.5 = -This is a major upgrade please check the [MainWP Upgrade FAQ](https://kb.mainwp.com/docs/upgrading-to-mainwp-v4-5/) \ No newline at end of file +[See changelog for all versions.](https://mainwp.com/mainwp-child-changelog.txt) \ No newline at end of file From 14b8588ffe1f7dd7e14d804cec17adec7609e72a Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Thu, 4 Apr 2024 14:49:22 +0000 Subject: [PATCH 2/9] [CodeFactor] Apply fixes to commit c47da88 [ci skip] [skip ci] --- class/class-mainwp-child-cache-purge.php | 2 +- class/class-mainwp-child-wp-rocket.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/class/class-mainwp-child-cache-purge.php b/class/class-mainwp-child-cache-purge.php index a447b1c0..f4c3f2ad 100644 --- a/class/class-mainwp-child-cache-purge.php +++ b/class/class-mainwp-child-cache-purge.php @@ -466,7 +466,7 @@ public function wp_optimize_auto_purge_cache() { $preload = self::wp_optimize_preload_cache(); // Check response & return results. - if ( ( true === $purge && true === $preload ) || ( true === $minify && true === $purge && true === $preload ) ) { + if ( ( true === $purge && true === $preload ) || ( true === $minify && true === $purge && true === $preload ) ) { update_option( 'mainwp_cache_control_last_purged', time() ); return $this->purge_result( $success_message, 'SUCCESS' ); diff --git a/class/class-mainwp-child-wp-rocket.php b/class/class-mainwp-child-wp-rocket.php index a029cc0a..a2ecc082 100644 --- a/class/class-mainwp-child-wp-rocket.php +++ b/class/class-mainwp-child-wp-rocket.php @@ -530,7 +530,7 @@ public function purge_cloudflare() { } } - private function require_file_path($functionName, $fileName) { + private function require_file_path( $functionName, $fileName ) { if ( ! function_exists( $functionName ) && defined( 'WP_ROCKET_FUNCTIONS_PATH' ) ) { require_once WP_ROCKET_FUNCTIONS_PATH . $fileName; } From 84db7555448889736c24ec47e3317fd907bbc879 Mon Sep 17 00:00:00 2001 From: thanghv Date: Thu, 4 Apr 2024 21:51:08 +0700 Subject: [PATCH 3/9] Fixed codefactor issues --- class/class-mainwp-child-wp-rocket.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/class/class-mainwp-child-wp-rocket.php b/class/class-mainwp-child-wp-rocket.php index a029cc0a..a9def568 100644 --- a/class/class-mainwp-child-wp-rocket.php +++ b/class/class-mainwp-child-wp-rocket.php @@ -530,7 +530,7 @@ public function purge_cloudflare() { } } - private function require_file_path($functionName, $fileName) { + private function require_file_path( $functionName, $fileName ) { if ( ! function_exists( $functionName ) && defined( 'WP_ROCKET_FUNCTIONS_PATH' ) ) { require_once WP_ROCKET_FUNCTIONS_PATH . $fileName; } @@ -550,9 +550,9 @@ public function purge_cache_all() { set_transient( 'rocket_clear_cache', 'all', HOUR_IN_SECONDS ); // Require files to make sure the functions are available. - $this->require_file_path('get_rocket_i18n_uri', 'i18n.php'); - $this->require_file_path('get_rocket_parse_url', 'formatting.php'); - $this->require_file_path('create_rocket_uniqid', 'admin.php'); + $this->require_file_path( 'get_rocket_i18n_uri', 'i18n.php' ); + $this->require_file_path( 'get_rocket_parse_url', 'formatting.php' ); + $this->require_file_path( 'create_rocket_uniqid', 'admin.php' ); rocket_clean_domain(); rocket_clean_minify(); From f20d85593a3daf747fb2c256873303ceba5bc387 Mon Sep 17 00:00:00 2001 From: thanghv Date: Thu, 4 Apr 2024 21:54:01 +0700 Subject: [PATCH 4/9] Fixed codefactor issues --- class/class-mainwp-child-wp-rocket.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/class/class-mainwp-child-wp-rocket.php b/class/class-mainwp-child-wp-rocket.php index a9def568..20aa4802 100644 --- a/class/class-mainwp-child-wp-rocket.php +++ b/class/class-mainwp-child-wp-rocket.php @@ -530,6 +530,14 @@ public function purge_cloudflare() { } } + /** + * Method require_file_path() + * + * Include necessary files. + * + * @param string $functionName function Name. + * @param string $fileName file Name. + */ private function require_file_path( $functionName, $fileName ) { if ( ! function_exists( $functionName ) && defined( 'WP_ROCKET_FUNCTIONS_PATH' ) ) { require_once WP_ROCKET_FUNCTIONS_PATH . $fileName; From 6f31a098b9faab96bb75e2457d38953bbad225b6 Mon Sep 17 00:00:00 2001 From: Keith Crain Date: Thu, 4 Apr 2024 13:48:22 -0400 Subject: [PATCH 5/9] Addition: Support for Pressable Cache Purge --- class/class-mainwp-child-cache-purge.php | 1674 +++++++++++----------- 1 file changed, 846 insertions(+), 828 deletions(-) diff --git a/class/class-mainwp-child-cache-purge.php b/class/class-mainwp-child-cache-purge.php index f4c3f2ad..509ed841 100644 --- a/class/class-mainwp-child-cache-purge.php +++ b/class/class-mainwp-child-cache-purge.php @@ -1,1067 +1,1085 @@ encrypt_string( $data['mainwp_cloudflair_key'] ); - } else { - $encrypted = ''; + /** + * Method sync_others_data() + * + * Sync data to & from the MainWP Dashboard. + * + * @param array $information Array containing the data to be sent to the Dashboard. + * @param array $data Array containing the data sent from the Dashboard; to be saved to the Child Site. + * + * @return array $information Array containing the data to be sent to the Dashboard. + */ + public function sync_others_data( $information, $data = array() ) { + + // ** Grab data synced from MainWP Dashboard & update options. **// + if ( is_array( $data ) ) { + try { + + // Update mainwp_child_auto_purge_cache option value with either yes|no. + update_option( 'mainwp_child_auto_purge_cache', ( $data['auto_purge_cache'] ? 1 : 0 ) ); + + // Update mainwp_child_cloud_flair_enabled options value. + update_option( 'mainwp_child_cloud_flair_enabled', ( $data['cloud_flair_enabled'] ? 1 : 0 ) ); + + // Update Cloudflare API Credentials option values. + if ( isset( $data['mainwp_cloudflair_email'] ) ) { + update_option( 'mainwp_cloudflair_email', ( $data['mainwp_cloudflair_email'] ) ); } - update_option( 'mainwp_child_cloudflair_key', $encrypted ); - $old = get_option( 'mainwp_cloudflair_key' ); - if ( false !== $old ) { - delete_option( 'mainwp_cloudflair_key' ); + if ( isset( $data['mainwp_cloudflair_key'] ) ) { + if ( ! empty( $data['mainwp_cloudflair_key'] ) ) { + $encrypted = MainWP_Child_Keys_Manager::instance()->encrypt_string( $data['mainwp_cloudflair_key'] ); + } else { + $encrypted = ''; + } + update_option( 'mainwp_child_cloudflair_key', $encrypted ); + $old = get_option( 'mainwp_cloudflair_key' ); + if ( false !== $old ) { + delete_option( 'mainwp_cloudflair_key' ); + } } + } catch ( \Exception $e ) { + error_log( $e->getMessage() ); // phpcs:ignore -- debug mode only. } - } catch ( \Exception $e ) { - error_log( $e->getMessage() ); // phpcs:ignore -- debug mode only. } - } - // ** Send data to MainWP Dashboard. **// + // ** Send data to MainWP Dashboard. **// - // Send last purged time stamp to MainWP Dashboard. - $information['mainwp_cache_control_last_purged'] = get_option( 'mainwp_cache_control_last_purged', 0 ); + // Send last purged time stamp to MainWP Dashboard. + $information['mainwp_cache_control_last_purged'] = get_option( 'mainwp_cache_control_last_purged', 0 ); - // Send active cache solution to MainWP Dashboard. - $information['mainwp_cache_control_cache_solution'] = get_option( 'mainwp_cache_control_cache_solution', 0 ); + // Send active cache solution to MainWP Dashboard. + $information['mainwp_cache_control_cache_solution'] = get_option( 'mainwp_cache_control_cache_solution', 0 ); - // Send data for Cache Control Logs. - $information['mainwp_cache_control_logs'] = get_option( 'mainwp_cache_control_log', '' ); + // Send data for Cache Control Logs. + $information['mainwp_cache_control_logs'] = get_option( 'mainwp_cache_control_log', '' ); - return $information; - } - - /** - * Check which supported plugin is installed, - * Set wp_option 'mainwp_cache_control_cache_solution' to active plugin, - * and set public variable 'is_plugin_installed' to TRUE. - * - * If a supported plugin is not installed check to see if CloudFlair solution is enabled. - * - * @return void - */ - public function check_cache_solution() { + return $information; + } - // Default value for cache solution. - $cache_plugin_solution = 'Plugin Not Found'; + /** + * Check which supported plugin is installed, + * Set wp_option 'mainwp_cache_control_cache_solution' to active plugin, + * and set public variable 'is_plugin_installed' to TRUE. + * + * If a supported plugin is not installed check to see if CloudFlair solution is enabled. + * + * @return void + */ + public function check_cache_solution() { + + // Default value for cache solution. + $cache_plugin_solution = 'Plugin Not Found'; + + // Grab all mu-plugins & check for Rocket.net mu-plugin. If found, set cache solution to CDN Cache Plugin. + $mu_plugings_list = get_mu_plugins(); + if ( array_key_exists( 'cdn-cache-management.php', $mu_plugings_list ) ) { + $cache_plugin_solution = 'CDN Cache Plugin'; + } - // Grab all mu-plugins & check for Rocket.net mu-plugin. If found, set cache solution to CDN Cache Plugin. - $mu_plugings_list = get_mu_plugins(); - if ( array_key_exists( 'cdn-cache-management.php', $mu_plugings_list ) ) { - $cache_plugin_solution = 'CDN Cache Plugin'; - } + $supported_cache_plugins = array( + 'wp-rocket/wp-rocket.php' => 'WP Rocket', + 'breeze/breeze.php' => 'Breeze', + 'litespeed-cache/litespeed-cache.php' => 'LiteSpeed Cache', + 'sg-cachepress/sg-cachepress.php' => 'SiteGround Optimizer', + 'swift-performance-lite/performance.php' => 'Swift Performance Lite', + 'swift-performance/performance.php' => 'Swift Performance', + 'wp-fastest-cache/wpFastestCache.php' => 'WP Fastest Cache', + 'w3-total-cache/w3-total-cache.php' => 'W3 Total Cache', + 'hummingbird-performance/wp-hummingbird.php' => 'Hummingbird Performance', + 'cache-enabler/cache-enabler.php' => 'Cache Enabler', + 'nginx-helper/nginx-helper.php' => 'Nginx Helper', + 'nitropack/main.php' => 'Nitropack', + 'autoptimize/autoptimize.php' => 'Autoptimize', + 'flying-press/flying-press.php' => 'FlyingPress', + 'wp-super-cache/wp-cache.php' => 'WP Super Cache', + 'comet-cache/comet-cache.php' => 'Comet Cache', + 'wp-optimize/wp-optimize.php' => 'WP Optimize', + 'seraphinite-accelerator/plugin_root.php' => 'Seraphinite Accelerator', + 'swis-performance/swis-performance.php' => 'Swis Performance', + 'pressable-cache-management/pressable-cache-management.php' => 'Pressable Cache Management', + ); - $supported_cache_plugins = array( - 'wp-rocket/wp-rocket.php' => 'WP Rocket', - 'breeze/breeze.php' => 'Breeze', - 'litespeed-cache/litespeed-cache.php' => 'LiteSpeed Cache', - 'sg-cachepress/sg-cachepress.php' => 'SiteGround Optimizer', - 'swift-performance-lite/performance.php' => 'Swift Performance Lite', - 'swift-performance/performance.php' => 'Swift Performance', - 'wp-fastest-cache/wpFastestCache.php' => 'WP Fastest Cache', - 'w3-total-cache/w3-total-cache.php' => 'W3 Total Cache', - 'hummingbird-performance/wp-hummingbird.php' => 'Hummingbird Performance', - 'cache-enabler/cache-enabler.php' => 'Cache Enabler', - 'nginx-helper/nginx-helper.php' => 'Nginx Helper', - 'nitropack/main.php' => 'Nitropack', - 'autoptimize/autoptimize.php' => 'Autoptimize', - 'flying-press/flying-press.php' => 'FlyingPress', - 'wp-super-cache/wp-cache.php' => 'WP Super Cache', - 'comet-cache/comet-cache.php' => 'Comet Cache', - 'wp-optimize/wp-optimize.php' => 'WP Optimize', - 'seraphinite-accelerator/plugin_root.php' => 'Seraphinite Accelerator', - 'swis-performance/swis-performance.php' => 'Swis Performance', - ); - - // Check if a supported cache plugin is active. - foreach ( $supported_cache_plugins as $plugin => $name ) { - if ( is_plugin_active( $plugin ) ) { - - // Check if WP Optimize is active and page cache is enabled or disabled. If disabled, continue to next plugin as if it is not installed. - if ( 'wp-optimize/wp-optimize.php' === $plugin ) { - if ( class_exists( '\WP_Optimize' ) ) { - $cache = WP_Optimize()->get_page_cache(); - if ( $cache->is_enabled() === false ) { - continue; - } elseif ( $cache->is_enabled() === true ) { - { - $cache_plugin_solution = 'WP Optimize'; + // Check if a supported cache plugin is active. + foreach ( $supported_cache_plugins as $plugin => $name ) { + if ( is_plugin_active( $plugin ) ) { + + // Check if WP Optimize is active and page cache is enabled or disabled. If disabled, continue to next plugin as if it is not installed. + if ( 'wp-optimize/wp-optimize.php' === $plugin ) { + if ( class_exists( '\WP_Optimize' ) ) { + $cache = WP_Optimize()->get_page_cache(); + if ( $cache->is_enabled() === false ) { + continue; + } elseif ( $cache->is_enabled() === true ) { + { + $cache_plugin_solution = 'WP Optimize'; + } } } + } else { + $cache_plugin_solution = $name; } - } else { - $cache_plugin_solution = $name; } } + + // Update wp_option 'mainwp_cache_control_cache_solution' with active plugin or "Plugin Not Found". + update_option( 'mainwp_cache_control_cache_solution', $cache_plugin_solution ); } - // Update wp_option 'mainwp_cache_control_cache_solution' with active plugin or "Plugin Not Found". - update_option( 'mainwp_cache_control_cache_solution', $cache_plugin_solution ); - } + /** + * Auto purge cache based on which cache plugin is installed & activated. + * + * @used-by MainWP_Child_Updates::upgrade_plugin_theme() + * @used-by MainWP_Child_Updates::upgrade_wp() + * + * @param string $bulk Bulk update distinguisher. + * + * @return void + */ + public function auto_purge_cache( $bulk = '' ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. + + $do_purge = get_option( 'mainwp_child_auto_purge_cache' ); + // If Cache Control is enabled, run the cache purge. + if ( 1 === $do_purge || '1' === $do_purge ) { + + // Set information array. + $information = array(); + + // Grab detected cache solution.. + $cache_plugin_solution = get_option( 'mainwp_cache_control_cache_solution', 0 ); + + // Run the corresponding cache plugin purge method. + try { + switch ( $cache_plugin_solution ) { + case 'WP Rocket': + $information = $this->wprocket_auto_cache_purge(); + break; + case 'Breeze': + $information = $this->breeze_auto_purge_cache(); + break; + case 'LiteSpeed Cache': + $information = $this->litespeed_auto_purge_cache(); + break; + case 'SiteGround Optimizer': + $information = $this->sitegrounds_optimizer_auto_purge_cache(); + break; + case 'Swift Performance Lite': + $information = $this->swift_performance_lite_auto_purge_cache(); + break; + case 'Swift Performance': + $information = $this->swift_performance_auto_purge_cache(); + break; + case 'WP Fastest Cache': + $information = $this->wp_fastest_cache_auto_purge_cache(); + break; + case 'W3 Total Cache': + $information = $this->w3_total_cache_auto_purge_cache(); + break; + case 'Hummingbird Performance': + $information = $this->wp_hummingbird_auto_purge_cache(); + break; + case 'Cache Enabler': + $information = $this->cache_enabler_auto_purge_cache(); + break; + case 'Nginx Helper': + $information = $this->nginx_helper_auto_purge_cache(); + break; + case 'Nitropack': + $information = $this->nitropack_auto_purge_cache(); + break; + case 'Autoptimize': + $information = $this->autoptimize_auto_purge_cache(); + break; + case 'FlyingPress': + $information = $this->flyingpress_auto_purge_cache(); + break; + case 'WP Super Cache': + $information = $this->wp_super_cache_auto_purge_cache(); + break; + case 'WP Optimize': + $information = $this->wp_optimize_auto_purge_cache(); + break; + case 'Comet Cache': + $information = $this->comet_cache_auto_purge_cache(); + break; + case 'CDN Cache Plugin': + $information = $this->cdn_cache_plugin_auto_purge_cache(); + break; + case 'Seraphinite Accelerator': + $information = $this->seraphinite_auto_purge_cache(); + break; + case 'Swis Performance': + $information = $this->swis_performance_auto_purge_cache(); + break; + case 'Pressable Cache Management': + $information = $this->pressable_cache_management_auto_purge_cache(); + default: + break; + } + } catch ( \Exception $e ) { + $information = array( 'error' => $e->getMessage() ); + } - /** - * Auto purge cache based on which cache plugin is installed & activated. - * - * @used-by MainWP_Child_Updates::upgrade_plugin_theme() - * @used-by MainWP_Child_Updates::upgrade_wp() - * - * @param string $bulk Bulk update distinguisher. - * - * @return void - */ - public function auto_purge_cache( $bulk = '' ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. - - $do_purge = get_option( 'mainwp_child_auto_purge_cache' ); - // If Cache Control is enabled, run the cache purge. - if ( 1 === $do_purge || '1' === $do_purge ) { - - // Set information array. - $information = array(); - - // Grab detected cache solution.. - $cache_plugin_solution = get_option( 'mainwp_cache_control_cache_solution', 0 ); - - // Run the corresponding cache plugin purge method. - try { - switch ( $cache_plugin_solution ) { - case 'WP Rocket': - $information = $this->wprocket_auto_cache_purge(); - break; - case 'Breeze': - $information = $this->breeze_auto_purge_cache(); - break; - case 'LiteSpeed Cache': - $information = $this->litespeed_auto_purge_cache(); - break; - case 'SiteGround Optimizer': - $information = $this->sitegrounds_optimizer_auto_purge_cache(); - break; - case 'Swift Performance Lite': - $information = $this->swift_performance_lite_auto_purge_cache(); - break; - case 'Swift Performance': - $information = $this->swift_performance_auto_purge_cache(); - break; - case 'WP Fastest Cache': - $information = $this->wp_fastest_cache_auto_purge_cache(); - break; - case 'W3 Total Cache': - $information = $this->w3_total_cache_auto_purge_cache(); - break; - case 'Hummingbird Performance': - $information = $this->wp_hummingbird_auto_purge_cache(); - break; - case 'Cache Enabler': - $information = $this->cache_enabler_auto_purge_cache(); - break; - case 'Nginx Helper': - $information = $this->nginx_helper_auto_purge_cache(); - break; - case 'Nitropack': - $information = $this->nitropack_auto_purge_cache(); - break; - case 'Autoptimize': - $information = $this->autoptimize_auto_purge_cache(); - break; - case 'FlyingPress': - $information = $this->flyingpress_auto_purge_cache(); - break; - case 'WP Super Cache': - $information = $this->wp_super_cache_auto_purge_cache(); - break; - case 'WP Optimize': - $information = $this->wp_optimize_auto_purge_cache(); - break; - case 'Comet Cache': - $information = $this->comet_cache_auto_purge_cache(); - break; - case 'CDN Cache Plugin': - $information = $this->cdn_cache_plugin_auto_purge_cache(); - break; - case 'Seraphinite Accelerator': - $information = $this->seraphinite_auto_purge_cache(); - break; - case 'Swis Performance': - $information = $this->swis_performance_auto_purge_cache(); - break; - default: - break; + // If no cache plugin is found, set status to disabled but still pass "SUCCESS" action because it did not fail. + if ( 'Plugin Not Found' === $cache_plugin_solution ) { + $information = array( + 'status' => 'Disabled', + 'action' => 'SUCCESS', + ); } - } catch ( \Exception $e ) { - $information = array( 'error' => $e->getMessage() ); - } - // If no cache plugin is found, set status to disabled but still pass "SUCCESS" action because it did not fail. - if ( 'Plugin Not Found' === $cache_plugin_solution ) { + // Fire off CloudFlare purge if enabled & not using a CDN Cache Plugin. ( Stops double purging Cloudflare ). + if ( '1' === get_option( 'mainwp_child_cloud_flair_enabled' ) && 'CDN Cache Plugin' !== $cache_plugin_solution ) { + $information['cloudflare'] = $this->cloudflair_auto_purge_cache(); + } + } else { + // If Cache Control is disabled, set status to disabled but still pass "SUCCESS" action because it did not fail. $information = array( - 'status' => 'Disabled', - 'action' => 'SUCCESS', + 'status' => 'Disabled', + 'action' => 'SUCCESS', + 'do_purge' => $do_purge, ); } - // Fire off CloudFlare purge if enabled & not using a CDN Cache Plugin. ( Stops double purging Cloudflare ). - if ( '1' === get_option( 'mainwp_child_cloud_flair_enabled' ) && 'CDN Cache Plugin' !== $cache_plugin_solution ) { - $information['cloudflare'] = $this->cloudflair_auto_purge_cache(); + // Save to DB. + $this->record_results( $information ); + + // Only fire off if this is a 'bulk' action. + if ( 'true' === $bulk ) { + // Return results in JSON format. + MainWP_Helper::write( $information ); } - } else { - // If Cache Control is disabled, set status to disabled but still pass "SUCCESS" action because it did not fail. - $information = array( - 'status' => 'Disabled', - 'action' => 'SUCCESS', - 'do_purge' => $do_purge, + } + + /** + * Build purge results array for return to dashboard. + * + * @param string $message Result message. + * @param string $action Action result. + * + * @return array Purge results array. + */ + public function purge_result( $message, $action ) { + $result = array( + 'Last Purged' => get_option( 'mainwp_cache_control_last_purged', false ), + 'Cache Solution' => get_option( 'mainwp_cache_control_cache_solution', false ), + 'Cache Control Enabled' => get_option( 'mainwp_child_auto_purge_cache' ), + 'Cloudflair Enabled' => get_option( 'mainwp_child_cloud_flair_enabled' ), ); + $result['result'] = $message; + if ( 'SUCCESS' === $action ) { + $result['action'] = 'SUCCESS'; + } else { + $result['action'] = 'ERROR'; + } + return $result; } - // Save to DB. - $this->record_results( $information ); + /** + * Purge Pressable Cache Management. + */ + public function pressable_cache_management_auto_purge_cache() { - // Only fire off if this is a 'bulk' action. - if ( 'true' === $bulk ) { - // Return results in JSON format. - MainWP_Helper::write( $information ); - } - } + $success_message = 'Pressable Cache Management => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - /** - * Build purge results array for return to dashboard. - * - * @param string $message Result message. - * @param string $action Action result. - * - * @return array Purge results array. - */ - public function purge_result( $message, $action ) { - $result = array( - 'Last Purged' => get_option( 'mainwp_cache_control_last_purged', false ), - 'Cache Solution' => get_option( 'mainwp_cache_control_cache_solution', false ), - 'Cache Control Enabled' => get_option( 'mainwp_child_auto_purge_cache' ), - 'Cloudflair Enabled' => get_option( 'mainwp_child_cloud_flair_enabled' ), - ); - $result['result'] = $message; - if ( 'SUCCESS' === $action ) { - $result['action'] = 'SUCCESS'; - } else { - $result['action'] = 'ERROR'; + if ( is_callable( 'flush_pressable_cache_callback' ) ) { + flush_pressable_cache_callback(); + } + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); + return $this->purge_result( $success_message, 'SUCCESS' ); } - return $result; - } - /** - * Purge Swis Performance plugin cache. - * - * @return array Purge results array. - */ - public function swis_performance_auto_purge_cache() { + /** + * Purge Swis Performance plugin cache. + * + * @return array Purge results array. + */ + public function swis_performance_auto_purge_cache() { - $success_message = 'Swis Performance => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Swis Performance => There was an issue purging your cache.'; - $bypass_message = 'Swis Performance => Purge was bypassed due to Swis Auto Purge Settings.'; + $success_message = 'Swis Performance => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Swis Performance => There was an issue purging your cache.'; + $bypass_message = 'Swis Performance => Purge was bypassed due to Swis Auto Purge Settings.'; - if ( is_callable( 'swis' ) ) { + if ( is_callable( 'swis' ) ) { - // Get Swis Cache Settings. - $swis_cache_settings = swis()->cache->get_settings(); + // Get Swis Cache Settings. + $swis_cache_settings = swis()->cache->get_settings(); - // Check if Swis Auto Purge is enabled. - if ( empty( $swis_cache_settings['clear_complete_cache_on_changed_plugin'] ) ) { + // Check if Swis Auto Purge is enabled. + if ( empty( $swis_cache_settings['clear_complete_cache_on_changed_plugin'] ) ) { - // Purge Cache. - do_action( 'swis_clear_complete_cache' ); + // Purge Cache. + do_action( 'swis_clear_complete_cache' ); - sleep( 3 ); + sleep( 3 ); - // Preload Cache. - swis()->cache_preload->start_preload(); + // Preload Cache. + swis()->cache_preload->start_preload(); + } else { + return $this->purge_result( $bypass_message, 'SUCCESS' ); + } + + // record results. ( below needs to stay untouched ). + update_option( 'mainwp_cache_control_last_purged', time() ); + return $this->purge_result( $success_message, 'SUCCESS' ); } else { - return $this->purge_result( $bypass_message, 'SUCCESS' ); + return $this->purge_result( $error_message, 'ERROR' ); } - - // record results. ( below needs to stay untouched ). - update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); } - } - /** - * Purge Seraphinite Accelerator plugin cache. - * - * @return array Purge results array. - */ - public function seraphinite_auto_purge_cache() { + /** + * Purge Seraphinite Accelerator plugin cache. + * + * @return array Purge results array. + */ + public function seraphinite_auto_purge_cache() { - $success_message = 'Seraphinite Accelerator => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Seraphinite Accelerator => There was an issue purging your cache.'; + $success_message = 'Seraphinite Accelerator => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Seraphinite Accelerator => There was an issue purging your cache.'; - if ( class_exists( '\seraph_accel\API' ) ) { + if ( class_exists( '\seraph_accel\API' ) ) { - \seraph_accel\API::OperateCache( \seraph_accel\API::CACHE_OP_DEL ); + \seraph_accel\API::OperateCache( \seraph_accel\API::CACHE_OP_DEL ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge CDN Cache Plugin cache. - * - * @return array Purge results array. - */ - public function cdn_cache_plugin_auto_purge_cache() { + /** + * Purge CDN Cache Plugin cache. + * + * @return array Purge results array. + */ + public function cdn_cache_plugin_auto_purge_cache() { - $success_message = 'CDN Cache Plugin => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'CDN Cache Plugin => There was an issue purging your cache.'; + $success_message = 'CDN Cache Plugin => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'CDN Cache Plugin => There was an issue purging your cache.'; - if ( class_exists( 'CDN_Clear_Cache_Api' ) ) { + if ( class_exists( 'CDN_Clear_Cache_Api' ) ) { - \CDN_Clear_Cache_Api::cache_api_call( array(), 'purge_everything' ); + \CDN_Clear_Cache_Api::cache_api_call( array(), 'purge_everything' ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge Comet Cache. - * - * @return array Purge results array. - */ - public function comet_cache_auto_purge_cache() { + /** + * Purge Comet Cache. + * + * @return array Purge results array. + */ + public function comet_cache_auto_purge_cache() { - $success_message = 'Comet Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Comet Cache => There was an issue purging your cache.'; + $success_message = 'Comet Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Comet Cache => There was an issue purging your cache.'; - if ( class_exists( '\comet_cache' ) ) { + if ( class_exists( '\comet_cache' ) ) { - // Clear Cache. - \comet_cache::clear(); + // Clear Cache. + \comet_cache::clear(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge WP Optimize cache. - * - * @return array Purge results array. - */ - public function wp_optimize_auto_purge_cache() { + /** + * Purge WP Optimize cache. + * + * @return array Purge results array. + */ + public function wp_optimize_auto_purge_cache() { - $success_message = 'WP Optimize => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'WP Optimize => There was an issue purging your cache.'; + $success_message = 'WP Optimize => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'WP Optimize => There was an issue purging your cache.'; - // Clear Cache. - $purge = self::wp_optimize_purge_cache(); + // Clear Cache. + $purge = self::wp_optimize_purge_cache(); - // Purge Minified files. - $minify = self::wp_optimize_purge_minify(); + // Purge Minified files. + $minify = self::wp_optimize_purge_minify(); - // Preload cache. - $preload = self::wp_optimize_preload_cache(); + // Preload cache. + $preload = self::wp_optimize_preload_cache(); - // Check response & return results. - if ( ( true === $purge && true === $preload ) || ( true === $minify && true === $purge && true === $preload ) ) { - update_option( 'mainwp_cache_control_last_purged', time() ); + // Check response & return results. + if ( ( true === $purge && true === $preload ) || ( true === $minify && true === $purge && true === $preload ) ) { + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Preload WP Optimize cache after purge. - * - * @return bool True if successful, false if not. - */ - public function wp_optimize_preload_cache() { - if ( class_exists( '\WP_Optimize_Cache_Commands' ) && class_exists( '\WP_Optimize_Page_Cache_Preloader' ) ) { - - // Clear Cache. - $purge = new \WP_Optimize_Cache_Commands(); - $purge->run_cache_preload(); - return true; + /** + * Preload WP Optimize cache after purge. + * + * @return bool True if successful, false if not. + */ + public function wp_optimize_preload_cache() { + if ( class_exists( '\WP_Optimize_Cache_Commands' ) && class_exists( '\WP_Optimize_Page_Cache_Preloader' ) ) { + + // Clear Cache. + $purge = new \WP_Optimize_Cache_Commands(); + $purge->run_cache_preload(); + return true; + } + return false; } - return false; - } - - /** - * Purge WP Optimize minified files. - * - * @return bool True if successful, false if not. - */ - public function wp_optimize_purge_minify() { - if ( class_exists( '\WP_Optimize' ) ) { - $cache = \WP_Optimize()->get_page_cache()->purge(); - // $cache returns true if successful, false if not. - return true; + /** + * Purge WP Optimize minified files. + * + * @return bool True if successful, false if not. + */ + public function wp_optimize_purge_minify() { + if ( class_exists( '\WP_Optimize' ) ) { + $cache = \WP_Optimize()->get_page_cache()->purge(); + + // $cache returns true if successful, false if not. + return true; + } + return false; } - return false; - } - - /** - * Purge WP Optimize cache. - * - * @return bool True if successful, false if not. - */ - public function wp_optimize_purge_cache() { - if ( class_exists( '\WP_Optimize' ) ) { - $cache = \WP_Optimize()->get_page_cache(); - $cache->purge(); - return true; + /** + * Purge WP Optimize cache. + * + * @return bool True if successful, false if not. + */ + public function wp_optimize_purge_cache() { + if ( class_exists( '\WP_Optimize' ) ) { + $cache = \WP_Optimize()->get_page_cache(); + $cache->purge(); + + return true; + } + return false; } - return false; - } - /** - * Check if WP Optimize is installed and cache is enabled. - */ - public function wp_optimize_activated_check() { - if ( class_exists( '\WP_Optimize' ) ) { - $cache = WP_Optimize()->get_page_cache(); - if ( ! $cache->is_enabled() ) { - return false; + /** + * Check if WP Optimize is installed and cache is enabled. + */ + public function wp_optimize_activated_check() { + if ( class_exists( '\WP_Optimize' ) ) { + $cache = WP_Optimize()->get_page_cache(); + if ( ! $cache->is_enabled() ) { + return false; + } } } - } - /** - * Purge WP Super Cache. - * - * @return array Purge results array. - */ - public function wp_super_cache_auto_purge_cache() { + /** + * Purge WP Super Cache. + * + * @return array Purge results array. + */ + public function wp_super_cache_auto_purge_cache() { - $success_message = 'WP Super Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'WP Super Cache => There was an issue purging your cache.'; + $success_message = 'WP Super Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'WP Super Cache => There was an issue purging your cache.'; - if ( function_exists( '\wp_cache_clean_cache' ) ) { + if ( function_exists( '\wp_cache_clean_cache' ) ) { - // Clear Cache. - global $file_prefix; - \wp_cache_clean_cache( $file_prefix, true ); + // Clear Cache. + global $file_prefix; + \wp_cache_clean_cache( $file_prefix, true ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge FlyingPress cache. - * - * @return array Purge results array. - */ - public function flyingpress_auto_purge_cache() { + /** + * Purge FlyingPress cache. + * + * @return array Purge results array. + */ + public function flyingpress_auto_purge_cache() { - $success_message = 'FlyingPress Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'FlyingPress Cache => There was an issue purging your cache.'; + $success_message = 'FlyingPress Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'FlyingPress Cache => There was an issue purging your cache.'; - if ( class_exists( '\FlyingPress\Purge' ) && class_exists( '\FlyingPress\Preload' ) ) { + if ( class_exists( '\FlyingPress\Purge' ) && class_exists( '\FlyingPress\Preload' ) ) { - // Clear Cache. - \FlyingPress\Purge::purge_everything(); + // Clear Cache. + \FlyingPress\Purge::purge_everything(); - sleep( 3 ); - // Preload Cache. - \FlyingPress\Preload::preload_cache(); + sleep( 3 ); + // Preload Cache. + \FlyingPress\Preload::preload_cache(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge Autoptimize cache. - * - * @return array Purge results array. - */ - public function autoptimize_auto_purge_cache() { + /** + * Purge Autoptimize cache. + * + * @return array Purge results array. + */ + public function autoptimize_auto_purge_cache() { - $success_message = 'Autoptimize => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Autoptimize => There was an issue purging your cache.'; + $success_message = 'Autoptimize => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Autoptimize => There was an issue purging your cache.'; - if ( class_exists( 'autoptimizeCache' ) ) { + if ( class_exists( 'autoptimizeCache' ) ) { - // Clear Cache. - \autoptimizeCache::clearall(); + // Clear Cache. + \autoptimizeCache::clearall(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge Nitropack cache. - * - * Nitropack_purge($url = NULL, $tag = NULL, $reason = NULL); - * - * In case you want to do a full purge, you must leave the values - * for URL and Tag empty. In case you want to create a targeted purge - * you can replace them with the URL or tag of the page. - * - * @return array Purge results array. - */ - public function nitropack_auto_purge_cache() { + /** + * Purge Nitropack cache. + * + * Nitropack_purge($url = NULL, $tag = NULL, $reason = NULL); + * + * In case you want to do a full purge, you must leave the values + * for URL and Tag empty. In case you want to create a targeted purge + * you can replace them with the URL or tag of the page. + * + * @return array Purge results array. + */ + public function nitropack_auto_purge_cache() { - $success_message = 'Nitropack => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Nitropack => There was an issue purging your cache.'; + $success_message = 'Nitropack => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Nitropack => There was an issue purging your cache.'; - if ( function_exists( 'nitropack_purge' ) ) { + if ( function_exists( 'nitropack_purge' ) ) { - // Clear Nitropack Cache after update. - nitropack_purge(); + // Clear Nitropack Cache after update. + nitropack_purge(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge Nginx Helper cache. - * - * @return array Purge results array. - */ - public function nginx_helper_auto_purge_cache() { + /** + * Purge Nginx Helper cache. + * + * @return array Purge results array. + */ + public function nginx_helper_auto_purge_cache() { - $success_message = 'Nginx Helper => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Nginx Helper => There was an issue purging your cache.'; + $success_message = 'Nginx Helper => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Nginx Helper => There was an issue purging your cache.'; - if ( class_exists( 'Nginx_Helper' ) ) { + if ( class_exists( 'Nginx_Helper' ) ) { - // Clear Nginx Helper Cache after update. - do_action( 'rt_nginx_helper_purge_all' ); + // Clear Nginx Helper Cache after update. + do_action( 'rt_nginx_helper_purge_all' ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge WP Hummingbird cache. - * - * @note needs to have namespace or it will not work. - * - * @return array Purge results array. - */ - public function wp_hummingbird_auto_purge_cache() { + /** + * Purge WP Hummingbird cache. + * + * @note needs to have namespace or it will not work. + * + * @return array Purge results array. + */ + public function wp_hummingbird_auto_purge_cache() { - $success_message = 'Hummingbird => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Hummingbird => There was an issue purging your cache.'; + $success_message = 'Hummingbird => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Hummingbird => There was an issue purging your cache.'; - if ( class_exists( 'Hummingbird\Core\Modules\\Page_Cache' ) ) { + if ( class_exists( 'Hummingbird\Core\Modules\\Page_Cache' ) ) { - // Clear WP Hummingbird Cache after update. - do_action( 'wphb_clear_page_cache' ); + // Clear WP Hummingbird Cache after update. + do_action( 'wphb_clear_page_cache' ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge Cache Enabler cache. - * - * @return array Purge results array. - */ - public function cache_enabler_auto_purge_cache() { + /** + * Purge Cache Enabler cache. + * + * @return array Purge results array. + */ + public function cache_enabler_auto_purge_cache() { - $success_message = 'Cache Enabler => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Cache Enabler => There was an issue purging your cache.'; + $success_message = 'Cache Enabler => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Cache Enabler => There was an issue purging your cache.'; - if ( class_exists( 'Cache_Enabler' ) ) { + if ( class_exists( 'Cache_Enabler' ) ) { - // Clear the Cache after update. - \Cache_Enabler::clear_complete_cache(); + // Clear the Cache after update. + \Cache_Enabler::clear_complete_cache(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge W3 Total Cache. - * - * @return array Purge results array. - */ - public function w3_total_cache_auto_purge_cache() { + /** + * Purge W3 Total Cache. + * + * @return array Purge results array. + */ + public function w3_total_cache_auto_purge_cache() { - $success_message = 'W3 Total Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'W3 Total Cache => There was an issue purging your cache.'; + $success_message = 'W3 Total Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'W3 Total Cache => There was an issue purging your cache.'; - if ( function_exists( 'w3tc_flush_all' ) ) { + if ( function_exists( 'w3tc_flush_all' ) ) { - // Purge all W3 total cache. - w3tc_flush_all(); + // Purge all W3 total cache. + w3tc_flush_all(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge WP Fastest Cache. - * - * @return array Purge results array. - */ - public function wp_fastest_cache_auto_purge_cache() { + /** + * Purge WP Fastest Cache. + * + * @return array Purge results array. + */ + public function wp_fastest_cache_auto_purge_cache() { - $success_message = 'WP Fastest Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'WP Fastest Cache => There was an issue purging your cache.'; + $success_message = 'WP Fastest Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'WP Fastest Cache => There was an issue purging your cache.'; - if ( class_exists( 'WpFastestCache' ) ) { + if ( class_exists( 'WpFastestCache' ) ) { - // Clear the Cache after update. - do_action( 'wpfc_clear_all_cache' ); + // Clear the Cache after update. + do_action( 'wpfc_clear_all_cache' ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge Swift Performance Lite Cache. - * - * @return array Purge results array. - */ - public function swift_performance_lite_auto_purge_cache() { + /** + * Purge Swift Performance Lite Cache. + * + * @return array Purge results array. + */ + public function swift_performance_lite_auto_purge_cache() { - $success_message = 'Swift Performance Lite => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Swift Performance Lite => There was an issue purging your cache.'; + $success_message = 'Swift Performance Lite => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Swift Performance Lite => There was an issue purging your cache.'; - if ( class_exists( 'Swift_Performance_Cache' ) ) { + if ( class_exists( 'Swift_Performance_Cache' ) ) { - // Clear All Swift Performance Lite Cache. - \Swift_Performance_Cache::clear_all_cache(); + // Clear All Swift Performance Lite Cache. + \Swift_Performance_Cache::clear_all_cache(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge Swift Performance Cache. - * - * @return array Purge results array. - */ - public function swift_performance_auto_purge_cache() { + /** + * Purge Swift Performance Cache. + * + * @return array Purge results array. + */ + public function swift_performance_auto_purge_cache() { - $success_message = 'Swift Performance => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Swift Performance => There was an issue purging your cache.'; + $success_message = 'Swift Performance => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Swift Performance => There was an issue purging your cache.'; - if ( class_exists( 'Swift_Performance_Cache' ) ) { + if ( class_exists( 'Swift_Performance_Cache' ) ) { - // Clear All Swift Performance Cache. - \Swift_Performance_Cache::clear_all_cache(); + // Clear All Swift Performance Cache. + \Swift_Performance_Cache::clear_all_cache(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge SiteGrounds Optimiser Cache. - * - * @return array Purge results array. - */ - public function sitegrounds_optimizer_auto_purge_cache() { + /** + * Purge SiteGrounds Optimiser Cache. + * + * @return array Purge results array. + */ + public function sitegrounds_optimizer_auto_purge_cache() { - $success_message = 'SiteGround Optimizer => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'SiteGround Optimizer => There was an issue purging your cache.'; + $success_message = 'SiteGround Optimizer => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'SiteGround Optimizer => There was an issue purging your cache.'; - if ( function_exists( 'sg_cachepress_purge_everything' ) ) { + if ( function_exists( 'sg_cachepress_purge_everything' ) ) { - // Purge all SG CachePress cache. - sg_cachepress_purge_everything(); + // Purge all SG CachePress cache. + sg_cachepress_purge_everything(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); + return $this->purge_result( $success_message, 'SUCCESS' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - - /** - * Purge Cloudflair Cache. - * - * @noinspection PhpIdempotentOperationInspection - * - * @return array Purge results array. - */ - public function cloudflair_auto_purge_cache() { - // Credentials for Cloudflare. - $cust_email = get_option( 'mainwp_cloudflair_email', '' ); - $cust_xauth = get_option( 'mainwp_child_cloudflair_key', '' ); - if ( ! empty( $cust_xauth ) ) { - $cust_xauth = MainWP_Child_Keys_Manager::instance()->decrypt_string( $cust_xauth ); - } - $cust_domain = trim( str_replace( array( 'http://', 'https://', 'www.' ), '', get_option( 'siteurl' ) ), '/' ); + /** + * Purge Cloudflair Cache. + * + * @noinspection PhpIdempotentOperationInspection + * + * @return array Purge results array. + */ + public function cloudflair_auto_purge_cache() { + + // Credentials for Cloudflare. + $cust_email = get_option( 'mainwp_cloudflair_email', '' ); + $cust_xauth = get_option( 'mainwp_child_cloudflair_key', '' ); + if ( ! empty( $cust_xauth ) ) { + $cust_xauth = MainWP_Child_Keys_Manager::instance()->decrypt_string( $cust_xauth ); + } + $cust_domain = trim( str_replace( array( 'http://', 'https://', 'www.' ), '', get_option( 'siteurl' ) ), '/' ); - // Check if we have all the required data. - if ( '' === $cust_email || '' === $cust_xauth ) { - return; - } + // Check if we have all the required data. + if ( '' === $cust_email || '' === $cust_xauth ) { + return; + } - // Strip subdomains. Cloudflare doesn't like them. - $cust_domain = $this->strip_subdomains( $cust_domain ); - - // Get the Zone-ID from Cloudflare since they don't provide that in the Backend. - $ch_query = curl_init(); // phpcs:ignore -- use core function. - curl_setopt( $ch_query, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones?name=' . $cust_domain . '&status=active&page=1&per_page=5&order=status&direction=desc&match=all' ); // phpcs:ignore -- use core function. - curl_setopt( $ch_query, CURLOPT_RETURNTRANSFER, 1 ); // phpcs:ignore -- use core function. - $qheaders = array( - 'X-Auth-Email: ' . $cust_email . '', - 'X-Auth-Key: ' . $cust_xauth . '', - 'Content-Type: application/json', - ); - curl_setopt( $ch_query, CURLOPT_HTTPHEADER, $qheaders ); // phpcs:ignore -- use core function. - $qresult = json_decode( curl_exec( $ch_query ), true ); // phpcs:ignore -- use core function. - if ( 'resource' === gettype( $ch_query ) ) { - curl_close( $ch_query ); // phpcs:ignore -- use core function. - } + // Strip subdomains. Cloudflare doesn't like them. + $cust_domain = $this->strip_subdomains( $cust_domain ); + + // Get the Zone-ID from Cloudflare since they don't provide that in the Backend. + $ch_query = curl_init(); // phpcs:ignore -- use core function. + curl_setopt( $ch_query, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones?name=' . $cust_domain . '&status=active&page=1&per_page=5&order=status&direction=desc&match=all' ); // phpcs:ignore -- use core function. + curl_setopt( $ch_query, CURLOPT_RETURNTRANSFER, 1 ); // phpcs:ignore -- use core function. + $qheaders = array( + 'X-Auth-Email: ' . $cust_email . '', + 'X-Auth-Key: ' . $cust_xauth . '', + 'Content-Type: application/json', + ); + curl_setopt( $ch_query, CURLOPT_HTTPHEADER, $qheaders ); // phpcs:ignore -- use core function. + $qresult = json_decode( curl_exec( $ch_query ), true ); // phpcs:ignore -- use core function. + if ( 'resource' === gettype( $ch_query ) ) { + curl_close( $ch_query ); // phpcs:ignore -- use core function. + } - $cust_zone = $qresult['result'][0]['id']; - - // Purge the entire cache via API. - $ch_purge = curl_init(); // phpcs:ignore -- use core function. - curl_setopt( $ch_purge, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones/' . $cust_zone . '/purge_cache' ); // phpcs:ignore -- use core function. - curl_setopt( $ch_purge, CURLOPT_CUSTOMREQUEST, 'DELETE' ); // phpcs:ignore -- use core function. - curl_setopt( $ch_purge, CURLOPT_RETURNTRANSFER, 1 ); // phpcs:ignore -- use core function. - $headers = array( - 'X-Auth-Email: ' . $cust_email, - 'X-Auth-Key: ' . $cust_xauth, - 'Content-Type: application/json', - ); - $data = wp_json_encode( array( 'purge_everything' => true ) ); // phpcs:ignore -- ok. - curl_setopt( $ch_purge, CURLOPT_POST, true ); // phpcs:ignore -- use core function. - curl_setopt( $ch_purge, CURLOPT_POSTFIELDS, $data ); // phpcs:ignore -- use core function. - curl_setopt( $ch_purge, CURLOPT_HTTPHEADER, $headers ); // phpcs:ignore -- use core function. - - $result = json_decode( curl_exec( $ch_purge ), true ); // phpcs:ignore -- use core function. - if ( 'resource' === gettype( $ch_query ) ) { - curl_close( $ch_purge ); // phpcs:ignore -- use core function. - } - $success_message = 'Cloudflare => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Cloudflare => There was an issue purging the cache. ' . wp_json_encode( $qresult['errors'][0], JSON_UNESCAPED_SLASHES ) . "-" . wp_json_encode( $result['errors'][0], JSON_UNESCAPED_SLASHES ); // phpcs:ignore -- ok. + $cust_zone = $qresult['result'][0]['id']; + + // Purge the entire cache via API. + $ch_purge = curl_init(); // phpcs:ignore -- use core function. + curl_setopt( $ch_purge, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones/' . $cust_zone . '/purge_cache' ); // phpcs:ignore -- use core function. + curl_setopt( $ch_purge, CURLOPT_CUSTOMREQUEST, 'DELETE' ); // phpcs:ignore -- use core function. + curl_setopt( $ch_purge, CURLOPT_RETURNTRANSFER, 1 ); // phpcs:ignore -- use core function. + $headers = array( + 'X-Auth-Email: ' . $cust_email, + 'X-Auth-Key: ' . $cust_xauth, + 'Content-Type: application/json', + ); + $data = wp_json_encode( array( 'purge_everything' => true ) ); // phpcs:ignore -- ok. + curl_setopt( $ch_purge, CURLOPT_POST, true ); // phpcs:ignore -- use core function. + curl_setopt( $ch_purge, CURLOPT_POSTFIELDS, $data ); // phpcs:ignore -- use core function. + curl_setopt( $ch_purge, CURLOPT_HTTPHEADER, $headers ); // phpcs:ignore -- use core function. + + $result = json_decode( curl_exec( $ch_purge ), true ); // phpcs:ignore -- use core function. + if ( 'resource' === gettype( $ch_query ) ) { + curl_close( $ch_purge ); // phpcs:ignore -- use core function. + } + $success_message = 'Cloudflare => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Cloudflare => There was an issue purging the cache. ' . wp_json_encode( $qresult['errors'][0], JSON_UNESCAPED_SLASHES ) . "-" . wp_json_encode( $result['errors'][0], JSON_UNESCAPED_SLASHES ); // phpcs:ignore -- ok. - // Save last purge time to database on success. - if ( 1 === (int) $result['success'] ) { + // Save last purge time to database on success. + if ( 1 === (int) $result['success'] ) { - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - // Return success message. - return $this->purge_result( $success_message, 'SUCCESS' ); - } elseif ( ( 1 !== (int) $qresult['success'] ) || ( 1 !== (int) $result['success'] ) ) { - // Return error message. - return $this->purge_result( $error_message, 'ERROR' ); + // Return success message. + return $this->purge_result( $success_message, 'SUCCESS' ); + } elseif ( ( 1 !== (int) $qresult['success'] ) || ( 1 !== (int) $result['success'] ) ) { + // Return error message. + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge LiteSpeed Cache. - * - * @return array Purge results array. - */ - public function litespeed_auto_purge_cache() { + /** + * Purge LiteSpeed Cache. + * + * @return array Purge results array. + */ + public function litespeed_auto_purge_cache() { - $success_message = 'LiteSpeed => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'LiteSpeed => There was an issue purging your cache.'; + $success_message = 'LiteSpeed => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'LiteSpeed => There was an issue purging your cache.'; - if ( class_exists( '\LiteSpeed\Purge' ) ) { + if ( class_exists( '\LiteSpeed\Purge' ) ) { - // Purge all LS Cache. - \LiteSpeed\Purge::purge_all(); + // Purge all LS Cache. + \LiteSpeed\Purge::purge_all(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - // Return success message. - return $this->purge_result( $success_message, 'SUCCESS' ); + // Return success message. + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - // Return error message. - return $this->purge_result( $error_message, 'ERROR' ); + } else { + // Return error message. + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge Breeze cache. - * - * @return array Purge results array. - */ - public function breeze_auto_purge_cache() { + /** + * Purge Breeze cache. + * + * @return array Purge results array. + */ + public function breeze_auto_purge_cache() { - $success_message = 'Breeze => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Breeze => There was an issue purging your cache.'; + $success_message = 'Breeze => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Breeze => There was an issue purging your cache.'; - if ( class_exists( 'Breeze_Admin' ) ) { + if ( class_exists( 'Breeze_Admin' ) ) { - // Clears varnish cache. - $admin = new \Breeze_Admin(); - $admin->breeze_clear_varnish(); + // Clears varnish cache. + $admin = new \Breeze_Admin(); + $admin->breeze_clear_varnish(); - // For local static files: Clears files within /cache/breeze-minification/ folder. - if ( class_exists( '\Breeze_Configuration' ) ) { - $size_cache = \Breeze_Configuration::breeze_clean_cache(); - } else { - $size_cache = 0; - } + // For local static files: Clears files within /cache/breeze-minification/ folder. + if ( class_exists( '\Breeze_Configuration' ) ) { + $size_cache = \Breeze_Configuration::breeze_clean_cache(); + } else { + $size_cache = 0; + } - // Delete minified files. - \Breeze_MinificationCache::clear_minification(); + // Delete minified files. + \Breeze_MinificationCache::clear_minification(); - // Clear normal cache. - \Breeze_PurgeCache::breeze_cache_flush(); + // Clear normal cache. + \Breeze_PurgeCache::breeze_cache_flush(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - // Return success message. - return $this->purge_result( $success_message, 'SUCCESS' ); + // Return success message. + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - // Return error message. - return $this->purge_result( $error_message, 'ERROR' ); + } else { + // Return error message. + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Purge WP-Rocket cache. - * - * @return array Purge results array. - */ - public function wprocket_auto_cache_purge() { + /** + * Purge WP-Rocket cache. + * + * @return array Purge results array. + */ + public function wprocket_auto_cache_purge() { - // Purge Cache if action is set to "1". - $do_purge = get_option( 'mainwp_child_auto_purge_cache', false ); - $purge_result = array(); + // Purge Cache if action is set to "1". + $do_purge = get_option( 'mainwp_child_auto_purge_cache', false ); + $purge_result = array(); - if ( 1 === (int) $do_purge ) { - $purge_result = MainWP_Child_WP_Rocket::instance()->purge_cache_all(); - } + if ( 1 === (int) $do_purge ) { + $purge_result = MainWP_Child_WP_Rocket::instance()->purge_cache_all(); + } - // Record results & return response. - if ( 'SUCCESS' === $purge_result['result'] ) { + // Record results & return response. + if ( 'SUCCESS' === $purge_result['result'] ) { - // Save last purge time to database on success. - update_option( 'mainwp_cache_control_last_purged', time() ); + // Save last purge time to database on success. + update_option( 'mainwp_cache_control_last_purged', time() ); - // Return success message. - $success_message = 'WP Rocket => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - return $this->purge_result( $success_message, 'SUCCESS' ); + // Return success message. + $success_message = 'WP Rocket => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { + } else { - // Return error message. - $error_message = 'WP Rocket => There was an issue purging your cache.'; - return $this->purge_result( $error_message, 'ERROR' ); + // Return error message. + $error_message = 'WP Rocket => There was an issue purging your cache.'; + return $this->purge_result( $error_message, 'ERROR' ); + } } - } - /** - * Record last Purge. - * - * Create log file & Save in /Upload dir. - * - * @param array $information Array containing the data to be sent to the Dashboard. - */ - public function record_results( $information ) { + /** + * Record last Purge. + * + * Create log file & Save in /Upload dir. + * + * @param array $information Array containing the data to be sent to the Dashboard. + */ + public function record_results( $information ) { + + // Setup timezone and upload directory for logs. + $ti = wp_timezone(); + if ( is_array( $ti ) && isset( $ti['timezone'] ) ) { + date_default_timezone_set( $ti['timezone'] ); // phpcs:ignore -- use core function. + } - // Setup timezone and upload directory for logs. - $ti = wp_timezone(); - if ( is_array( $ti ) && isset( $ti['timezone'] ) ) { - date_default_timezone_set( $ti['timezone'] ); // phpcs:ignore -- use core function. + // Save Cache Control Log Data. + update_option( 'mainwp_cache_control_log', wp_json_encode( $information ) ); } - // Save Cache Control Log Data. - update_option( 'mainwp_cache_control_log', wp_json_encode( $information ) ); - } - - /** - * Strip subdomains from a url. - * - * @param string $url string The url to strip subdomains from. - * - * @return string The url without subdomains (if any). - */ - public function strip_subdomains( $url ) { - $parts = explode( '/', $url ); - $url_first = $parts[0]; // get first part. - $count = count( explode( '.', $url_first ) ); - $domain = ''; - if ( 4 <= $count ) { - $domain = implode( '.', array_slice( explode( '.', $url_first ), -3 ) ); - } else { - $domain = implode( '.', array_slice( explode( '.', $url_first ), -2 ) ); + /** + * Strip subdomains from a url. + * + * @param string $url string The url to strip subdomains from. + * + * @return string The url without subdomains (if any). + */ + public function strip_subdomains( $url ) { + $parts = explode( '/', $url ); + $url_first = $parts[0]; // get first part. + $count = count( explode( '.', $url_first ) ); + $domain = ''; + if ( 4 <= $count ) { + $domain = implode( '.', array_slice( explode( '.', $url_first ), -3 ) ); + } else { + $domain = implode( '.', array_slice( explode( '.', $url_first ), -2 ) ); + } + return $domain; } - return $domain; } -} From d08f501d8304f6841ddbca921d8373f14fb466c1 Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Thu, 4 Apr 2024 17:51:25 +0000 Subject: [PATCH 6/9] [CodeFactor] Apply fixes [ci skip] [skip ci] --- class/class-mainwp-child-cache-purge.php | 1674 +++++++++++----------- 1 file changed, 837 insertions(+), 837 deletions(-) diff --git a/class/class-mainwp-child-cache-purge.php b/class/class-mainwp-child-cache-purge.php index 509ed841..a91b3fbe 100644 --- a/class/class-mainwp-child-cache-purge.php +++ b/class/class-mainwp-child-cache-purge.php @@ -16,1070 +16,1070 @@ * * @package MainWP\Child */ - class MainWP_Child_Cache_Purge { - - /** - * Public variable to state if supported plugin is installed on the child site. - * - * @var bool If supported plugin is installed, return true, if not, return false. - */ - public $is_plugin_installed = false; - - /** - * Public static variable to hold the single instance of the class. - * - * @var mixed Default null - */ - protected static $instance = null; - - /** - * Method instance() - * - * Create a public static instance. - * - * @return mixed Class instance. - */ - public static function instance() { - if ( null === self::$instance ) { - self::$instance = new self(); - } +class MainWP_Child_Cache_Purge { - return self::$instance; - } + /** + * Public variable to state if supported plugin is installed on the child site. + * + * @var bool If supported plugin is installed, return true, if not, return false. + */ + public $is_plugin_installed = false; - /** - * MainWP_Child_Cache_Purge constructor. - * - * Run any time class is called. - * - * Add filter to sync data to & from the MainWP Dashboard. - * Add action to check for supported cache plugins. - * - * @uses \MainWP\Child\MainWP_Child_Cache_Purge::sync_others_data() - * @uses \MainWP\Child\MainWP_Child_Cache_Purge::check_cache_solution() - */ - public function __construct() { - add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 ); - add_action( 'plugins_loaded', array( $this, 'check_cache_solution' ), 10, 2 ); + /** + * Public static variable to hold the single instance of the class. + * + * @var mixed Default null + */ + protected static $instance = null; + + /** + * Method instance() + * + * Create a public static instance. + * + * @return mixed Class instance. + */ + public static function instance() { + if ( null === self::$instance ) { + self::$instance = new self(); } - /** - * Method sync_others_data() - * - * Sync data to & from the MainWP Dashboard. - * - * @param array $information Array containing the data to be sent to the Dashboard. - * @param array $data Array containing the data sent from the Dashboard; to be saved to the Child Site. - * - * @return array $information Array containing the data to be sent to the Dashboard. - */ - public function sync_others_data( $information, $data = array() ) { - - // ** Grab data synced from MainWP Dashboard & update options. **// - if ( is_array( $data ) ) { - try { - - // Update mainwp_child_auto_purge_cache option value with either yes|no. - update_option( 'mainwp_child_auto_purge_cache', ( $data['auto_purge_cache'] ? 1 : 0 ) ); - - // Update mainwp_child_cloud_flair_enabled options value. - update_option( 'mainwp_child_cloud_flair_enabled', ( $data['cloud_flair_enabled'] ? 1 : 0 ) ); - - // Update Cloudflare API Credentials option values. - if ( isset( $data['mainwp_cloudflair_email'] ) ) { - update_option( 'mainwp_cloudflair_email', ( $data['mainwp_cloudflair_email'] ) ); + return self::$instance; + } + + /** + * MainWP_Child_Cache_Purge constructor. + * + * Run any time class is called. + * + * Add filter to sync data to & from the MainWP Dashboard. + * Add action to check for supported cache plugins. + * + * @uses \MainWP\Child\MainWP_Child_Cache_Purge::sync_others_data() + * @uses \MainWP\Child\MainWP_Child_Cache_Purge::check_cache_solution() + */ + public function __construct() { + add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 ); + add_action( 'plugins_loaded', array( $this, 'check_cache_solution' ), 10, 2 ); + } + + /** + * Method sync_others_data() + * + * Sync data to & from the MainWP Dashboard. + * + * @param array $information Array containing the data to be sent to the Dashboard. + * @param array $data Array containing the data sent from the Dashboard; to be saved to the Child Site. + * + * @return array $information Array containing the data to be sent to the Dashboard. + */ + public function sync_others_data( $information, $data = array() ) { + + // ** Grab data synced from MainWP Dashboard & update options. **// + if ( is_array( $data ) ) { + try { + + // Update mainwp_child_auto_purge_cache option value with either yes|no. + update_option( 'mainwp_child_auto_purge_cache', ( $data['auto_purge_cache'] ? 1 : 0 ) ); + + // Update mainwp_child_cloud_flair_enabled options value. + update_option( 'mainwp_child_cloud_flair_enabled', ( $data['cloud_flair_enabled'] ? 1 : 0 ) ); + + // Update Cloudflare API Credentials option values. + if ( isset( $data['mainwp_cloudflair_email'] ) ) { + update_option( 'mainwp_cloudflair_email', ( $data['mainwp_cloudflair_email'] ) ); + } + if ( isset( $data['mainwp_cloudflair_key'] ) ) { + if ( ! empty( $data['mainwp_cloudflair_key'] ) ) { + $encrypted = MainWP_Child_Keys_Manager::instance()->encrypt_string( $data['mainwp_cloudflair_key'] ); + } else { + $encrypted = ''; } - if ( isset( $data['mainwp_cloudflair_key'] ) ) { - if ( ! empty( $data['mainwp_cloudflair_key'] ) ) { - $encrypted = MainWP_Child_Keys_Manager::instance()->encrypt_string( $data['mainwp_cloudflair_key'] ); - } else { - $encrypted = ''; - } - update_option( 'mainwp_child_cloudflair_key', $encrypted ); - $old = get_option( 'mainwp_cloudflair_key' ); - if ( false !== $old ) { - delete_option( 'mainwp_cloudflair_key' ); - } + update_option( 'mainwp_child_cloudflair_key', $encrypted ); + $old = get_option( 'mainwp_cloudflair_key' ); + if ( false !== $old ) { + delete_option( 'mainwp_cloudflair_key' ); } - } catch ( \Exception $e ) { - error_log( $e->getMessage() ); // phpcs:ignore -- debug mode only. } + } catch ( \Exception $e ) { + error_log( $e->getMessage() ); // phpcs:ignore -- debug mode only. } + } - // ** Send data to MainWP Dashboard. **// + // ** Send data to MainWP Dashboard. **// - // Send last purged time stamp to MainWP Dashboard. - $information['mainwp_cache_control_last_purged'] = get_option( 'mainwp_cache_control_last_purged', 0 ); + // Send last purged time stamp to MainWP Dashboard. + $information['mainwp_cache_control_last_purged'] = get_option( 'mainwp_cache_control_last_purged', 0 ); - // Send active cache solution to MainWP Dashboard. - $information['mainwp_cache_control_cache_solution'] = get_option( 'mainwp_cache_control_cache_solution', 0 ); + // Send active cache solution to MainWP Dashboard. + $information['mainwp_cache_control_cache_solution'] = get_option( 'mainwp_cache_control_cache_solution', 0 ); - // Send data for Cache Control Logs. - $information['mainwp_cache_control_logs'] = get_option( 'mainwp_cache_control_log', '' ); + // Send data for Cache Control Logs. + $information['mainwp_cache_control_logs'] = get_option( 'mainwp_cache_control_log', '' ); - return $information; - } + return $information; + } - /** - * Check which supported plugin is installed, - * Set wp_option 'mainwp_cache_control_cache_solution' to active plugin, - * and set public variable 'is_plugin_installed' to TRUE. - * - * If a supported plugin is not installed check to see if CloudFlair solution is enabled. - * - * @return void - */ - public function check_cache_solution() { - - // Default value for cache solution. - $cache_plugin_solution = 'Plugin Not Found'; - - // Grab all mu-plugins & check for Rocket.net mu-plugin. If found, set cache solution to CDN Cache Plugin. - $mu_plugings_list = get_mu_plugins(); - if ( array_key_exists( 'cdn-cache-management.php', $mu_plugings_list ) ) { - $cache_plugin_solution = 'CDN Cache Plugin'; - } + /** + * Check which supported plugin is installed, + * Set wp_option 'mainwp_cache_control_cache_solution' to active plugin, + * and set public variable 'is_plugin_installed' to TRUE. + * + * If a supported plugin is not installed check to see if CloudFlair solution is enabled. + * + * @return void + */ + public function check_cache_solution() { - $supported_cache_plugins = array( - 'wp-rocket/wp-rocket.php' => 'WP Rocket', - 'breeze/breeze.php' => 'Breeze', - 'litespeed-cache/litespeed-cache.php' => 'LiteSpeed Cache', - 'sg-cachepress/sg-cachepress.php' => 'SiteGround Optimizer', - 'swift-performance-lite/performance.php' => 'Swift Performance Lite', - 'swift-performance/performance.php' => 'Swift Performance', - 'wp-fastest-cache/wpFastestCache.php' => 'WP Fastest Cache', - 'w3-total-cache/w3-total-cache.php' => 'W3 Total Cache', - 'hummingbird-performance/wp-hummingbird.php' => 'Hummingbird Performance', - 'cache-enabler/cache-enabler.php' => 'Cache Enabler', - 'nginx-helper/nginx-helper.php' => 'Nginx Helper', - 'nitropack/main.php' => 'Nitropack', - 'autoptimize/autoptimize.php' => 'Autoptimize', - 'flying-press/flying-press.php' => 'FlyingPress', - 'wp-super-cache/wp-cache.php' => 'WP Super Cache', - 'comet-cache/comet-cache.php' => 'Comet Cache', - 'wp-optimize/wp-optimize.php' => 'WP Optimize', - 'seraphinite-accelerator/plugin_root.php' => 'Seraphinite Accelerator', - 'swis-performance/swis-performance.php' => 'Swis Performance', - 'pressable-cache-management/pressable-cache-management.php' => 'Pressable Cache Management', - ); + // Default value for cache solution. + $cache_plugin_solution = 'Plugin Not Found'; + + // Grab all mu-plugins & check for Rocket.net mu-plugin. If found, set cache solution to CDN Cache Plugin. + $mu_plugings_list = get_mu_plugins(); + if ( array_key_exists( 'cdn-cache-management.php', $mu_plugings_list ) ) { + $cache_plugin_solution = 'CDN Cache Plugin'; + } - // Check if a supported cache plugin is active. - foreach ( $supported_cache_plugins as $plugin => $name ) { - if ( is_plugin_active( $plugin ) ) { - - // Check if WP Optimize is active and page cache is enabled or disabled. If disabled, continue to next plugin as if it is not installed. - if ( 'wp-optimize/wp-optimize.php' === $plugin ) { - if ( class_exists( '\WP_Optimize' ) ) { - $cache = WP_Optimize()->get_page_cache(); - if ( $cache->is_enabled() === false ) { - continue; - } elseif ( $cache->is_enabled() === true ) { - { - $cache_plugin_solution = 'WP Optimize'; - } + $supported_cache_plugins = array( + 'wp-rocket/wp-rocket.php' => 'WP Rocket', + 'breeze/breeze.php' => 'Breeze', + 'litespeed-cache/litespeed-cache.php' => 'LiteSpeed Cache', + 'sg-cachepress/sg-cachepress.php' => 'SiteGround Optimizer', + 'swift-performance-lite/performance.php' => 'Swift Performance Lite', + 'swift-performance/performance.php' => 'Swift Performance', + 'wp-fastest-cache/wpFastestCache.php' => 'WP Fastest Cache', + 'w3-total-cache/w3-total-cache.php' => 'W3 Total Cache', + 'hummingbird-performance/wp-hummingbird.php' => 'Hummingbird Performance', + 'cache-enabler/cache-enabler.php' => 'Cache Enabler', + 'nginx-helper/nginx-helper.php' => 'Nginx Helper', + 'nitropack/main.php' => 'Nitropack', + 'autoptimize/autoptimize.php' => 'Autoptimize', + 'flying-press/flying-press.php' => 'FlyingPress', + 'wp-super-cache/wp-cache.php' => 'WP Super Cache', + 'comet-cache/comet-cache.php' => 'Comet Cache', + 'wp-optimize/wp-optimize.php' => 'WP Optimize', + 'seraphinite-accelerator/plugin_root.php' => 'Seraphinite Accelerator', + 'swis-performance/swis-performance.php' => 'Swis Performance', + 'pressable-cache-management/pressable-cache-management.php' => 'Pressable Cache Management', + ); + + // Check if a supported cache plugin is active. + foreach ( $supported_cache_plugins as $plugin => $name ) { + if ( is_plugin_active( $plugin ) ) { + + // Check if WP Optimize is active and page cache is enabled or disabled. If disabled, continue to next plugin as if it is not installed. + if ( 'wp-optimize/wp-optimize.php' === $plugin ) { + if ( class_exists( '\WP_Optimize' ) ) { + $cache = WP_Optimize()->get_page_cache(); + if ( $cache->is_enabled() === false ) { + continue; + } elseif ( $cache->is_enabled() === true ) { + { + $cache_plugin_solution = 'WP Optimize'; } } - } else { - $cache_plugin_solution = $name; } + } else { + $cache_plugin_solution = $name; } } - - // Update wp_option 'mainwp_cache_control_cache_solution' with active plugin or "Plugin Not Found". - update_option( 'mainwp_cache_control_cache_solution', $cache_plugin_solution ); } - /** - * Auto purge cache based on which cache plugin is installed & activated. - * - * @used-by MainWP_Child_Updates::upgrade_plugin_theme() - * @used-by MainWP_Child_Updates::upgrade_wp() - * - * @param string $bulk Bulk update distinguisher. - * - * @return void - */ - public function auto_purge_cache( $bulk = '' ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. - - $do_purge = get_option( 'mainwp_child_auto_purge_cache' ); - // If Cache Control is enabled, run the cache purge. - if ( 1 === $do_purge || '1' === $do_purge ) { - - // Set information array. - $information = array(); - - // Grab detected cache solution.. - $cache_plugin_solution = get_option( 'mainwp_cache_control_cache_solution', 0 ); - - // Run the corresponding cache plugin purge method. - try { - switch ( $cache_plugin_solution ) { - case 'WP Rocket': - $information = $this->wprocket_auto_cache_purge(); - break; - case 'Breeze': - $information = $this->breeze_auto_purge_cache(); - break; - case 'LiteSpeed Cache': - $information = $this->litespeed_auto_purge_cache(); - break; - case 'SiteGround Optimizer': - $information = $this->sitegrounds_optimizer_auto_purge_cache(); - break; - case 'Swift Performance Lite': - $information = $this->swift_performance_lite_auto_purge_cache(); - break; - case 'Swift Performance': - $information = $this->swift_performance_auto_purge_cache(); - break; - case 'WP Fastest Cache': - $information = $this->wp_fastest_cache_auto_purge_cache(); - break; - case 'W3 Total Cache': - $information = $this->w3_total_cache_auto_purge_cache(); - break; - case 'Hummingbird Performance': - $information = $this->wp_hummingbird_auto_purge_cache(); - break; - case 'Cache Enabler': - $information = $this->cache_enabler_auto_purge_cache(); - break; - case 'Nginx Helper': - $information = $this->nginx_helper_auto_purge_cache(); - break; - case 'Nitropack': - $information = $this->nitropack_auto_purge_cache(); - break; - case 'Autoptimize': - $information = $this->autoptimize_auto_purge_cache(); - break; - case 'FlyingPress': - $information = $this->flyingpress_auto_purge_cache(); - break; - case 'WP Super Cache': - $information = $this->wp_super_cache_auto_purge_cache(); - break; - case 'WP Optimize': - $information = $this->wp_optimize_auto_purge_cache(); - break; - case 'Comet Cache': - $information = $this->comet_cache_auto_purge_cache(); - break; - case 'CDN Cache Plugin': - $information = $this->cdn_cache_plugin_auto_purge_cache(); - break; - case 'Seraphinite Accelerator': - $information = $this->seraphinite_auto_purge_cache(); - break; - case 'Swis Performance': - $information = $this->swis_performance_auto_purge_cache(); - break; - case 'Pressable Cache Management': - $information = $this->pressable_cache_management_auto_purge_cache(); - default: - break; - } - } catch ( \Exception $e ) { - $information = array( 'error' => $e->getMessage() ); - } + // Update wp_option 'mainwp_cache_control_cache_solution' with active plugin or "Plugin Not Found". + update_option( 'mainwp_cache_control_cache_solution', $cache_plugin_solution ); + } - // If no cache plugin is found, set status to disabled but still pass "SUCCESS" action because it did not fail. - if ( 'Plugin Not Found' === $cache_plugin_solution ) { - $information = array( - 'status' => 'Disabled', - 'action' => 'SUCCESS', - ); + /** + * Auto purge cache based on which cache plugin is installed & activated. + * + * @used-by MainWP_Child_Updates::upgrade_plugin_theme() + * @used-by MainWP_Child_Updates::upgrade_wp() + * + * @param string $bulk Bulk update distinguisher. + * + * @return void + */ + public function auto_purge_cache( $bulk = '' ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. + + $do_purge = get_option( 'mainwp_child_auto_purge_cache' ); + // If Cache Control is enabled, run the cache purge. + if ( 1 === $do_purge || '1' === $do_purge ) { + + // Set information array. + $information = array(); + + // Grab detected cache solution.. + $cache_plugin_solution = get_option( 'mainwp_cache_control_cache_solution', 0 ); + + // Run the corresponding cache plugin purge method. + try { + switch ( $cache_plugin_solution ) { + case 'WP Rocket': + $information = $this->wprocket_auto_cache_purge(); + break; + case 'Breeze': + $information = $this->breeze_auto_purge_cache(); + break; + case 'LiteSpeed Cache': + $information = $this->litespeed_auto_purge_cache(); + break; + case 'SiteGround Optimizer': + $information = $this->sitegrounds_optimizer_auto_purge_cache(); + break; + case 'Swift Performance Lite': + $information = $this->swift_performance_lite_auto_purge_cache(); + break; + case 'Swift Performance': + $information = $this->swift_performance_auto_purge_cache(); + break; + case 'WP Fastest Cache': + $information = $this->wp_fastest_cache_auto_purge_cache(); + break; + case 'W3 Total Cache': + $information = $this->w3_total_cache_auto_purge_cache(); + break; + case 'Hummingbird Performance': + $information = $this->wp_hummingbird_auto_purge_cache(); + break; + case 'Cache Enabler': + $information = $this->cache_enabler_auto_purge_cache(); + break; + case 'Nginx Helper': + $information = $this->nginx_helper_auto_purge_cache(); + break; + case 'Nitropack': + $information = $this->nitropack_auto_purge_cache(); + break; + case 'Autoptimize': + $information = $this->autoptimize_auto_purge_cache(); + break; + case 'FlyingPress': + $information = $this->flyingpress_auto_purge_cache(); + break; + case 'WP Super Cache': + $information = $this->wp_super_cache_auto_purge_cache(); + break; + case 'WP Optimize': + $information = $this->wp_optimize_auto_purge_cache(); + break; + case 'Comet Cache': + $information = $this->comet_cache_auto_purge_cache(); + break; + case 'CDN Cache Plugin': + $information = $this->cdn_cache_plugin_auto_purge_cache(); + break; + case 'Seraphinite Accelerator': + $information = $this->seraphinite_auto_purge_cache(); + break; + case 'Swis Performance': + $information = $this->swis_performance_auto_purge_cache(); + break; + case 'Pressable Cache Management': + $information = $this->pressable_cache_management_auto_purge_cache(); + default: + break; } + } catch ( \Exception $e ) { + $information = array( 'error' => $e->getMessage() ); + } - // Fire off CloudFlare purge if enabled & not using a CDN Cache Plugin. ( Stops double purging Cloudflare ). - if ( '1' === get_option( 'mainwp_child_cloud_flair_enabled' ) && 'CDN Cache Plugin' !== $cache_plugin_solution ) { - $information['cloudflare'] = $this->cloudflair_auto_purge_cache(); - } - } else { - // If Cache Control is disabled, set status to disabled but still pass "SUCCESS" action because it did not fail. + // If no cache plugin is found, set status to disabled but still pass "SUCCESS" action because it did not fail. + if ( 'Plugin Not Found' === $cache_plugin_solution ) { $information = array( - 'status' => 'Disabled', - 'action' => 'SUCCESS', - 'do_purge' => $do_purge, + 'status' => 'Disabled', + 'action' => 'SUCCESS', ); } - // Save to DB. - $this->record_results( $information ); - - // Only fire off if this is a 'bulk' action. - if ( 'true' === $bulk ) { - // Return results in JSON format. - MainWP_Helper::write( $information ); + // Fire off CloudFlare purge if enabled & not using a CDN Cache Plugin. ( Stops double purging Cloudflare ). + if ( '1' === get_option( 'mainwp_child_cloud_flair_enabled' ) && 'CDN Cache Plugin' !== $cache_plugin_solution ) { + $information['cloudflare'] = $this->cloudflair_auto_purge_cache(); } - } - - /** - * Build purge results array for return to dashboard. - * - * @param string $message Result message. - * @param string $action Action result. - * - * @return array Purge results array. - */ - public function purge_result( $message, $action ) { - $result = array( - 'Last Purged' => get_option( 'mainwp_cache_control_last_purged', false ), - 'Cache Solution' => get_option( 'mainwp_cache_control_cache_solution', false ), - 'Cache Control Enabled' => get_option( 'mainwp_child_auto_purge_cache' ), - 'Cloudflair Enabled' => get_option( 'mainwp_child_cloud_flair_enabled' ), + } else { + // If Cache Control is disabled, set status to disabled but still pass "SUCCESS" action because it did not fail. + $information = array( + 'status' => 'Disabled', + 'action' => 'SUCCESS', + 'do_purge' => $do_purge, ); - $result['result'] = $message; - if ( 'SUCCESS' === $action ) { - $result['action'] = 'SUCCESS'; - } else { - $result['action'] = 'ERROR'; - } - return $result; } - /** - * Purge Pressable Cache Management. - */ - public function pressable_cache_management_auto_purge_cache() { + // Save to DB. + $this->record_results( $information ); - $success_message = 'Pressable Cache Management => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + // Only fire off if this is a 'bulk' action. + if ( 'true' === $bulk ) { + // Return results in JSON format. + MainWP_Helper::write( $information ); + } + } - if ( is_callable( 'flush_pressable_cache_callback' ) ) { - flush_pressable_cache_callback(); - } - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + /** + * Build purge results array for return to dashboard. + * + * @param string $message Result message. + * @param string $action Action result. + * + * @return array Purge results array. + */ + public function purge_result( $message, $action ) { + $result = array( + 'Last Purged' => get_option( 'mainwp_cache_control_last_purged', false ), + 'Cache Solution' => get_option( 'mainwp_cache_control_cache_solution', false ), + 'Cache Control Enabled' => get_option( 'mainwp_child_auto_purge_cache' ), + 'Cloudflair Enabled' => get_option( 'mainwp_child_cloud_flair_enabled' ), + ); + $result['result'] = $message; + if ( 'SUCCESS' === $action ) { + $result['action'] = 'SUCCESS'; + } else { + $result['action'] = 'ERROR'; } + return $result; + } - /** - * Purge Swis Performance plugin cache. - * - * @return array Purge results array. - */ - public function swis_performance_auto_purge_cache() { + /** + * Purge Pressable Cache Management. + */ + public function pressable_cache_management_auto_purge_cache() { - $success_message = 'Swis Performance => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Swis Performance => There was an issue purging your cache.'; - $bypass_message = 'Swis Performance => Purge was bypassed due to Swis Auto Purge Settings.'; + $success_message = 'Pressable Cache Management => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - if ( is_callable( 'swis' ) ) { + if ( is_callable( 'flush_pressable_cache_callback' ) ) { + flush_pressable_cache_callback(); + } + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); + return $this->purge_result( $success_message, 'SUCCESS' ); + } - // Get Swis Cache Settings. - $swis_cache_settings = swis()->cache->get_settings(); + /** + * Purge Swis Performance plugin cache. + * + * @return array Purge results array. + */ + public function swis_performance_auto_purge_cache() { - // Check if Swis Auto Purge is enabled. - if ( empty( $swis_cache_settings['clear_complete_cache_on_changed_plugin'] ) ) { + $success_message = 'Swis Performance => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Swis Performance => There was an issue purging your cache.'; + $bypass_message = 'Swis Performance => Purge was bypassed due to Swis Auto Purge Settings.'; - // Purge Cache. - do_action( 'swis_clear_complete_cache' ); + if ( is_callable( 'swis' ) ) { - sleep( 3 ); + // Get Swis Cache Settings. + $swis_cache_settings = swis()->cache->get_settings(); - // Preload Cache. - swis()->cache_preload->start_preload(); - } else { - return $this->purge_result( $bypass_message, 'SUCCESS' ); - } + // Check if Swis Auto Purge is enabled. + if ( empty( $swis_cache_settings['clear_complete_cache_on_changed_plugin'] ) ) { + + // Purge Cache. + do_action( 'swis_clear_complete_cache' ); + + sleep( 3 ); - // record results. ( below needs to stay untouched ). - update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + // Preload Cache. + swis()->cache_preload->start_preload(); } else { - return $this->purge_result( $error_message, 'ERROR' ); + return $this->purge_result( $bypass_message, 'SUCCESS' ); } + + // record results. ( below needs to stay untouched ). + update_option( 'mainwp_cache_control_last_purged', time() ); + return $this->purge_result( $success_message, 'SUCCESS' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge Seraphinite Accelerator plugin cache. - * - * @return array Purge results array. - */ - public function seraphinite_auto_purge_cache() { + /** + * Purge Seraphinite Accelerator plugin cache. + * + * @return array Purge results array. + */ + public function seraphinite_auto_purge_cache() { - $success_message = 'Seraphinite Accelerator => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Seraphinite Accelerator => There was an issue purging your cache.'; + $success_message = 'Seraphinite Accelerator => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Seraphinite Accelerator => There was an issue purging your cache.'; - if ( class_exists( '\seraph_accel\API' ) ) { + if ( class_exists( '\seraph_accel\API' ) ) { - \seraph_accel\API::OperateCache( \seraph_accel\API::CACHE_OP_DEL ); + \seraph_accel\API::OperateCache( \seraph_accel\API::CACHE_OP_DEL ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge CDN Cache Plugin cache. - * - * @return array Purge results array. - */ - public function cdn_cache_plugin_auto_purge_cache() { + /** + * Purge CDN Cache Plugin cache. + * + * @return array Purge results array. + */ + public function cdn_cache_plugin_auto_purge_cache() { - $success_message = 'CDN Cache Plugin => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'CDN Cache Plugin => There was an issue purging your cache.'; + $success_message = 'CDN Cache Plugin => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'CDN Cache Plugin => There was an issue purging your cache.'; - if ( class_exists( 'CDN_Clear_Cache_Api' ) ) { + if ( class_exists( 'CDN_Clear_Cache_Api' ) ) { - \CDN_Clear_Cache_Api::cache_api_call( array(), 'purge_everything' ); + \CDN_Clear_Cache_Api::cache_api_call( array(), 'purge_everything' ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge Comet Cache. - * - * @return array Purge results array. - */ - public function comet_cache_auto_purge_cache() { + /** + * Purge Comet Cache. + * + * @return array Purge results array. + */ + public function comet_cache_auto_purge_cache() { - $success_message = 'Comet Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Comet Cache => There was an issue purging your cache.'; + $success_message = 'Comet Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Comet Cache => There was an issue purging your cache.'; - if ( class_exists( '\comet_cache' ) ) { + if ( class_exists( '\comet_cache' ) ) { - // Clear Cache. - \comet_cache::clear(); + // Clear Cache. + \comet_cache::clear(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge WP Optimize cache. - * - * @return array Purge results array. - */ - public function wp_optimize_auto_purge_cache() { + /** + * Purge WP Optimize cache. + * + * @return array Purge results array. + */ + public function wp_optimize_auto_purge_cache() { - $success_message = 'WP Optimize => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'WP Optimize => There was an issue purging your cache.'; + $success_message = 'WP Optimize => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'WP Optimize => There was an issue purging your cache.'; - // Clear Cache. - $purge = self::wp_optimize_purge_cache(); + // Clear Cache. + $purge = self::wp_optimize_purge_cache(); - // Purge Minified files. - $minify = self::wp_optimize_purge_minify(); + // Purge Minified files. + $minify = self::wp_optimize_purge_minify(); - // Preload cache. - $preload = self::wp_optimize_preload_cache(); + // Preload cache. + $preload = self::wp_optimize_preload_cache(); - // Check response & return results. - if ( ( true === $purge && true === $preload ) || ( true === $minify && true === $purge && true === $preload ) ) { - update_option( 'mainwp_cache_control_last_purged', time() ); + // Check response & return results. + if ( ( true === $purge && true === $preload ) || ( true === $minify && true === $purge && true === $preload ) ) { + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Preload WP Optimize cache after purge. - * - * @return bool True if successful, false if not. - */ - public function wp_optimize_preload_cache() { - if ( class_exists( '\WP_Optimize_Cache_Commands' ) && class_exists( '\WP_Optimize_Page_Cache_Preloader' ) ) { - - // Clear Cache. - $purge = new \WP_Optimize_Cache_Commands(); - $purge->run_cache_preload(); - return true; - } - return false; + /** + * Preload WP Optimize cache after purge. + * + * @return bool True if successful, false if not. + */ + public function wp_optimize_preload_cache() { + if ( class_exists( '\WP_Optimize_Cache_Commands' ) && class_exists( '\WP_Optimize_Page_Cache_Preloader' ) ) { + + // Clear Cache. + $purge = new \WP_Optimize_Cache_Commands(); + $purge->run_cache_preload(); + return true; } + return false; + } - /** - * Purge WP Optimize minified files. - * - * @return bool True if successful, false if not. - */ - public function wp_optimize_purge_minify() { - if ( class_exists( '\WP_Optimize' ) ) { - $cache = \WP_Optimize()->get_page_cache()->purge(); - - // $cache returns true if successful, false if not. - return true; - } - return false; + /** + * Purge WP Optimize minified files. + * + * @return bool True if successful, false if not. + */ + public function wp_optimize_purge_minify() { + if ( class_exists( '\WP_Optimize' ) ) { + $cache = \WP_Optimize()->get_page_cache()->purge(); + + // $cache returns true if successful, false if not. + return true; } + return false; + } - /** - * Purge WP Optimize cache. - * - * @return bool True if successful, false if not. - */ - public function wp_optimize_purge_cache() { - if ( class_exists( '\WP_Optimize' ) ) { - $cache = \WP_Optimize()->get_page_cache(); - $cache->purge(); - - return true; - } - return false; + /** + * Purge WP Optimize cache. + * + * @return bool True if successful, false if not. + */ + public function wp_optimize_purge_cache() { + if ( class_exists( '\WP_Optimize' ) ) { + $cache = \WP_Optimize()->get_page_cache(); + $cache->purge(); + + return true; } + return false; + } - /** - * Check if WP Optimize is installed and cache is enabled. - */ - public function wp_optimize_activated_check() { - if ( class_exists( '\WP_Optimize' ) ) { - $cache = WP_Optimize()->get_page_cache(); - if ( ! $cache->is_enabled() ) { - return false; - } + /** + * Check if WP Optimize is installed and cache is enabled. + */ + public function wp_optimize_activated_check() { + if ( class_exists( '\WP_Optimize' ) ) { + $cache = WP_Optimize()->get_page_cache(); + if ( ! $cache->is_enabled() ) { + return false; } } + } - /** - * Purge WP Super Cache. - * - * @return array Purge results array. - */ - public function wp_super_cache_auto_purge_cache() { + /** + * Purge WP Super Cache. + * + * @return array Purge results array. + */ + public function wp_super_cache_auto_purge_cache() { - $success_message = 'WP Super Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'WP Super Cache => There was an issue purging your cache.'; + $success_message = 'WP Super Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'WP Super Cache => There was an issue purging your cache.'; - if ( function_exists( '\wp_cache_clean_cache' ) ) { + if ( function_exists( '\wp_cache_clean_cache' ) ) { - // Clear Cache. - global $file_prefix; - \wp_cache_clean_cache( $file_prefix, true ); + // Clear Cache. + global $file_prefix; + \wp_cache_clean_cache( $file_prefix, true ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge FlyingPress cache. - * - * @return array Purge results array. - */ - public function flyingpress_auto_purge_cache() { + /** + * Purge FlyingPress cache. + * + * @return array Purge results array. + */ + public function flyingpress_auto_purge_cache() { - $success_message = 'FlyingPress Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'FlyingPress Cache => There was an issue purging your cache.'; + $success_message = 'FlyingPress Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'FlyingPress Cache => There was an issue purging your cache.'; - if ( class_exists( '\FlyingPress\Purge' ) && class_exists( '\FlyingPress\Preload' ) ) { + if ( class_exists( '\FlyingPress\Purge' ) && class_exists( '\FlyingPress\Preload' ) ) { - // Clear Cache. - \FlyingPress\Purge::purge_everything(); + // Clear Cache. + \FlyingPress\Purge::purge_everything(); - sleep( 3 ); - // Preload Cache. - \FlyingPress\Preload::preload_cache(); + sleep( 3 ); + // Preload Cache. + \FlyingPress\Preload::preload_cache(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge Autoptimize cache. - * - * @return array Purge results array. - */ - public function autoptimize_auto_purge_cache() { + /** + * Purge Autoptimize cache. + * + * @return array Purge results array. + */ + public function autoptimize_auto_purge_cache() { - $success_message = 'Autoptimize => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Autoptimize => There was an issue purging your cache.'; + $success_message = 'Autoptimize => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Autoptimize => There was an issue purging your cache.'; - if ( class_exists( 'autoptimizeCache' ) ) { + if ( class_exists( 'autoptimizeCache' ) ) { - // Clear Cache. - \autoptimizeCache::clearall(); + // Clear Cache. + \autoptimizeCache::clearall(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge Nitropack cache. - * - * Nitropack_purge($url = NULL, $tag = NULL, $reason = NULL); - * - * In case you want to do a full purge, you must leave the values - * for URL and Tag empty. In case you want to create a targeted purge - * you can replace them with the URL or tag of the page. - * - * @return array Purge results array. - */ - public function nitropack_auto_purge_cache() { + /** + * Purge Nitropack cache. + * + * Nitropack_purge($url = NULL, $tag = NULL, $reason = NULL); + * + * In case you want to do a full purge, you must leave the values + * for URL and Tag empty. In case you want to create a targeted purge + * you can replace them with the URL or tag of the page. + * + * @return array Purge results array. + */ + public function nitropack_auto_purge_cache() { - $success_message = 'Nitropack => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Nitropack => There was an issue purging your cache.'; + $success_message = 'Nitropack => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Nitropack => There was an issue purging your cache.'; - if ( function_exists( 'nitropack_purge' ) ) { + if ( function_exists( 'nitropack_purge' ) ) { - // Clear Nitropack Cache after update. - nitropack_purge(); + // Clear Nitropack Cache after update. + nitropack_purge(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge Nginx Helper cache. - * - * @return array Purge results array. - */ - public function nginx_helper_auto_purge_cache() { + /** + * Purge Nginx Helper cache. + * + * @return array Purge results array. + */ + public function nginx_helper_auto_purge_cache() { - $success_message = 'Nginx Helper => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Nginx Helper => There was an issue purging your cache.'; + $success_message = 'Nginx Helper => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Nginx Helper => There was an issue purging your cache.'; - if ( class_exists( 'Nginx_Helper' ) ) { + if ( class_exists( 'Nginx_Helper' ) ) { - // Clear Nginx Helper Cache after update. - do_action( 'rt_nginx_helper_purge_all' ); + // Clear Nginx Helper Cache after update. + do_action( 'rt_nginx_helper_purge_all' ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge WP Hummingbird cache. - * - * @note needs to have namespace or it will not work. - * - * @return array Purge results array. - */ - public function wp_hummingbird_auto_purge_cache() { + /** + * Purge WP Hummingbird cache. + * + * @note needs to have namespace or it will not work. + * + * @return array Purge results array. + */ + public function wp_hummingbird_auto_purge_cache() { - $success_message = 'Hummingbird => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Hummingbird => There was an issue purging your cache.'; + $success_message = 'Hummingbird => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Hummingbird => There was an issue purging your cache.'; - if ( class_exists( 'Hummingbird\Core\Modules\\Page_Cache' ) ) { + if ( class_exists( 'Hummingbird\Core\Modules\\Page_Cache' ) ) { - // Clear WP Hummingbird Cache after update. - do_action( 'wphb_clear_page_cache' ); + // Clear WP Hummingbird Cache after update. + do_action( 'wphb_clear_page_cache' ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge Cache Enabler cache. - * - * @return array Purge results array. - */ - public function cache_enabler_auto_purge_cache() { + /** + * Purge Cache Enabler cache. + * + * @return array Purge results array. + */ + public function cache_enabler_auto_purge_cache() { - $success_message = 'Cache Enabler => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Cache Enabler => There was an issue purging your cache.'; + $success_message = 'Cache Enabler => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Cache Enabler => There was an issue purging your cache.'; - if ( class_exists( 'Cache_Enabler' ) ) { + if ( class_exists( 'Cache_Enabler' ) ) { - // Clear the Cache after update. - \Cache_Enabler::clear_complete_cache(); + // Clear the Cache after update. + \Cache_Enabler::clear_complete_cache(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge W3 Total Cache. - * - * @return array Purge results array. - */ - public function w3_total_cache_auto_purge_cache() { + /** + * Purge W3 Total Cache. + * + * @return array Purge results array. + */ + public function w3_total_cache_auto_purge_cache() { - $success_message = 'W3 Total Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'W3 Total Cache => There was an issue purging your cache.'; + $success_message = 'W3 Total Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'W3 Total Cache => There was an issue purging your cache.'; - if ( function_exists( 'w3tc_flush_all' ) ) { + if ( function_exists( 'w3tc_flush_all' ) ) { - // Purge all W3 total cache. - w3tc_flush_all(); + // Purge all W3 total cache. + w3tc_flush_all(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge WP Fastest Cache. - * - * @return array Purge results array. - */ - public function wp_fastest_cache_auto_purge_cache() { + /** + * Purge WP Fastest Cache. + * + * @return array Purge results array. + */ + public function wp_fastest_cache_auto_purge_cache() { - $success_message = 'WP Fastest Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'WP Fastest Cache => There was an issue purging your cache.'; + $success_message = 'WP Fastest Cache => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'WP Fastest Cache => There was an issue purging your cache.'; - if ( class_exists( 'WpFastestCache' ) ) { + if ( class_exists( 'WpFastestCache' ) ) { - // Clear the Cache after update. - do_action( 'wpfc_clear_all_cache' ); + // Clear the Cache after update. + do_action( 'wpfc_clear_all_cache' ); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge Swift Performance Lite Cache. - * - * @return array Purge results array. - */ - public function swift_performance_lite_auto_purge_cache() { + /** + * Purge Swift Performance Lite Cache. + * + * @return array Purge results array. + */ + public function swift_performance_lite_auto_purge_cache() { - $success_message = 'Swift Performance Lite => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Swift Performance Lite => There was an issue purging your cache.'; + $success_message = 'Swift Performance Lite => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Swift Performance Lite => There was an issue purging your cache.'; - if ( class_exists( 'Swift_Performance_Cache' ) ) { + if ( class_exists( 'Swift_Performance_Cache' ) ) { - // Clear All Swift Performance Lite Cache. - \Swift_Performance_Cache::clear_all_cache(); + // Clear All Swift Performance Lite Cache. + \Swift_Performance_Cache::clear_all_cache(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge Swift Performance Cache. - * - * @return array Purge results array. - */ - public function swift_performance_auto_purge_cache() { + /** + * Purge Swift Performance Cache. + * + * @return array Purge results array. + */ + public function swift_performance_auto_purge_cache() { - $success_message = 'Swift Performance => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Swift Performance => There was an issue purging your cache.'; + $success_message = 'Swift Performance => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Swift Performance => There was an issue purging your cache.'; - if ( class_exists( 'Swift_Performance_Cache' ) ) { + if ( class_exists( 'Swift_Performance_Cache' ) ) { - // Clear All Swift Performance Cache. - \Swift_Performance_Cache::clear_all_cache(); + // Clear All Swift Performance Cache. + \Swift_Performance_Cache::clear_all_cache(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge SiteGrounds Optimiser Cache. - * - * @return array Purge results array. - */ - public function sitegrounds_optimizer_auto_purge_cache() { + /** + * Purge SiteGrounds Optimiser Cache. + * + * @return array Purge results array. + */ + public function sitegrounds_optimizer_auto_purge_cache() { - $success_message = 'SiteGround Optimizer => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'SiteGround Optimizer => There was an issue purging your cache.'; + $success_message = 'SiteGround Optimizer => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'SiteGround Optimizer => There was an issue purging your cache.'; - if ( function_exists( 'sg_cachepress_purge_everything' ) ) { + if ( function_exists( 'sg_cachepress_purge_everything' ) ) { - // Purge all SG CachePress cache. - sg_cachepress_purge_everything(); + // Purge all SG CachePress cache. + sg_cachepress_purge_everything(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - return $this->purge_result( $error_message, 'ERROR' ); - } + return $this->purge_result( $success_message, 'SUCCESS' ); + } else { + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge Cloudflair Cache. - * - * @noinspection PhpIdempotentOperationInspection - * - * @return array Purge results array. - */ - public function cloudflair_auto_purge_cache() { - - // Credentials for Cloudflare. - $cust_email = get_option( 'mainwp_cloudflair_email', '' ); - $cust_xauth = get_option( 'mainwp_child_cloudflair_key', '' ); - if ( ! empty( $cust_xauth ) ) { - $cust_xauth = MainWP_Child_Keys_Manager::instance()->decrypt_string( $cust_xauth ); - } - $cust_domain = trim( str_replace( array( 'http://', 'https://', 'www.' ), '', get_option( 'siteurl' ) ), '/' ); + /** + * Purge Cloudflair Cache. + * + * @noinspection PhpIdempotentOperationInspection + * + * @return array Purge results array. + */ + public function cloudflair_auto_purge_cache() { - // Check if we have all the required data. - if ( '' === $cust_email || '' === $cust_xauth ) { - return; - } + // Credentials for Cloudflare. + $cust_email = get_option( 'mainwp_cloudflair_email', '' ); + $cust_xauth = get_option( 'mainwp_child_cloudflair_key', '' ); + if ( ! empty( $cust_xauth ) ) { + $cust_xauth = MainWP_Child_Keys_Manager::instance()->decrypt_string( $cust_xauth ); + } + $cust_domain = trim( str_replace( array( 'http://', 'https://', 'www.' ), '', get_option( 'siteurl' ) ), '/' ); - // Strip subdomains. Cloudflare doesn't like them. - $cust_domain = $this->strip_subdomains( $cust_domain ); - - // Get the Zone-ID from Cloudflare since they don't provide that in the Backend. - $ch_query = curl_init(); // phpcs:ignore -- use core function. - curl_setopt( $ch_query, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones?name=' . $cust_domain . '&status=active&page=1&per_page=5&order=status&direction=desc&match=all' ); // phpcs:ignore -- use core function. - curl_setopt( $ch_query, CURLOPT_RETURNTRANSFER, 1 ); // phpcs:ignore -- use core function. - $qheaders = array( - 'X-Auth-Email: ' . $cust_email . '', - 'X-Auth-Key: ' . $cust_xauth . '', - 'Content-Type: application/json', - ); - curl_setopt( $ch_query, CURLOPT_HTTPHEADER, $qheaders ); // phpcs:ignore -- use core function. - $qresult = json_decode( curl_exec( $ch_query ), true ); // phpcs:ignore -- use core function. - if ( 'resource' === gettype( $ch_query ) ) { - curl_close( $ch_query ); // phpcs:ignore -- use core function. - } + // Check if we have all the required data. + if ( '' === $cust_email || '' === $cust_xauth ) { + return; + } - $cust_zone = $qresult['result'][0]['id']; - - // Purge the entire cache via API. - $ch_purge = curl_init(); // phpcs:ignore -- use core function. - curl_setopt( $ch_purge, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones/' . $cust_zone . '/purge_cache' ); // phpcs:ignore -- use core function. - curl_setopt( $ch_purge, CURLOPT_CUSTOMREQUEST, 'DELETE' ); // phpcs:ignore -- use core function. - curl_setopt( $ch_purge, CURLOPT_RETURNTRANSFER, 1 ); // phpcs:ignore -- use core function. - $headers = array( - 'X-Auth-Email: ' . $cust_email, - 'X-Auth-Key: ' . $cust_xauth, - 'Content-Type: application/json', - ); - $data = wp_json_encode( array( 'purge_everything' => true ) ); // phpcs:ignore -- ok. - curl_setopt( $ch_purge, CURLOPT_POST, true ); // phpcs:ignore -- use core function. - curl_setopt( $ch_purge, CURLOPT_POSTFIELDS, $data ); // phpcs:ignore -- use core function. - curl_setopt( $ch_purge, CURLOPT_HTTPHEADER, $headers ); // phpcs:ignore -- use core function. - - $result = json_decode( curl_exec( $ch_purge ), true ); // phpcs:ignore -- use core function. - if ( 'resource' === gettype( $ch_query ) ) { - curl_close( $ch_purge ); // phpcs:ignore -- use core function. - } - $success_message = 'Cloudflare => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Cloudflare => There was an issue purging the cache. ' . wp_json_encode( $qresult['errors'][0], JSON_UNESCAPED_SLASHES ) . "-" . wp_json_encode( $result['errors'][0], JSON_UNESCAPED_SLASHES ); // phpcs:ignore -- ok. + // Strip subdomains. Cloudflare doesn't like them. + $cust_domain = $this->strip_subdomains( $cust_domain ); + + // Get the Zone-ID from Cloudflare since they don't provide that in the Backend. + $ch_query = curl_init(); // phpcs:ignore -- use core function. + curl_setopt( $ch_query, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones?name=' . $cust_domain . '&status=active&page=1&per_page=5&order=status&direction=desc&match=all' ); // phpcs:ignore -- use core function. + curl_setopt( $ch_query, CURLOPT_RETURNTRANSFER, 1 ); // phpcs:ignore -- use core function. + $qheaders = array( + 'X-Auth-Email: ' . $cust_email . '', + 'X-Auth-Key: ' . $cust_xauth . '', + 'Content-Type: application/json', + ); + curl_setopt( $ch_query, CURLOPT_HTTPHEADER, $qheaders ); // phpcs:ignore -- use core function. + $qresult = json_decode( curl_exec( $ch_query ), true ); // phpcs:ignore -- use core function. + if ( 'resource' === gettype( $ch_query ) ) { + curl_close( $ch_query ); // phpcs:ignore -- use core function. + } - // Save last purge time to database on success. - if ( 1 === (int) $result['success'] ) { + $cust_zone = $qresult['result'][0]['id']; + + // Purge the entire cache via API. + $ch_purge = curl_init(); // phpcs:ignore -- use core function. + curl_setopt( $ch_purge, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones/' . $cust_zone . '/purge_cache' ); // phpcs:ignore -- use core function. + curl_setopt( $ch_purge, CURLOPT_CUSTOMREQUEST, 'DELETE' ); // phpcs:ignore -- use core function. + curl_setopt( $ch_purge, CURLOPT_RETURNTRANSFER, 1 ); // phpcs:ignore -- use core function. + $headers = array( + 'X-Auth-Email: ' . $cust_email, + 'X-Auth-Key: ' . $cust_xauth, + 'Content-Type: application/json', + ); + $data = wp_json_encode( array( 'purge_everything' => true ) ); // phpcs:ignore -- ok. + curl_setopt( $ch_purge, CURLOPT_POST, true ); // phpcs:ignore -- use core function. + curl_setopt( $ch_purge, CURLOPT_POSTFIELDS, $data ); // phpcs:ignore -- use core function. + curl_setopt( $ch_purge, CURLOPT_HTTPHEADER, $headers ); // phpcs:ignore -- use core function. + + $result = json_decode( curl_exec( $ch_purge ), true ); // phpcs:ignore -- use core function. + if ( 'resource' === gettype( $ch_query ) ) { + curl_close( $ch_purge ); // phpcs:ignore -- use core function. + } + $success_message = 'Cloudflare => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Cloudflare => There was an issue purging the cache. ' . wp_json_encode( $qresult['errors'][0], JSON_UNESCAPED_SLASHES ) . "-" . wp_json_encode( $result['errors'][0], JSON_UNESCAPED_SLASHES ); // phpcs:ignore -- ok. - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // Save last purge time to database on success. + if ( 1 === (int) $result['success'] ) { - // Return success message. - return $this->purge_result( $success_message, 'SUCCESS' ); - } elseif ( ( 1 !== (int) $qresult['success'] ) || ( 1 !== (int) $result['success'] ) ) { - // Return error message. - return $this->purge_result( $error_message, 'ERROR' ); - } + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); + + // Return success message. + return $this->purge_result( $success_message, 'SUCCESS' ); + } elseif ( ( 1 !== (int) $qresult['success'] ) || ( 1 !== (int) $result['success'] ) ) { + // Return error message. + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge LiteSpeed Cache. - * - * @return array Purge results array. - */ - public function litespeed_auto_purge_cache() { + /** + * Purge LiteSpeed Cache. + * + * @return array Purge results array. + */ + public function litespeed_auto_purge_cache() { - $success_message = 'LiteSpeed => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'LiteSpeed => There was an issue purging your cache.'; + $success_message = 'LiteSpeed => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'LiteSpeed => There was an issue purging your cache.'; - if ( class_exists( '\LiteSpeed\Purge' ) ) { + if ( class_exists( '\LiteSpeed\Purge' ) ) { - // Purge all LS Cache. - \LiteSpeed\Purge::purge_all(); + // Purge all LS Cache. + \LiteSpeed\Purge::purge_all(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - // Return success message. - return $this->purge_result( $success_message, 'SUCCESS' ); + // Return success message. + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - // Return error message. - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + // Return error message. + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge Breeze cache. - * - * @return array Purge results array. - */ - public function breeze_auto_purge_cache() { + /** + * Purge Breeze cache. + * + * @return array Purge results array. + */ + public function breeze_auto_purge_cache() { - $success_message = 'Breeze => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - $error_message = 'Breeze => There was an issue purging your cache.'; + $success_message = 'Breeze => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + $error_message = 'Breeze => There was an issue purging your cache.'; - if ( class_exists( 'Breeze_Admin' ) ) { + if ( class_exists( 'Breeze_Admin' ) ) { - // Clears varnish cache. - $admin = new \Breeze_Admin(); - $admin->breeze_clear_varnish(); + // Clears varnish cache. + $admin = new \Breeze_Admin(); + $admin->breeze_clear_varnish(); - // For local static files: Clears files within /cache/breeze-minification/ folder. - if ( class_exists( '\Breeze_Configuration' ) ) { - $size_cache = \Breeze_Configuration::breeze_clean_cache(); - } else { - $size_cache = 0; - } + // For local static files: Clears files within /cache/breeze-minification/ folder. + if ( class_exists( '\Breeze_Configuration' ) ) { + $size_cache = \Breeze_Configuration::breeze_clean_cache(); + } else { + $size_cache = 0; + } - // Delete minified files. - \Breeze_MinificationCache::clear_minification(); + // Delete minified files. + \Breeze_MinificationCache::clear_minification(); - // Clear normal cache. - \Breeze_PurgeCache::breeze_cache_flush(); + // Clear normal cache. + \Breeze_PurgeCache::breeze_cache_flush(); - // record results. - update_option( 'mainwp_cache_control_last_purged', time() ); + // record results. + update_option( 'mainwp_cache_control_last_purged', time() ); - // Return success message. - return $this->purge_result( $success_message, 'SUCCESS' ); + // Return success message. + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { - // Return error message. - return $this->purge_result( $error_message, 'ERROR' ); - } + } else { + // Return error message. + return $this->purge_result( $error_message, 'ERROR' ); } + } - /** - * Purge WP-Rocket cache. - * - * @return array Purge results array. - */ - public function wprocket_auto_cache_purge() { + /** + * Purge WP-Rocket cache. + * + * @return array Purge results array. + */ + public function wprocket_auto_cache_purge() { - // Purge Cache if action is set to "1". - $do_purge = get_option( 'mainwp_child_auto_purge_cache', false ); - $purge_result = array(); + // Purge Cache if action is set to "1". + $do_purge = get_option( 'mainwp_child_auto_purge_cache', false ); + $purge_result = array(); - if ( 1 === (int) $do_purge ) { - $purge_result = MainWP_Child_WP_Rocket::instance()->purge_cache_all(); - } + if ( 1 === (int) $do_purge ) { + $purge_result = MainWP_Child_WP_Rocket::instance()->purge_cache_all(); + } - // Record results & return response. - if ( 'SUCCESS' === $purge_result['result'] ) { + // Record results & return response. + if ( 'SUCCESS' === $purge_result['result'] ) { - // Save last purge time to database on success. - update_option( 'mainwp_cache_control_last_purged', time() ); + // Save last purge time to database on success. + update_option( 'mainwp_cache_control_last_purged', time() ); - // Return success message. - $success_message = 'WP Rocket => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; - return $this->purge_result( $success_message, 'SUCCESS' ); + // Return success message. + $success_message = 'WP Rocket => Cache auto cleared on: (' . current_time( 'mysql' ) . ')'; + return $this->purge_result( $success_message, 'SUCCESS' ); - } else { + } else { - // Return error message. - $error_message = 'WP Rocket => There was an issue purging your cache.'; - return $this->purge_result( $error_message, 'ERROR' ); + // Return error message. + $error_message = 'WP Rocket => There was an issue purging your cache.'; + return $this->purge_result( $error_message, 'ERROR' ); - } } + } - /** - * Record last Purge. - * - * Create log file & Save in /Upload dir. - * - * @param array $information Array containing the data to be sent to the Dashboard. - */ - public function record_results( $information ) { - - // Setup timezone and upload directory for logs. - $ti = wp_timezone(); - if ( is_array( $ti ) && isset( $ti['timezone'] ) ) { - date_default_timezone_set( $ti['timezone'] ); // phpcs:ignore -- use core function. - } + /** + * Record last Purge. + * + * Create log file & Save in /Upload dir. + * + * @param array $information Array containing the data to be sent to the Dashboard. + */ + public function record_results( $information ) { - // Save Cache Control Log Data. - update_option( 'mainwp_cache_control_log', wp_json_encode( $information ) ); + // Setup timezone and upload directory for logs. + $ti = wp_timezone(); + if ( is_array( $ti ) && isset( $ti['timezone'] ) ) { + date_default_timezone_set( $ti['timezone'] ); // phpcs:ignore -- use core function. } - /** - * Strip subdomains from a url. - * - * @param string $url string The url to strip subdomains from. - * - * @return string The url without subdomains (if any). - */ - public function strip_subdomains( $url ) { - $parts = explode( '/', $url ); - $url_first = $parts[0]; // get first part. - $count = count( explode( '.', $url_first ) ); - $domain = ''; - if ( 4 <= $count ) { - $domain = implode( '.', array_slice( explode( '.', $url_first ), -3 ) ); - } else { - $domain = implode( '.', array_slice( explode( '.', $url_first ), -2 ) ); - } - return $domain; + // Save Cache Control Log Data. + update_option( 'mainwp_cache_control_log', wp_json_encode( $information ) ); + } + + /** + * Strip subdomains from a url. + * + * @param string $url string The url to strip subdomains from. + * + * @return string The url without subdomains (if any). + */ + public function strip_subdomains( $url ) { + $parts = explode( '/', $url ); + $url_first = $parts[0]; // get first part. + $count = count( explode( '.', $url_first ) ); + $domain = ''; + if ( 4 <= $count ) { + $domain = implode( '.', array_slice( explode( '.', $url_first ), -3 ) ); + } else { + $domain = implode( '.', array_slice( explode( '.', $url_first ), -2 ) ); } + return $domain; } +} From 192e4eae9ea9b9b046b4585f16874aa25951ebe1 Mon Sep 17 00:00:00 2001 From: thanghv Date: Fri, 5 Apr 2024 01:05:17 +0700 Subject: [PATCH 7/9] Fixed codefacter issue --- class/class-mainwp-child-cache-purge.php | 1 + 1 file changed, 1 insertion(+) diff --git a/class/class-mainwp-child-cache-purge.php b/class/class-mainwp-child-cache-purge.php index a91b3fbe..c5644611 100644 --- a/class/class-mainwp-child-cache-purge.php +++ b/class/class-mainwp-child-cache-purge.php @@ -276,6 +276,7 @@ public function auto_purge_cache( $bulk = '' ) { // phpcs:ignore -- Current com break; case 'Pressable Cache Management': $information = $this->pressable_cache_management_auto_purge_cache(); + break; default: break; } From 67641c3ca028b1bf2844eb9158f45c74934da167 Mon Sep 17 00:00:00 2001 From: thanghv Date: Tue, 9 Apr 2024 18:56:14 +0700 Subject: [PATCH 8/9] Update readme --- class/class-mainwp-child.php | 2 +- mainwp-child.php | 2 +- readme.txt | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/class/class-mainwp-child.php b/class/class-mainwp-child.php index 2076a0e4..8d1c8404 100644 --- a/class/class-mainwp-child.php +++ b/class/class-mainwp-child.php @@ -33,7 +33,7 @@ class MainWP_Child { * * @var string MainWP Child plugin version. */ - public static $version = '5.0'; + public static $version = '5.0.1'; /** * Private variable containing the latest MainWP Child update version. diff --git a/mainwp-child.php b/mainwp-child.php index 854a8863..25e7243f 100644 --- a/mainwp-child.php +++ b/mainwp-child.php @@ -12,7 +12,7 @@ * Author: MainWP * Author URI: https://mainwp.com * Text Domain: mainwp-child - * Version: 5.0 + * Version: 5.0.1 * Requires at least: 5.4 * Requires PHP: 7.4 */ diff --git a/readme.txt b/readme.txt index 54b30ff1..3e32390e 100644 --- a/readme.txt +++ b/readme.txt @@ -7,7 +7,7 @@ Plugin URI: https://mainwp.com Requires at least: 6.2 Tested up to: 6.5 Requires PHP: 7.4 -Stable tag: 5.0 +Stable tag: 5.0.3 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -111,8 +111,12 @@ We have an extensive FAQ with more questions and answers [here](https://mainwp.c == Changelog == -= 5.0 - 2-27-2024 = -* Added: Support for the new API Backups providers - cPanel and Plesk -* Updated: Updated the phpSecLib library to enhance security and performance. += 5.0.1 - 4-9-2024 = +* Fixed: Post subcategories sharing the same name but belonging to different main categories are now correctly displayed. +* Fixed: Addressed a scenario where the MainWP Child plugin inadvertently triggered Core updates. +* Fixed: The detection of WP Optimize caching plugin in the Cache Control extension +* Fixed: Last purged time not being refreshed when clearing the Cache Control cache +* Fixed: Resolved a problem with invalid URL encountered when navigating back after submitting a White Label Support Form. +* Added: Introduced support for the AVIF image format in post and page creation processes. [See changelog for all versions.](https://mainwp.com/mainwp-child-changelog.txt) \ No newline at end of file From a3b65894bd065720d7457318aa2e5fdd558bfcd4 Mon Sep 17 00:00:00 2001 From: thanghv Date: Tue, 9 Apr 2024 21:32:02 +0700 Subject: [PATCH 9/9] Update readme --- readme.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 3e32390e..ee842787 100644 --- a/readme.txt +++ b/readme.txt @@ -7,7 +7,7 @@ Plugin URI: https://mainwp.com Requires at least: 6.2 Tested up to: 6.5 Requires PHP: 7.4 -Stable tag: 5.0.3 +Stable tag: 5.0.1 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -118,5 +118,8 @@ We have an extensive FAQ with more questions and answers [here](https://mainwp.c * Fixed: Last purged time not being refreshed when clearing the Cache Control cache * Fixed: Resolved a problem with invalid URL encountered when navigating back after submitting a White Label Support Form. * Added: Introduced support for the AVIF image format in post and page creation processes. +* Added: We’ve expanded support for Cache Control extension to include Pressable Cache Management and add the changelog video link the same as in dashboard + +[See Video Changelog](https://www.youtube.com/watch?v=5idFDPrgFf8) [See changelog for all versions.](https://mainwp.com/mainwp-child-changelog.txt) \ No newline at end of file