From cb60afea0d9ed45f04e8aa8823b4623e04a76383 Mon Sep 17 00:00:00 2001 From: thanghv Date: Wed, 20 May 2020 20:15:29 +0700 Subject: [PATCH] Refactoring --- class/class-mainwp-child-back-up-buddy.php | 13 +- .../class-mainwp-child-back-up-wordpress.php | 14 +- class/class-mainwp-child-back-wp-up.php | 38 +++--- class/class-mainwp-child-branding.php | 4 +- class/class-mainwp-child-callable.php | 66 +++++----- class/class-mainwp-child-install.php | 121 ++++++++++-------- class/class-mainwp-child-ithemes-security.php | 6 +- class/class-mainwp-child-links-checker.php | 8 +- class/class-mainwp-child-pagespeed.php | 6 +- class/class-mainwp-child-posts.php | 20 +-- class/class-mainwp-child-skeleton-key.php | 4 +- class/class-mainwp-child-staging.php | 9 +- class/class-mainwp-child-stats.php | 10 +- class/class-mainwp-child-timecapsule.php | 17 ++- class/class-mainwp-child-updates.php | 6 +- ...lass-mainwp-child-updraft-plus-backups.php | 12 +- class/class-mainwp-child-users.php | 10 +- ...ass-mainwp-child-vulnerability-checker.php | 2 +- .../class-mainwp-child-woocommerce-status.php | 7 +- class/class-mainwp-child-wordfence.php | 13 +- class/class-mainwp-child-wp-rocket.php | 8 +- ...ass-mainwp-child-wpvivid-backuprestore.php | 7 +- class/class-mainwp-child.php | 93 -------------- class/class-mainwp-client-report.php | 6 +- class/class-mainwp-clone-install.php | 6 +- class/class-mainwp-connect.php | 47 +++++-- class/class-mainwp-helper.php | 100 +-------------- class/class-mainwp-keyword-links.php | 2 +- class/class-mainwp-utility.php | 90 +++++++++++-- class/class-mainwp-wordpress-seo.php | 8 +- 30 files changed, 351 insertions(+), 402 deletions(-) diff --git a/class/class-mainwp-child-back-up-buddy.php b/class/class-mainwp-child-back-up-buddy.php index 1f55fb0..1b58ecc 100644 --- a/class/class-mainwp-child-back-up-buddy.php +++ b/class/class-mainwp-child-back-up-buddy.php @@ -12,6 +12,7 @@ * Extension URL: https://mainwp.com/extension/mainwpbuddy/ */ +use MainWP\Child\MainWP_Helper; // phpcs:disable -- third party credit. class MainWP_Child_Back_Up_Buddy { @@ -60,7 +61,7 @@ class MainWP_Child_Back_Up_Buddy { return $value; } - if ( ! MainWP_Helper::is_screen_with_update() ) { + if ( ! MainWP_Helper::is_updates_screen() ) { return $value; } @@ -216,7 +217,7 @@ class MainWP_Child_Back_Up_Buddy { public function action() { $information = array(); if ( ! $this->is_backupbuddy_installed ) { - mainwp_child_helper()->write( array( 'error' => __( 'Please install the BackupBuddy plugin on the child site.', $this->plugin_translate ) ) ); + MainWP_Helper::write( array( 'error' => __( 'Please install the BackupBuddy plugin on the child site.', $this->plugin_translate ) ) ); } if ( ! class_exists( 'backupbuddy_core' ) ) { @@ -369,7 +370,7 @@ class MainWP_Child_Back_Up_Buddy { break; } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -791,7 +792,7 @@ class MainWP_Child_Back_Up_Buddy { $time = $this->localize_time( $finish_time ); $data['lastBackupStats'] = date( 'M j - g:i A', $time ); // phpcs:ignore -- local time. $data['lasttime_backup'] = $finish_time; - mainwp_child_helper()->update_lasttime_backup( 'backupbuddy', $finish_time ); // support Require Backup Before Update feature. + MainWP_Helper::instance()->update_lasttime_backup( 'backupbuddy', $finish_time ); // support Require Backup Before Update feature. } else { $data['lastBackupStats'] = 'Unknown'; } @@ -1264,7 +1265,7 @@ class MainWP_Child_Back_Up_Buddy { // Calculate main row string. if ( 'default' == $type ) { // Default backup listing. - $download_url = '/wp-admin/admin-ajax.php?action=mainwp_backupbuddy_download_archive&backupbuddy_backup=' . basename( $file ) . '&_wpnonce=' . mainwp_child_helper()->create_nonce_without_session( 'mainwp_download_backup' ); + $download_url = '/wp-admin/admin-ajax.php?action=mainwp_backupbuddy_download_archive&backupbuddy_backup=' . basename( $file ) . '&_wpnonce=' . MainWP_Helper::instance()->create_nonce_without_session( 'mainwp_download_backup' ); $main_string = '' . $modified . ' (' . $time_ago . ')'; } elseif ( 'migrate' == $type ) { // Migration backup listing. $main_string = '' . $modified . ' (' . $time_ago . ')'; @@ -1760,7 +1761,7 @@ class MainWP_Child_Back_Up_Buddy { die( '-1' ); } - if ( ! mainwp_child_helper()->verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) { + if ( ! MainWP_Helper::instance()->verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) { die( '-2' ); } diff --git a/class/class-mainwp-child-back-up-wordpress.php b/class/class-mainwp-child-back-up-wordpress.php index 702d15b..07ae51c 100644 --- a/class/class-mainwp-child-back-up-wordpress.php +++ b/class/class-mainwp-child-back-up-wordpress.php @@ -13,6 +13,8 @@ * Extension URL: https://mainwp.com/extension/backupwordpress/ */ +use MainWP\Child\MainWP_Helper; + // phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code. class MainWP_Child_Back_Up_WordPress { @@ -65,7 +67,7 @@ class MainWP_Child_Back_Up_WordPress { return $value; } - if ( ! MainWP_Helper::is_screen_with_update() ) { + if ( ! MainWP_Helper::is_updates_screen() ) { return $value; } if ( isset( $value->response['backupwordpress/backupwordpress.php'] ) ) { @@ -79,7 +81,7 @@ class MainWP_Child_Back_Up_WordPress { $information = array(); if ( ! self::is_activated() ) { $information['error'] = 'NO_BACKUPWORDPRESS'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } if ( isset( $_POST['mwp_action'] ) ) { switch ( $_POST['mwp_action'] ) { @@ -127,7 +129,7 @@ class MainWP_Child_Back_Up_WordPress { break; } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -135,13 +137,13 @@ class MainWP_Child_Back_Up_WordPress { $schedule_id = ( isset( $_POST['schedule_id'] ) && ! empty( $_POST['schedule_id'] ) ) ? $_POST['schedule_id'] : ''; if ( empty( $schedule_id ) ) { $information = array( 'error' => 'Empty schedule id' ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } else { $schedule_id = sanitize_text_field( rawurldecode( $schedule_id ) ); HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); if ( ! HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) { $information = array( 'result' => 'NOTFOUND' ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } } @@ -225,7 +227,7 @@ class MainWP_Child_Back_Up_WordPress { $date = filemtime( $file ); if ( ! empty( $date ) ) { do_action( 'mainwp_reports_backupwordpress_backup', $destination, $message, 'finished', $backup_type, $date ); - mainwp_child_helper()->update_lasttime_backup( 'backupwordpress', $date ); // to support backup before update feature. + MainWP_Helper::instance()->update_lasttime_backup( 'backupwordpress', $date ); // to support backup before update feature. } } } diff --git a/class/class-mainwp-child-back-wp-up.php b/class/class-mainwp-child-back-wp-up.php index f91fd45..9edd1aa 100644 --- a/class/class-mainwp-child-back-wp-up.php +++ b/class/class-mainwp-child-back-wp-up.php @@ -15,6 +15,8 @@ // phpcs:disable -- third party credit. +use MainWP\Child\MainWP_Helper; + if ( ! defined( 'MAINWP_BACKWPUP_DEVELOPMENT' ) ) { define( 'MAINWP_BACKWPUP_DEVELOPMENT', false ); } @@ -77,21 +79,21 @@ class MainWP_Child_Back_WP_Up { $file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/pro/class-pro.php'; } - mainwp_child_helper()->check_files_exists( array( $file_path1, $file_path2 ) ); + MainWP_Helper::instance()->check_files_exists( array( $file_path1, $file_path2 ) ); require_once $file_path1; require_once $file_path2; $this->is_backwpup_installed = true; $this->is_backwpup_pro = true; } elseif ( is_plugin_active( 'backwpup/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ) ) { $file_path = plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php'; - mainwp_child_helper()->check_files_exists( array( $file_path ) ); + MainWP_Helper::instance()->check_files_exists( array( $file_path ) ); require_once $file_path; $this->is_backwpup_installed = true; } if ( $this->is_backwpup_installed ) { - mainwp_child_helper()->check_classes_exists( '\BackWPup' ); - mainwp_child_helper()->check_methods( 'get_instance' ); + MainWP_Helper::instance()->check_classes_exists( '\BackWPup' ); + MainWP_Helper::instance()->check_methods( 'get_instance' ); \BackWPup::get_instance(); add_action( 'admin_init', array( $this, 'init_download_backup' ) ); @@ -104,7 +106,7 @@ class MainWP_Child_Back_WP_Up { public function action() { if ( ! $this->is_backwpup_installed ) { - mainwp_child_helper()->write( array( 'error' => __( 'Please install BackWPup plugin on child website', 'mainwp-child' ) ) ); + MainWP_Helper::write( array( 'error' => __( 'Please install BackWPup plugin on child website', 'mainwp-child' ) ) ); return; } @@ -112,11 +114,11 @@ class MainWP_Child_Back_WP_Up { $error = error_get_last(); $info = self::$information; if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) { - mainwp_child_helper()->write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); + MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); } elseif ( ! empty( $info ) ) { - mainwp_child_helper()->write( self::$information ); + MainWP_Helper::write( self::$information ); } else { - mainwp_child_helper()->write( array( 'error' => 'Missing information array inside fatal_error' ) ); + MainWP_Helper::write( array( 'error' => 'Missing information array inside fatal_error' ) ); } } @@ -242,11 +244,11 @@ class MainWP_Child_Back_WP_Up { try { - mainwp_child_helper()->check_classes_exists( array( '\BackWPup_File', '\BackWPup_Job' ) ); - mainwp_child_helper()->check_methods( '\BackWPup_File', array( 'get_absolute_path' ) ); - mainwp_child_helper()->check_methods( '\BackWPup_Job', array( 'read_logheader' ) ); + MainWP_Helper::instance()->check_classes_exists( array( '\BackWPup_File', '\BackWPup_Job' ) ); + MainWP_Helper::instance()->check_methods( '\BackWPup_File', array( 'get_absolute_path' ) ); + MainWP_Helper::instance()->check_methods( '\BackWPup_Job', array( 'read_logheader' ) ); - $lasttime_logged = mainwp_child_helper()->get_lasttime_backup( 'backwpup' ); + $lasttime_logged = MainWP_Helper::instance()->get_lasttime_backup( 'backwpup' ); $log_folder = get_site_option( 'backwpup_cfg_logfolder' ); $log_folder = \BackWPup_File::get_absolute_path( $log_folder ); @@ -317,7 +319,7 @@ class MainWP_Child_Back_WP_Up { } if ( $new_lasttime_logged > $lasttime_logged ) { - mainwp_child_helper()->update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature. + MainWP_Helper::instance()->update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature. } } } catch ( \Exception $ex ) { @@ -328,7 +330,7 @@ class MainWP_Child_Back_WP_Up { public function sync_others_data( $information, $data = array() ) { if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) { try { - $lastbackup = mainwp_child_helper()->get_lasttime_backup( 'backwpup' ); + $lastbackup = MainWP_Helper::instance()->get_lasttime_backup( 'backwpup' ); $information['syncBackwpupData'] = array( 'lastbackup' => $lastbackup, ); @@ -340,9 +342,9 @@ class MainWP_Child_Back_WP_Up { } public function get_destinations_list() { - mainwp_child_helper()->check_classes_exists( array( '\BackWPup', '\BackWPup_Option' ) ); - mainwp_child_helper()->check_methods( '\BackWPup', array( 'get_registered_destinations', 'get_destination' ) ); - mainwp_child_helper()->check_methods( '\BackWPup_Option', array( 'get_job_ids', 'get' ) ); + MainWP_Helper::instance()->check_classes_exists( array( '\BackWPup', '\BackWPup_Option' ) ); + MainWP_Helper::instance()->check_methods( '\BackWPup', array( 'get_registered_destinations', 'get_destination' ) ); + MainWP_Helper::instance()->check_methods( '\BackWPup_Option', array( 'get_job_ids', 'get' ) ); $jobdest = array(); $jobids = \BackWPup_Option::get_job_ids(); @@ -401,7 +403,7 @@ class MainWP_Child_Back_WP_Up { $hide = isset( $_POST['show_hide'] ) && ( '1' === $_POST['show_hide'] ) ? 'hide' : ''; - mainwp_child_helper()->update_option( 'mainwp_backwpup_hide_plugin', $hide, 'yes' ); + MainWP_Helper::instance()->update_option( 'mainwp_backwpup_hide_plugin', $hide, 'yes' ); return array( 'success' => 1 ); } diff --git a/class/class-mainwp-child-branding.php b/class/class-mainwp-child-branding.php index aa4ac5d..b08e9dc 100644 --- a/class/class-mainwp-child-branding.php +++ b/class/class-mainwp-child-branding.php @@ -124,7 +124,7 @@ class MainWP_Child_Branding { $information = $this->update_branding(); break; } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function update_branding() { @@ -1121,7 +1121,7 @@ class MainWP_Child_Branding { return $value; } - if ( ! MainWP_Helper::is_screen_with_update() ) { + if ( ! MainWP_Helper::is_updates_screen() ) { return $value; } diff --git a/class/class-mainwp-child-callable.php b/class/class-mainwp-child-callable.php index a361d5a..1922bc6 100644 --- a/class/class-mainwp-child-callable.php +++ b/class/class-mainwp-child-callable.php @@ -191,7 +191,7 @@ class MainWP_Child_Callable { ) ); } - mainwp_child_helper()->write( $ids ); + MainWP_Helper::write( $ids ); } public function theme_action() { @@ -250,12 +250,12 @@ class MainWP_Child_Callable { $maint_options = $_POST['options']; if ( ! is_array( $maint_options ) ) { - mainwp_child_helper()->write( array( 'status' => 'FAIL' ) ); // exit. + MainWP_Helper::write( array( 'status' => 'FAIL' ) ); // exit. } $max_revisions = isset( $_POST['revisions'] ) ? intval( $_POST['revisions'] ) : 0; $information = $this->maintenance_db( $maint_options, $max_revisions ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } private function maintenance_db( $maint_options, $max_revisions ) { @@ -387,17 +387,17 @@ class MainWP_Child_Callable { delete_option( 'mainwp_maintenance_opt_alert_404_email' ); } $information['result'] = 'SUCCESS'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); return; } elseif ( 'clear_settings' === $action ) { delete_option( 'mainwp_maintenance_opt_alert_404' ); delete_option( 'mainwp_maintenance_opt_alert_404_email' ); $information['result'] = 'SUCCESS'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function new_post() { @@ -424,7 +424,7 @@ class MainWP_Child_Callable { $information['site_url'] = get_option( 'site_url' ); $information['home'] = get_option( 'home' ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function backup_poll() { @@ -449,10 +449,10 @@ class MainWP_Child_Callable { } } if ( false === $archiveFile ) { - mainwp_child_helper()->write( array() ); + MainWP_Helper::write( array() ); } - mainwp_child_helper()->write( array( 'size' => filesize( $archiveFile ) ) ); + MainWP_Helper::write( array( 'size' => filesize( $archiveFile ) ) ); } else { $backupFile = 'dbBackup-' . $fileNameUID . '-*.sql'; @@ -460,14 +460,14 @@ class MainWP_Child_Callable { $backupdir = $dirs[0]; $result = glob( $backupdir . $backupFile . '*' ); if ( 0 === count( $result ) ) { - mainwp_child_helper()->write( array() ); + MainWP_Helper::write( array() ); } $size = 0; foreach ( $result as $f ) { $size += filesize( $f ); } - mainwp_child_helper()->write( array( 'size' => $size ) ); + MainWP_Helper::write( array( 'size' => $size ) ); exit(); } } @@ -518,7 +518,7 @@ class MainWP_Child_Callable { $information['status'] = 'invalid'; } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function backup( $pWrite = true ) { @@ -580,7 +580,7 @@ class MainWP_Child_Callable { } if ( $pWrite ) { - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } return $information; @@ -717,7 +717,7 @@ class MainWP_Child_Callable { if ( ! empty( $url ) ) { $information['faviIconUrl'] = $url; } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function get_favicon( $parse_page = false ) { @@ -808,7 +808,7 @@ class MainWP_Child_Callable { $information['admin'] = ( MainWP_Security::admin_user_ok() ? 'Y' : 'N' ); $information['readme'] = ( MainWP_Security::remove_readme_ok() ? 'Y' : 'N' ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -886,7 +886,7 @@ class MainWP_Child_Callable { if ( $sync ) { $information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false ); } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function do_security_un_fix() { @@ -941,7 +941,7 @@ class MainWP_Child_Callable { $information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false ); } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function settings_tools() { @@ -949,7 +949,7 @@ class MainWP_Child_Callable { switch ( $_POST['action'] ) { case 'force_destroy_sessions': if ( 0 === get_current_user_id() ) { - mainwp_child_helper()->write( array( 'error' => __( 'Cannot get user_id', 'mainwp-child' ) ) ); + MainWP_Helper::write( array( 'error' => __( 'Cannot get user_id', 'mainwp-child' ) ) ); } wp_destroy_all_sessions(); @@ -957,17 +957,17 @@ class MainWP_Child_Callable { $sessions = wp_get_all_sessions(); if ( empty( $sessions ) ) { - mainwp_child_helper()->write( array( 'success' => 1 ) ); + MainWP_Helper::write( array( 'success' => 1 ) ); } else { - mainwp_child_helper()->write( array( 'error' => __( 'Cannot destroy sessions', 'mainwp-child' ) ) ); + MainWP_Helper::write( array( 'error' => __( 'Cannot destroy sessions', 'mainwp-child' ) ) ); } break; default: - mainwp_child_helper()->write( array( 'error' => __( 'Invalid action', 'mainwp-child' ) ) ); + MainWP_Helper::write( array( 'error' => __( 'Invalid action', 'mainwp-child' ) ) ); } } else { - mainwp_child_helper()->write( array( 'error' => __( 'Missing action', 'mainwp-child' ) ) ); + MainWP_Helper::write( array( 'error' => __( 'Missing action', 'mainwp-child' ) ) ); } } @@ -999,7 +999,7 @@ class MainWP_Child_Callable { $post = $_POST; $information = array(); $information = apply_filters( 'mainwp_child_extra_execution', $information, $post ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -1010,7 +1010,7 @@ class MainWP_Child_Callable { $information = array(); if ( empty( $file_url ) || empty( $path ) ) { - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); return; } @@ -1032,7 +1032,7 @@ class MainWP_Child_Callable { if ( ! file_exists( $dir ) ) { if ( false === mkdir( $dir, 0777, true ) ) { $information['error'] = 'ERRORCREATEDIR'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); return; } @@ -1046,7 +1046,7 @@ class MainWP_Child_Callable { } catch ( \Exception $e ) { $information['error'] = $e->getMessage(); } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -1131,7 +1131,7 @@ class MainWP_Child_Callable { public function backup_wp() { if ( ! version_compare( phpversion(), '5.3', '>=' ) ) { $error = sprintf( __( 'PHP Version %s is unsupported.', 'mainwp-child' ), phpversion() ); - mainwp_child_helper()->write( array( 'error' => $error ) ); + MainWP_Helper::write( array( 'error' => $error ) ); } \MainWP_Child_Back_Up_WordPress::instance()->action(); } @@ -1155,14 +1155,14 @@ class MainWP_Child_Callable { unlink( $backupdir . $file ); } - mainwp_child_helper()->write( array( 'result' => 'ok' ) ); + MainWP_Helper::write( array( 'result' => 'ok' ) ); } public function update_child_values() { $uniId = isset( $_POST['uniqueId'] ) ? $_POST['uniqueId'] : ''; MainWP_Helper::update_option( 'mainwp_child_uniqueId', $uniId ); - mainwp_child_helper()->write( array( 'result' => 'ok' ) ); + MainWP_Helper::write( array( 'result' => 'ok' ) ); } @@ -1189,7 +1189,7 @@ class MainWP_Child_Callable { if ( 'run_snippet' === $action || 'save_snippet' === $action ) { if ( ! isset( $_POST['code'] ) ) { - mainwp_child_helper()->write( array( 'status' => 'FAIL' ) ); + MainWP_Helper::write( array( 'status' => 'FAIL' ) ); } } @@ -1208,7 +1208,7 @@ class MainWP_Child_Callable { $information = array( 'status' => 'FAIL' ); } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } private function snippet_save_snippet( $slug, $type, $code, $snippets ) { @@ -1275,7 +1275,7 @@ class MainWP_Child_Callable { public function disconnect() { global $mainWPChild; $mainWPChild->deactivation( false ); - mainwp_child_helper()->write( array( 'result' => 'success' ) ); + MainWP_Helper::write( array( 'result' => 'success' ) ); } @@ -1289,7 +1289,7 @@ class MainWP_Child_Callable { MainWP_Helper::error( 'Plugin still active' ); } $information['deactivated'] = true; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } } diff --git a/class/class-mainwp-child-install.php b/class/class-mainwp-child-install.php index f715e39..5fd8cc4 100644 --- a/class/class-mainwp-child-install.php +++ b/class/class-mainwp-child-install.php @@ -95,7 +95,7 @@ class MainWP_Child_Install { $information['status'] = 'SUCCESS'; } $information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } private function delete_plugins( $plugins ) { @@ -177,7 +177,7 @@ class MainWP_Child_Install { $themeToDelete = current( $themes ); if ( $themeToDelete == $theme_name ) { $information['error'] = 'IsActivatedTheme'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); return; } } @@ -206,7 +206,7 @@ class MainWP_Child_Install { } $information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -222,13 +222,8 @@ class MainWP_Child_Install { if ( ! isset( $_POST['type'] ) || ! isset( $_POST['url'] ) || ( 'plugin' !== $_POST['type'] && 'theme' !== $_POST['type'] ) || '' === $_POST['url'] ) { MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); } - if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/screen.php'; - } - include_once ABSPATH . '/wp-admin/includes/template.php'; - include_once ABSPATH . '/wp-admin/includes/misc.php'; - include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; - include_once ABSPATH . '/wp-admin/includes/plugin.php'; + + $this->require_files(); $urlgot = json_decode( stripslashes( $_POST['url'] ) ); @@ -263,7 +258,7 @@ class MainWP_Child_Install { if ( is_wp_error( $result ) ) { if ( true == $ssl_verify && strpos( $url, 'https://' ) === 0 ) { $ssl_verify = false; - $result = $this->try_install_one_more( $url, $installer ); + $result = $this->try_second_install( $url, $installer ); } } @@ -271,56 +266,70 @@ class MainWP_Child_Install { if ( false == $ssl_verify ) { remove_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'no_ssl_filter_function' ), 99 ); } - - $args = array( - 'success' => 1, - 'action' => 'install', - ); - if ( 'plugin' === $_POST['type'] ) { - $path = $result['destination']; - $fileName = ''; - wp_cache_set( 'plugins', array(), 'plugins' ); - foreach ( $result['source_files'] as $srcFile ) { - if ( is_dir( $path . $srcFile ) ) { - continue; - } - $thePlugin = get_plugin_data( $path . $srcFile ); - if ( null !== $thePlugin && '' !== $thePlugin && '' !== $thePlugin['Name'] ) { - $args['type'] = 'plugin'; - $args['Name'] = $thePlugin['Name']; - $args['Version'] = $thePlugin['Version']; - $args['slug'] = $result['destination_name'] . '/' . $srcFile; - $fileName = $srcFile; - break; - } - } - - if ( ! empty( $fileName ) ) { - do_action_deprecated( 'mainwp_child_installPluginTheme', array( $args ), '4.0.7.1', 'mainwp_child_install_plugin_theme' ); - do_action( 'mainwp_child_install_plugin_theme', $args ); - - if ( isset( $_POST['activatePlugin'] ) && 'yes' === $_POST['activatePlugin'] ) { - // to fix activate issue. - if ( 'quotes-collection/quotes-collection.php' == $args['slug'] ) { - activate_plugin( $path . $fileName, '', false, true ); - } else { - activate_plugin( $path . $fileName, '' ); - } - } - } - } else { - $args['type'] = 'theme'; - $args['slug'] = $result['destination_name']; - do_action_deprecated( 'mainwp_child_installPluginTheme', array( $args ), '4.0.7.1', 'mainwp_child_install_plugin_theme' ); - do_action( 'mainwp_child_install_plugin_theme', $args ); - } + $this->after_installed( $result ); } + $information['installation'] = 'SUCCESS'; $information['destination_name'] = $result['destination_name']; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); + } + + private function require_files() { + if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { + include_once ABSPATH . '/wp-admin/includes/screen.php'; + } + include_once ABSPATH . '/wp-admin/includes/template.php'; + include_once ABSPATH . '/wp-admin/includes/misc.php'; + include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; + include_once ABSPATH . '/wp-admin/includes/plugin.php'; } - private function try_install_one_more( $url, $installer ) { + private function after_installed( $result ) { + $args = array( + 'success' => 1, + 'action' => 'install', + ); + if ( 'plugin' === $_POST['type'] ) { + $path = $result['destination']; + $fileName = ''; + wp_cache_set( 'plugins', array(), 'plugins' ); + foreach ( $result['source_files'] as $srcFile ) { + if ( is_dir( $path . $srcFile ) ) { + continue; + } + $thePlugin = get_plugin_data( $path . $srcFile ); + if ( null !== $thePlugin && '' !== $thePlugin && '' !== $thePlugin['Name'] ) { + $args['type'] = 'plugin'; + $args['Name'] = $thePlugin['Name']; + $args['Version'] = $thePlugin['Version']; + $args['slug'] = $result['destination_name'] . '/' . $srcFile; + $fileName = $srcFile; + break; + } + } + + if ( ! empty( $fileName ) ) { + do_action_deprecated( 'mainwp_child_installPluginTheme', array( $args ), '4.0.7.1', 'mainwp_child_install_plugin_theme' ); + do_action( 'mainwp_child_install_plugin_theme', $args ); + + if ( isset( $_POST['activatePlugin'] ) && 'yes' === $_POST['activatePlugin'] ) { + // to fix activate issue. + if ( 'quotes-collection/quotes-collection.php' == $args['slug'] ) { + activate_plugin( $path . $fileName, '', false, true ); + } else { + activate_plugin( $path . $fileName, '' ); + } + } + } + } else { + $args['type'] = 'theme'; + $args['slug'] = $result['destination_name']; + do_action_deprecated( 'mainwp_child_installPluginTheme', array( $args ), '4.0.7.1', 'mainwp_child_install_plugin_theme' ); + do_action( 'mainwp_child_install_plugin_theme', $args ); + } + } + + private function try_second_install( $url, $installer ) { add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'no_ssl_filter_function' ), 99, 2 ); $result = $installer->run( array( diff --git a/class/class-mainwp-child-ithemes-security.php b/class/class-mainwp-child-ithemes-security.php index 979dc46..8214dfa 100644 --- a/class/class-mainwp-child-ithemes-security.php +++ b/class/class-mainwp-child-ithemes-security.php @@ -13,6 +13,8 @@ * Extension URL: https://mainwp.com/extension/ithemes-security/ */ +use MainWP\Child\MainWP_Helper; + // phpcs:disable -- third party credit code. class MainWP_Child_IThemes_Security { @@ -56,7 +58,7 @@ class MainWP_Child_IThemes_Security { $information = array(); if ( ! class_exists( 'ITSEC_Core' ) || ! class_exists( 'ITSEC_Modules' ) ) { $information['error'] = 'NO_ITHEME'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } global $mainwp_itsec_modules_path; @@ -118,7 +120,7 @@ class MainWP_Child_IThemes_Security { break; } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function set_showhide() { diff --git a/class/class-mainwp-child-links-checker.php b/class/class-mainwp-child-links-checker.php index 07e5f4f..1473312 100644 --- a/class/class-mainwp-child-links-checker.php +++ b/class/class-mainwp-child-links-checker.php @@ -9,6 +9,8 @@ * The code is used for the MainWP Broken Links Checker Extension (Retired Extension) */ +use MainWP\Child\MainWP_Helper; + // phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code. class MainWP_Child_Links_Checker { @@ -41,7 +43,7 @@ class MainWP_Child_Links_Checker { $information = array(); if ( ! defined( 'BLC_ACTIVE' ) || ! function_exists( 'blc_init' ) ) { $information['error'] = 'NO_BROKENLINKSCHECKER'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } blc_init(); @@ -78,9 +80,9 @@ class MainWP_Child_Links_Checker { break; } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } catch ( \Exception $e ) { - mainwp_child_helper()->write( array( 'error' => $e->getMessage() ) ); + MainWP_Helper::write( array( 'error' => $e->getMessage() ) ); } } diff --git a/class/class-mainwp-child-pagespeed.php b/class/class-mainwp-child-pagespeed.php index 9feafda..e271a97 100644 --- a/class/class-mainwp-child-pagespeed.php +++ b/class/class-mainwp-child-pagespeed.php @@ -12,6 +12,8 @@ * Extension URL: https://mainwp.com/extension/page-speed/ */ +use MainWP\Child\MainWP_Helper; + // phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code. class MainWP_Child_Pagespeed { @@ -46,7 +48,7 @@ class MainWP_Child_Pagespeed { $information = array(); if ( ! defined( 'GPI_DIRECTORY' ) ) { $information['error'] = 'Please install Google Pagespeed Insights plugin on child website'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } if ( isset( $_POST['mwp_action'] ) ) { @@ -65,7 +67,7 @@ class MainWP_Child_Pagespeed { break; } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function child_deactivation() { diff --git a/class/class-mainwp-child-posts.php b/class/class-mainwp-child-posts.php index a4fae1c..23f7011 100644 --- a/class/class-mainwp-child-posts.php +++ b/class/class-mainwp-child-posts.php @@ -255,7 +255,7 @@ class MainWP_Child_Posts { $rslt = $this->get_recent_posts( explode( ',', $_POST['status'] ), $maxPages, $type, $extra ); $this->posts_where_suffix = ''; - mainwp_child_helper()->write( $rslt ); + MainWP_Helper::write( $rslt ); } public function new_post() { @@ -288,7 +288,7 @@ class MainWP_Child_Posts { do_action( 'mainwp_child_after_newpost', $res ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function post_action() { @@ -364,7 +364,7 @@ class MainWP_Child_Posts { $information['status'] = 'SUCCESS'; } $information['my_post'] = $my_post; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function get_post_edit( $id ) { @@ -542,7 +542,7 @@ class MainWP_Child_Posts { if ( ! isset( $information['status'] ) ) { $information['status'] = 'SUCCESS'; } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function comment_bulk_action() { @@ -571,7 +571,7 @@ class MainWP_Child_Posts { } } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -618,7 +618,7 @@ class MainWP_Child_Posts { $rslt = $this->get_recent_comments( explode( ',', $_POST['status'] ), $maxComments ); $this->comments_and_clauses = ''; - mainwp_child_helper()->write( $rslt ); + MainWP_Helper::write( $rslt ); } public function get_recent_comments( $pAllowedStatuses, $pCount ) { @@ -666,10 +666,10 @@ class MainWP_Child_Posts { * * Runs before creating or updating a post via MainWP dashboard. * - * @param array $new_post – Post data array. - * @param array $post_custom – Post custom meta data. - * @param string $post_category – Post categories. - * @param string $post_tags – Post tags. + * @param array $new_post � Post data array. + * @param array $post_custom � Post custom meta data. + * @param string $post_category � Post categories. + * @param string $post_tags � Post tags. */ do_action( 'mainwp_before_post_update', $new_post, $post_custom, $post_category, $post_tags ); $edit_post_id = 0; diff --git a/class/class-mainwp-child-skeleton-key.php b/class/class-mainwp-child-skeleton-key.php index ccbc817..96a9cca 100644 --- a/class/class-mainwp-child-skeleton-key.php +++ b/class/class-mainwp-child-skeleton-key.php @@ -56,7 +56,7 @@ class MainWP_Child_Skeleton_Key { function mainwp_skeleton_key_handle_fatal_error() { $error = error_get_last(); if ( isset( $error['type'] ) && in_array( $error['type'], array( 1, 4, 16, 64, 256 ) ) && isset( $error['message'] ) ) { - mainwp_child_helper()->write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); + MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); } } @@ -73,7 +73,7 @@ class MainWP_Child_Skeleton_Key { $information = array( 'error' => 'Unknown action' ); } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); exit(); } diff --git a/class/class-mainwp-child-staging.php b/class/class-mainwp-child-staging.php index ae152c9..7f2a065 100644 --- a/class/class-mainwp-child-staging.php +++ b/class/class-mainwp-child-staging.php @@ -12,6 +12,9 @@ * Extension URL: https://mainwp.com/extension/staging/ */ +use MainWP\Child\MainWP_Child_Callable; +use MainWP\Child\MainWP_Helper; + // phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code. class MainWP_Child_Staging { @@ -76,7 +79,7 @@ class MainWP_Child_Staging { public function action() { // phpcs:ignore -- ignore complex method notice. if ( ! $this->is_plugin_installed ) { - mainwp_child_helper()->write( array( 'error' => __( 'Please install WP Staging plugin on child website', 'mainwp-child' ) ) ); + MainWP_Helper::write( array( 'error' => __( 'Please install WP Staging plugin on child website', 'mainwp-child' ) ) ); } if ( ! class_exists( 'WPStaging\WPStaging' ) ) { @@ -145,7 +148,7 @@ class MainWP_Child_Staging { break; } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function set_showhide() { @@ -412,7 +415,7 @@ class MainWP_Child_Staging { return $value; } - if ( ! MainWP_Helper::is_screen_with_update() ) { + if ( ! MainWP_Helper::is_updates_screen() ) { return $value; } diff --git a/class/class-mainwp-child-stats.php b/class/class-mainwp-child-stats.php index c71720f..85e39b5 100644 --- a/class/class-mainwp-child-stats.php +++ b/class/class-mainwp-child-stats.php @@ -52,7 +52,7 @@ class MainWP_Child_Stats { $information['version'] = MainWP_Child::$version; $information['wpversion'] = $wp_version; $information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -141,7 +141,7 @@ class MainWP_Child_Stats { if ( isset( $_POST['primaryBackup'] ) && ! empty( $_POST['primaryBackup'] ) ) { $primary_bk = $_POST['primaryBackup']; - $information['primaryLasttimeBackup'] = mainwp_child_helper()->get_lasttime_backup( $primary_bk ); + $information['primaryLasttimeBackup'] = MainWP_Helper::instance()->get_lasttime_backup( $primary_bk ); } $last_post = wp_get_recent_posts( array( 'numberposts' => absint( '1' ) ) ); @@ -175,7 +175,7 @@ class MainWP_Child_Stats { } if ( $exit ) { - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } return $information; @@ -656,7 +656,7 @@ class MainWP_Child_Stats { $filter = isset( $_POST['filter'] ) ? $_POST['filter'] : true; $rslt = $this->get_all_themes_int( $filter, $keyword, $status ); - mainwp_child_helper()->write( $rslt ); + MainWP_Helper::write( $rslt ); } public function get_all_themes_int( $filter, $keyword = '', $status = '' ) { @@ -697,7 +697,7 @@ class MainWP_Child_Stats { $filter = isset( $_POST['filter'] ) ? $_POST['filter'] : true; $rslt = $this->get_all_plugins_int( $filter, $keyword, $status ); - mainwp_child_helper()->write( $rslt ); + MainWP_Helper::write( $rslt ); } public function get_all_plugins_int( $filter, $keyword = '', $status = '' ) { diff --git a/class/class-mainwp-child-timecapsule.php b/class/class-mainwp-child-timecapsule.php index 8eb88d3..e6684f2 100644 --- a/class/class-mainwp-child-timecapsule.php +++ b/class/class-mainwp-child-timecapsule.php @@ -11,6 +11,9 @@ * Extension URL: https://mainwp.com/extension/time-capsule/ */ +use MainWP\Child\MainWP_Helper; +use MainWP\Child\MainWP_Child_DB; + // phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code. class MainWP_Child_Timecapsule { @@ -60,14 +63,14 @@ class MainWP_Child_Timecapsule { public function action() { // phpcs:ignore -- ignore complex method notice. if ( ! $this->is_plugin_installed ) { - mainwp_child_helper()->write( array( 'error' => 'Please install WP Time Capsule plugin on child website' ) ); + MainWP_Helper::write( array( 'error' => 'Please install WP Time Capsule plugin on child website' ) ); } try { $this->require_files(); } catch ( \Exception $e ) { $error = $e->getMessage(); - mainwp_child_helper()->write( array( 'error' => $error ) ); + MainWP_Helper::write( array( 'error' => $error ) ); } $information = array(); @@ -80,7 +83,7 @@ class MainWP_Child_Timecapsule { if ( isset( $_POST['mwp_action'] ) ) { if ( ( 'save_settings' == $_POST['mwp_action'] || 'get_staging_details_wptc' == $_POST['mwp_action'] || 'progress_wptc' == $_POST['mwp_action'] ) && ( ! $is_user_logged_in || ! $privileges_wptc ) ) { - mainwp_child_helper()->write( array( 'error' => 'You are not login to your WP Time Capsule account.' ) ); + MainWP_Helper::write( array( 'error' => 'You are not login to your WP Time Capsule account.' ) ); } switch ( $_POST['mwp_action'] ) { @@ -209,7 +212,7 @@ class MainWP_Child_Timecapsule { break; } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -699,11 +702,11 @@ class MainWP_Child_Timecapsule { $backup_time = $config->get_option( 'last_backup_time' ); if ( ! empty( $backup_time ) ) { - mainwp_child_helper()->update_lasttime_backup( 'wptimecapsule', $backup_time ); + MainWP_Helper::instance()->update_lasttime_backup( 'wptimecapsule', $backup_time ); } $last_time = time() - 24 * 7 * 2 * 60 * 60; - $lasttime_logged = mainwp_child_helper()->get_lasttime_backup( 'wptimecapsule' ); + $lasttime_logged = MainWP_Helper::instance()->get_lasttime_backup( 'wptimecapsule' ); if ( empty( $lasttime_logged ) ) { $last_time = time() - 24 * 7 * 8 * 60 * 60; } @@ -1264,7 +1267,7 @@ class MainWP_Child_Timecapsule { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } - if ( ! MainWP_Helper::is_screen_with_update() ) { + if ( ! MainWP_Helper::is_updates_screen() ) { return $value; } if ( isset( $value->response['wp-time-capsule/wp-time-capsule.php'] ) ) { diff --git a/class/class-mainwp-child-updates.php b/class/class-mainwp-child-updates.php index 5d08878..643a239 100644 --- a/class/class-mainwp-child-updates.php +++ b/class/class-mainwp-child-updates.php @@ -68,7 +68,7 @@ class MainWP_Child_Updates { } $information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } private function include_updates() { @@ -562,7 +562,7 @@ class MainWP_Child_Updates { remove_filter( 'pre_transient_update_core', $this->filterFunction, 99 ); } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } private function do_upgrade_wp( &$information ) { @@ -668,7 +668,7 @@ class MainWP_Child_Updates { $information['upgrades'] = array(); // to fix error message when translations updated. } $information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } } diff --git a/class/class-mainwp-child-updraft-plus-backups.php b/class/class-mainwp-child-updraft-plus-backups.php index 7cb1b4a..3541250 100644 --- a/class/class-mainwp-child-updraft-plus-backups.php +++ b/class/class-mainwp-child-updraft-plus-backups.php @@ -12,6 +12,8 @@ * Extension URL: https://mainwp.com/extension/updraftplus/ */ +use MainWP\Child\MainWP_Helper; + // phpcs:disable -- Third party credit. class MainWP_Child_Updraft_Plus_Backups { @@ -47,7 +49,7 @@ class MainWP_Child_Updraft_Plus_Backups { if ( isset( $last_backup['backup_time'] ) ) { $backup_time = $last_backup['backup_time']; if ( $last_backup['success'] ) { - mainwp_child_helper()->update_lasttime_backup( 'updraftplus', $backup_time ); + MainWP_Helper::instance()->update_lasttime_backup( 'updraftplus', $backup_time ); } } return $last_backup; @@ -81,7 +83,7 @@ class MainWP_Child_Updraft_Plus_Backups { $information = array(); if ( ! $this->is_plugin_installed ) { $information['error'] = 'NO_UPDRAFTPLUS'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } $this->required_files(); @@ -92,7 +94,7 @@ class MainWP_Child_Updraft_Plus_Backups { } if ( empty( $updraftplus ) ) { $information['error'] = 'Error empty updraftplus'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } if ( isset( $_POST['mwp_action'] ) ) { @@ -163,7 +165,7 @@ class MainWP_Child_Updraft_Plus_Backups { $information = array( 'error' => $e->getMessage() ); } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function set_showhide() { @@ -3567,7 +3569,7 @@ ENDHERE; if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } - if ( ! MainWP_Helper::is_screen_with_update() ) { + if ( ! MainWP_Helper::is_updates_screen() ) { return $value; } diff --git a/class/class-mainwp-child-users.php b/class/class-mainwp-child-users.php index 2b9228c..dda339b 100644 --- a/class/class-mainwp-child-users.php +++ b/class/class-mainwp-child-users.php @@ -86,7 +86,7 @@ class MainWP_Child_Users { $information['users'] = $this->get_all_users_int( 500 ); } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -147,7 +147,7 @@ class MainWP_Child_Users { if ( $return ) { return $allusers; } - mainwp_child_helper()->write( $allusers ); + MainWP_Helper::write( $allusers ); } @@ -210,7 +210,7 @@ class MainWP_Child_Users { } } - mainwp_child_helper()->write( $allusers ); + MainWP_Helper::write( $allusers ); } @@ -424,7 +424,7 @@ class MainWP_Child_Users { } $information['added'] = true; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function new_user() { @@ -462,7 +462,7 @@ class MainWP_Child_Users { wp_mail( $user_email, sprintf( __( '[%s] Your username and password' ), $blogname ), $message, '' ); } $information['added'] = true; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } diff --git a/class/class-mainwp-child-vulnerability-checker.php b/class/class-mainwp-child-vulnerability-checker.php index f166220..e54c249 100644 --- a/class/class-mainwp-child-vulnerability-checker.php +++ b/class/class-mainwp-child-vulnerability-checker.php @@ -44,7 +44,7 @@ class MainWP_Child_Vulnerability_Checker { } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function vulner_recheck() { diff --git a/class/class-mainwp-child-woocommerce-status.php b/class/class-mainwp-child-woocommerce-status.php index 0e7278d..dc757f4 100644 --- a/class/class-mainwp-child-woocommerce-status.php +++ b/class/class-mainwp-child-woocommerce-status.php @@ -11,6 +11,9 @@ * Extension URL: https://mainwp.com/extension/woocommerce-status/ */ +use MainWP\Child\MainWP_Helper; + + // phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code. class MainWP_Child_WooCommerce_Status { @@ -35,7 +38,7 @@ class MainWP_Child_WooCommerce_Status { $information = array(); if ( ! class_exists( 'WooCommerce' ) || ! defined( 'WC_VERSION' ) ) { $information['error'] = 'NO_WOOCOMMERCE'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } $is_ver220 = $this->is_version_220(); @@ -52,7 +55,7 @@ class MainWP_Child_WooCommerce_Status { break; } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function is_version_220() { diff --git a/class/class-mainwp-child-wordfence.php b/class/class-mainwp-child-wordfence.php index bdf3dd6..bae206a 100644 --- a/class/class-mainwp-child-wordfence.php +++ b/class/class-mainwp-child-wordfence.php @@ -11,6 +11,9 @@ * Extension URL: https://mainwp.com/extension/wordfence/ */ +use MainWP\Child\MainWP_Helper; +use MainWP\Child\MainWP_Child_DB; + // phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code. class MainWP_Child_Wordfence { @@ -204,13 +207,13 @@ class MainWP_Child_Wordfence { public function action() { // phpcs:ignore -- not quite complex method $information = array(); if ( ! $this->is_wordfence_installed ) { - mainwp_child_helper()->write( array( 'error' => __( 'Please install the Wordfence plugin on the child site.', $this->plugin_translate ) ) ); + MainWP_Helper::write( array( 'error' => __( 'Please install the Wordfence plugin on the child site.', $this->plugin_translate ) ) ); return; } if ( ! class_exists( 'wordfence' ) || ! class_exists( 'wfScanEngine' ) ) { $information['error'] = 'NO_WORDFENCE'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } if ( isset( $_POST['mwp_action'] ) ) { @@ -424,7 +427,7 @@ class MainWP_Child_Wordfence { break; } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } @@ -2129,7 +2132,7 @@ SQL 'code' => wfCache::getHtaccessCode(), ); } - $download_url = admin_url( 'admin-ajax.php' ) . '?action=mainwp_wordfence_download_htaccess&_wpnonce=' . mainwp_child_helper()->create_nonce_without_session( 'mainwp_download_htaccess' ); + $download_url = admin_url( 'admin-ajax.php' ) . '?action=mainwp_wordfence_download_htaccess&_wpnonce=' . MainWP_Helper::instance()->create_nonce_without_session( 'mainwp_download_htaccess' ); return array( 'ok' => 1, 'download_url' => $download_url, @@ -2157,7 +2160,7 @@ SQL die( '-1' ); } - if ( ! mainwp_child_helper()->verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_htaccess' ) ) { + if ( ! MainWP_Helper::instance()->verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_htaccess' ) ) { die( '-2' ); } diff --git a/class/class-mainwp-child-wp-rocket.php b/class/class-mainwp-child-wp-rocket.php index 40bd715..bb5f490 100644 --- a/class/class-mainwp-child-wp-rocket.php +++ b/class/class-mainwp-child-wp-rocket.php @@ -12,6 +12,8 @@ * Extension URL: https://mainwp.com/extension/rocket/ */ +use MainWP\Child\MainWP_Helper; + // phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code. class MainWP_Child_WP_Rocket { @@ -210,7 +212,7 @@ class MainWP_Child_WP_Rocket { return $value; } - if ( ! MainWP_Helper::is_screen_with_update() ) { + if ( ! MainWP_Helper::is_updates_screen() ) { return $value; } @@ -259,7 +261,7 @@ class MainWP_Child_WP_Rocket { public function action() { if ( ! $this->is_plugin_installed ) { - mainwp_child_helper()->write( array( 'error' => __( 'Please install WP Rocket plugin on child website', $this->plugin_translate ) ) ); + MainWP_Helper::write( array( 'error' => __( 'Please install WP Rocket plugin on child website', $this->plugin_translate ) ) ); return; } @@ -303,7 +305,7 @@ class MainWP_Child_WP_Rocket { $information = array( 'error' => $e->getMessage() ); } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function set_showhide() { diff --git a/class/class-mainwp-child-wpvivid-backuprestore.php b/class/class-mainwp-child-wpvivid-backuprestore.php index 76fc3a7..917a70d 100644 --- a/class/class-mainwp-child-wpvivid-backuprestore.php +++ b/class/class-mainwp-child-wpvivid-backuprestore.php @@ -1,5 +1,8 @@ is_plugin_installed ) { $information['error'] = 'NO_WPVIVIDBACKUP'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } if ( isset( $_POST['mwp_action'] ) ) { @@ -128,7 +131,7 @@ class MainWP_Child_WPvivid_BackupRestore { $information = array( 'error' => $e->getMessage() ); } - mainwp_child_helper()->write($information); + MainWP_Helper::write($information); } } diff --git a/class/class-mainwp-child.php b/class/class-mainwp-child.php index e1a4881..2247ea5 100644 --- a/class/class-mainwp-child.php +++ b/class/class-mainwp-child.php @@ -150,99 +150,6 @@ class MainWP_Child { return; } - if ( false === $update_version ) { - $options = array( - 'mainwp_child_legacy', - 'mainwp_child_auth', - 'mainwp_child_uniqueId', - 'mainwp_child_htaccess_set', - 'mainwp_child_fix_htaccess', - 'mainwp_child_pubkey', - 'mainwp_child_server', - 'mainwp_child_nonce', - 'mainwp_child_nossl', - 'mainwp_child_nossl_key', - 'mainwp_child_remove_wp_version', - 'mainwp_child_remove_rsd', - 'mainwp_child_remove_wlw', - 'mainwp_child_remove_core_updates', - 'mainwp_child_remove_plugin_updates', - 'mainwp_child_remove_theme_updates', - 'mainwp_child_remove_php_reporting', - 'mainwp_child_remove_scripts_version', - 'mainwp_child_remove_styles_version', - 'mainwp_child_remove_readme', - 'mainwp_child_clone_sites', - 'mainwp_child_pluginDir', - 'mainwp_premium_updates', - 'mainwp_child_activated_once', - 'mainwp_maintenance_opt_alert_404', - 'mainwp_maintenance_opt_alert_404_email', - 'mainwp_ext_code_snippets', - 'mainwp_ext_snippets_enabled', - 'mainwp_temp_clone_plugins', - 'mainwp_temp_clone_themes', - 'mainwp_child_click_data', - 'mainwp_child_clone_from_server_last_folder', - 'mainwp_child_clone_permalink', - 'mainwp_child_restore_permalink', - 'mainwp_keyword_links_htaccess_set', - 'mainwp_kwl_options', - 'mainwp_kwl_keyword_links', - 'mainwp_kwl_click_statistic_data', - 'mainwp_kwl_statistic_data_', - 'mainwp_kwl_enable_statistic', - 'mainwpKeywordLinks', - ); - foreach ( $options as $option ) { - MainWP_Helper::fix_option( $option ); - } - } elseif ( ( '1.0' === $update_version ) || ( '1.1' === $update_version ) ) { - $options = array( - 'mainwp_child_pubkey', - 'mainwp_child_update_version', - 'mainwp_child_auth', - 'mainwp_child_clone_permalink', - 'mainwp_child_restore_permalink', - 'mainwp_ext_snippets_enabled', - 'mainwp_child_fix_htaccess', - 'mainwp_child_pluginDir', - 'mainwp_child_htaccess_set', - 'mainwp_child_nossl', - 'mainwp_updraftplus_ext_enabled', - 'mainwpKeywordLinks', - 'mainwp_keyword_links_htaccess_set', - 'mainwp_pagespeed_ext_enabled', - 'mainwp_linkschecker_ext_enabled', - 'mainwp_maintenance_opt_alert_404', - ); - foreach ( $options as $option ) { - MainWP_Helper::fix_option( $option, 'yes' ); - } - - if ( ! is_array( get_option( 'mainwp_security' ) ) ) { - $securityOptions = array( - 'wp_version' => 'mainwp_child_remove_wp_version', - 'rsd' => 'mainwp_child_remove_rsd', - 'wlw' => 'mainwp_child_remove_wlw', - 'core_updates' => 'mainwp_child_remove_core_updates', - 'plugin_updates' => 'mainwp_child_remove_plugin_updates', - 'theme_updates' => 'mainwp_child_remove_theme_updates', - 'php_reporting' => 'mainwp_child_remove_php_reporting', - 'scripts_version' => 'mainwp_child_remove_scripts_version', - 'styles_version' => 'mainwp_child_remove_styles_version', - 'readme' => 'mainwp_child_remove_readme', - ); - - $security = array(); - foreach ( $securityOptions as $option => $old ) { - $value = get_option( $old ); - $security[ $option ] = ( 'T' === $value ); - } - MainWP_Helper::update_option( 'mainwp_security', $security, 'yes' ); - } - } - MainWP_Helper::update_option( 'mainwp_child_update_version', $this->update_version, 'yes' ); } diff --git a/class/class-mainwp-client-report.php b/class/class-mainwp-client-report.php index a5ef081..a88825b 100644 --- a/class/class-mainwp-client-report.php +++ b/class/class-mainwp-client-report.php @@ -70,7 +70,7 @@ class MainWP_Client_Report { if ( ! function_exists( 'wp_mainwp_stream_get_instance' ) ) { $information['error'] = __( 'No MainWP Child Reports plugin installed.', 'mainwp-child' ); - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } if ( isset( $_POST['mwp_action'] ) ) { @@ -89,7 +89,7 @@ class MainWP_Client_Report { break; } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function save_sucuri_stream() { @@ -958,7 +958,7 @@ class MainWP_Client_Report { return $value; } - if ( ! MainWP_Helper::is_screen_with_update() ) { + if ( ! MainWP_Helper::is_updates_screen() ) { return $value; } diff --git a/class/class-mainwp-clone-install.php b/class/class-mainwp-clone-install.php index da0ae90..73f5145 100644 --- a/class/class-mainwp-clone-install.php +++ b/class/class-mainwp-clone-install.php @@ -629,7 +629,7 @@ class MainWP_Clone_Install { } unlink( $result[0] ); - mainwp_child_helper()->write( array( 'result' => 'ok' ) ); + MainWP_Helper::write( array( 'result' => 'ok' ) ); } elseif ( 'createCloneBackupPoll' === $_POST['cloneFunc'] ) { $dirs = MainWP_Helper::get_mainwp_dir( 'backup' ); $backupdir = $dirs[0]; @@ -645,7 +645,7 @@ class MainWP_Clone_Install { return; } - mainwp_child_helper()->write( array( 'size' => filesize( $archiveFile ) ) ); + MainWP_Helper::write( array( 'size' => filesize( $archiveFile ) ) ); } elseif ( 'createCloneBackup' === $_POST['cloneFunc'] ) { $this->create_clone_backup(); } @@ -726,6 +726,6 @@ class MainWP_Clone_Install { } closedir( $fh ); $information['themes'] = $themes; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } } diff --git a/class/class-mainwp-connect.php b/class/class-mainwp-connect.php index 1b54d57..88c147f 100644 --- a/class/class-mainwp-connect.php +++ b/class/class-mainwp-connect.php @@ -206,14 +206,8 @@ class MainWP_Connect { } $signature = rawurldecode( isset( $_REQUEST['mainwpsignature'] ) ? $_REQUEST['mainwpsignature'] : '' ); - $file = ''; - if ( isset( $_REQUEST['f'] ) ) { - $file = $_REQUEST['f']; - } elseif ( isset( $_REQUEST['file'] ) ) { - $file = $_REQUEST['file']; - } elseif ( isset( $_REQUEST['fdl'] ) ) { - $file = $_REQUEST['fdl']; - } + + $file = $this->get_request_files(); $auth = self::instance()->auth( $signature, rawurldecode( ( isset( $_REQUEST['where'] ) ? $_REQUEST['where'] : $file ) ), isset( $_REQUEST['nonce'] ) ? $_REQUEST['nonce'] : '', isset( $_REQUEST['nossl'] ) ? $_REQUEST['nossl'] : 0 ); @@ -237,7 +231,23 @@ class MainWP_Connect { return; } } + } + $this->check_redirects(); + } + + private function get_request_files() { + $file = ''; + if ( isset( $_REQUEST['f'] ) ) { + $file = $_REQUEST['f']; + } elseif ( isset( $_REQUEST['file'] ) ) { + $file = $_REQUEST['file']; + } elseif ( isset( $_REQUEST['fdl'] ) ) { + $file = $_REQUEST['fdl']; } + return $file; + } + + private function check_redirects() { if ( isset( $_REQUEST['fdl'] ) ) { if ( stristr( $_REQUEST['fdl'], '..' ) ) { return; @@ -252,9 +262,9 @@ class MainWP_Connect { } $this->where_redirect(); } - + private function open_location_redirect( $open_location ) { - $_vars = MainWP_Helper::parse_query( $open_location ); + $_vars = self::parse_query( $open_location ); $_path = wp_parse_url( $open_location, PHP_URL_PATH ); if ( isset( $_vars['_mwpNoneName'] ) && isset( $_vars['_mwpNoneValue'] ) ) { $_vars[ $_vars['_mwpNoneName'] ] = wp_create_nonce( $_vars['_mwpNoneValue'] ); @@ -274,6 +284,23 @@ class MainWP_Connect { wp_safe_redirect( site_url() . $open_location ); exit(); } + + + public static function parse_query( $var ) { + + $var = wp_parse_url( $var, PHP_URL_QUERY ); + $var = html_entity_decode( $var ); + $var = explode( '&', $var ); + $arr = array(); + + foreach ( $var as $val ) { + $x = explode( '=', $val ); + $arr[ $x[0] ] = $x[1]; + } + unset( $val, $x, $var ); + + return $arr; + } private function where_redirect() { $where = isset( $_REQUEST['where'] ) ? $_REQUEST['where'] : ''; diff --git a/class/class-mainwp-helper.php b/class/class-mainwp-helper.php index 92e9e4d..67859a3 100644 --- a/class/class-mainwp-helper.php +++ b/class/class-mainwp-helper.php @@ -26,7 +26,7 @@ class MainWP_Helper { return self::$instance; } - public function write( $val ) { + public static function write( $val ) { if ( isset( $_REQUEST['json_result'] ) && true == $_REQUEST['json_result'] ) : $output = wp_json_encode( $val ); else : @@ -64,7 +64,7 @@ class MainWP_Helper { if ( null !== $code ) { $information['error_code'] = $code; } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } /** @@ -378,14 +378,6 @@ class MainWP_Helper { return $url; } - public static function clean( $string ) { - $string = trim( $string ); - $string = htmlentities( $string, ENT_QUOTES ); - $string = str_replace( "\n", '
', $string ); - $string = stripslashes( $string ); - return $string; - } - public static function end_session() { session_write_close(); ob_end_flush(); @@ -488,66 +480,6 @@ class MainWP_Helper { return date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $timestamp ); } - public static function format_email( $to, $body ) { - return '
-
-
-
-
-
- -
-
-

Hello MainWP User!

- ' . $body . ' -
-
-
MainWP
- -

-
- -
-
-

© 2013 MainWP. All Rights Reserved.

-
-
-
-
-
-





- - - - -
- - - - -
- This email is sent from your MainWP Dashboard. -
- If you do not wish to receive these notices please re-check your preferences in the MainWP Settings page. -
-
-
-
- -
-
-
-
'; - } - public static function update_option( $option_name, $option_value, $autoload = 'no' ) { $success = add_option( $option_name, $option_value, '', $autoload ); @@ -558,16 +490,6 @@ class MainWP_Helper { return $success; } - public static function fix_option( $option_name, $autoload = 'no' ) { - global $wpdb; - - if ( $autoload != $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option_name ) ) ) { - $option_value = get_option( $option_name ); - delete_option( $option_name ); - add_option( $option_name, $option_value, '', $autoload ); - } - } - public function update_lasttime_backup( $by, $time ) { $backup_by = array( 'backupbuddy', 'backupwordpress', 'backwpup', 'updraftplus', 'wptimecapsule' ); if ( ! in_array( $by, $backup_by ) ) { @@ -698,22 +620,6 @@ class MainWP_Helper { return preg_match( '/' . $pPrefix . '(.*).(zip|tar|tar.gz|tar.bz2)' . $pSuffix . '$/', $pFileName ); } - public static function parse_query( $var ) { - - $var = wp_parse_url( $var, PHP_URL_QUERY ); - $var = html_entity_decode( $var ); - $var = explode( '&', $var ); - $arr = array(); - - foreach ( $var as $val ) { - $x = explode( '=', $val ); - $arr[ $x[0] ] = $x[1]; - } - unset( $val, $x, $var ); - - return $arr; - } - public static function sanitize_filename( $filename ) { if ( ! function_exists( 'mb_ereg_replace' ) ) { return sanitize_file_name( $filename ); @@ -753,7 +659,7 @@ class MainWP_Helper { return function_exists( 'openssl_verify' ); } - public static function is_screen_with_update() { + public static function is_updates_screen() { if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { return false; diff --git a/class/class-mainwp-keyword-links.php b/class/class-mainwp-keyword-links.php index 203b357..2ec42ea 100644 --- a/class/class-mainwp-keyword-links.php +++ b/class/class-mainwp-keyword-links.php @@ -735,7 +735,7 @@ class MainWP_Keyword_Links { $result = $this->remove_keywords(); break; } - mainwp_child_helper()->write( $result ); + MainWP_Helper::write( $result ); } function remove_keywords() { diff --git a/class/class-mainwp-utility.php b/class/class-mainwp-utility.php index d82b3f4..92b1c3e 100644 --- a/class/class-mainwp-utility.php +++ b/class/class-mainwp-utility.php @@ -111,43 +111,43 @@ class MainWP_Utility { // referrer. if ( isset( $_SERVER['HTTP_REFERER'] ) ) { - $referer = MainWP_Helper::clean( $_SERVER['HTTP_REFERER'] ); + $referer = self::clean( $_SERVER['HTTP_REFERER'] ); } else { $referer = 'undefined'; } $protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( $_SERVER['HTTPS'], 'off' ) ? 'https://' : 'http://'; // request URI. if ( isset( $_SERVER['REQUEST_URI'] ) && isset( $_SERVER['HTTP_HOST'] ) ) { - $request = MainWP_Helper::clean( $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); + $request = self::clean( $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); } else { $request = 'undefined'; } // query string. if ( isset( $_SERVER['QUERY_STRING'] ) ) { - $string = MainWP_Helper::clean( $_SERVER['QUERY_STRING'] ); + $string = self::clean( $_SERVER['QUERY_STRING'] ); } else { $string = 'undefined'; } // IP address. if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { - $address = MainWP_Helper::clean( $_SERVER['REMOTE_ADDR'] ); + $address = self::clean( $_SERVER['REMOTE_ADDR'] ); } else { $address = 'undefined'; } // user agent. if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { - $agent = MainWP_Helper::clean( $_SERVER['HTTP_USER_AGENT'] ); + $agent = self::clean( $_SERVER['HTTP_USER_AGENT'] ); } else { $agent = 'undefined'; } // identity. if ( isset( $_SERVER['REMOTE_IDENT'] ) ) { - $remote = MainWP_Helper::clean( $_SERVER['REMOTE_IDENT'] ); + $remote = self::clean( $_SERVER['REMOTE_IDENT'] ); } else { $remote = 'undefined'; } // log time. - $time = MainWP_Helper::clean( date( 'F jS Y, h:ia', time() ) ); // phpcs:ignore -- local time. + $time = self::clean( date( 'F jS Y, h:ia', time() ) ); // phpcs:ignore -- local time. $mail = '
404 alert
' . '
TIME: ' . $time . '
' . @@ -161,14 +161,82 @@ class MainWP_Utility { wp_mail( $email, 'MainWP - 404 Alert: ' . $blog, - MainWP_Helper::format_email( $email, $mail ), + self::format_email( $email, $mail ), array( 'content-type: text/html', ) ); + } + + public static function clean( $string ) { + $string = trim( $string ); + $string = htmlentities( $string, ENT_QUOTES ); + $string = str_replace( "\n", '
', $string ); + $string = stripslashes( $string ); + return $string; + } + + public static function format_email( $to_email, $body ) { + return '
+
+
+
+
+
+ +
+
+

Hello MainWP User!

+ ' . $body . ' +
+
+
MainWP
+ +

+
+ +
+
+

© 2013 MainWP. All Rights Reserved.

+
+
+
+
+
+





+ + + + +
+ + + + +
+ This email is sent from your MainWP Dashboard. +
+ If you do not wish to receive these notices please re-check your preferences in the MainWP Settings page. +
+
+
+
+ +
+
+
+
'; } - + /** * Handle fatal error for requests from the dashboard * mwp_action requests @@ -181,7 +249,7 @@ class MainWP_Utility { // handle fatal errors and compile errors. $error = error_get_last(); if ( isset( $error['type'] ) && isset( $error['message'] ) && ( E_ERROR === $error['type'] || E_COMPILE_ERROR === $error['type'] ) ) { - mainwp_child_helper()->write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); + MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); } } @@ -384,7 +452,7 @@ class MainWP_Utility { } return $wpdb->get_results( $wpdb->prepare( "SELECT ID,guid FROM $wpdb->posts WHERE post_type = 'attachment' AND guid LIKE %s", '%/' . $wpdb->esc_like( $filename ) ) ); } - + public static function fetch_url( $url, $postdata ) { try { $tmpUrl = $url; diff --git a/class/class-mainwp-wordpress-seo.php b/class/class-mainwp-wordpress-seo.php index 7778851..f8e2f67 100644 --- a/class/class-mainwp-wordpress-seo.php +++ b/class/class-mainwp-wordpress-seo.php @@ -12,6 +12,8 @@ * Extension URL: https://mainwp.com/extension/wordpress-seo/ */ +use MainWP\Child\MainWP_Helper; + // phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code. class MainWP_WordPress_SEO { @@ -40,7 +42,7 @@ class MainWP_WordPress_SEO { public function action() { if ( ! class_exists( 'WPSEO_Admin' ) ) { $information['error'] = 'NO_WPSEO'; - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } $result = array(); switch ( $_POST['action'] ) { @@ -48,7 +50,7 @@ class MainWP_WordPress_SEO { $information = $this->import_settings(); break; } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function import_settings() { @@ -106,7 +108,7 @@ class MainWP_WordPress_SEO { } } - mainwp_child_helper()->write( $information ); + MainWP_Helper::write( $information ); } public function import_seo_settings( $file ) {