From 673fe6f808863ba982a5a468a69a4f49a75a09ae Mon Sep 17 00:00:00 2001 From: thanghv Date: Mon, 11 May 2020 20:30:56 +0700 Subject: [PATCH] Refactoring --- class/class-mainwp-child-branding.php | 6 +- class/class-mainwp-child-install.php | 161 ++++ class/class-mainwp-child-plugins-check.php | 40 +- class/class-mainwp-child-skeleton-key.php | 3 +- class/class-mainwp-child-updates.php | 754 +++++++++++++++++++ class/class-mainwp-child.php | 807 +-------------------- class/class-mainwp-helper.php | 49 +- class/class-mainwp-security.php | 35 + class/class-mainwp-wordpress-seo.php | 6 +- 9 files changed, 1036 insertions(+), 825 deletions(-) create mode 100644 class/class-mainwp-child-install.php create mode 100644 class/class-mainwp-child-updates.php diff --git a/class/class-mainwp-child-branding.php b/class/class-mainwp-child-branding.php index 6548e00..752b6f4 100644 --- a/class/class-mainwp-child-branding.php +++ b/class/class-mainwp-child-branding.php @@ -315,10 +315,10 @@ class MainWP_Child_Branding { public static function upload_image( $img_url ) { include_once ABSPATH . 'wp-admin/includes/file.php'; - global $mainWPChild; - add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); + + add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 ); $temporary_file = download_url( $img_url ); - remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); + remove_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 ); if ( is_wp_error( $temporary_file ) ) { throw new \Exception( $temporary_file->get_error_message() ); diff --git a/class/class-mainwp-child-install.php b/class/class-mainwp-child-install.php new file mode 100644 index 0000000..f79a678 --- /dev/null +++ b/class/class-mainwp-child-install.php @@ -0,0 +1,161 @@ +run( + array( + 'package' => $url, + 'destination' => ( 'plugin' === $_POST['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ), + 'clear_destination' => ( isset( $_POST['overwrite'] ) && $_POST['overwrite'] ), + 'clear_working' => true, + 'hook_extra' => array(), + ) + ); + + if ( is_wp_error( $result ) ) { + if ( true == $ssl_verify && strpos( $url, 'https://' ) === 0 ) { + add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'no_ssl_filter_function' ), 99, 2 ); + $ssl_verify = false; + $result = $installer->run( + array( + 'package' => $url, + 'destination' => ( 'plugin' === $_POST['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ), + 'clear_destination' => ( isset( $_POST['overwrite'] ) && $_POST['overwrite'] ), + 'clear_working' => true, + 'hook_extra' => array(), + ) + ); + } + + if ( is_wp_error( $result ) ) { + $err_code = $result->get_error_code(); + if ( $result->get_error_data() && is_string( $result->get_error_data() ) ) { + $error = $result->get_error_data(); + MainWP_Helper::error( $error, $err_code ); + } else { + MainWP_Helper::error( implode( ', ', $error ), $err_code ); + } + } + } + + remove_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 ); + 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 = ''; + $rslt = null; + 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 ); + } + } + $information['installation'] = 'SUCCESS'; + $information['destination_name'] = $result['destination_name']; + mainwp_child_helper()->write( $information ); + } + +} diff --git a/class/class-mainwp-child-plugins-check.php b/class/class-mainwp-child-plugins-check.php index 3479019..1770672 100644 --- a/class/class-mainwp-child-plugins-check.php +++ b/class/class-mainwp-child-plugins-check.php @@ -127,39 +127,17 @@ class MainWP_Child_Plugins_Check { return $plugins_outdate; } - - public function change_plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) { - // Grab our previously stored array of known last modified dates. - $plugin_info = get_transient( $this->tran_name_plugin_timestamps ); - - // Sanity check the response. - if ( false === $plugin_info || ! is_array( $plugin_info ) && 0 === count( $plugin_info ) ) { - return $plugin_meta; - } - - // See if this specific plugin is in the known list. - if ( array_key_exists( $plugin_file, $plugin_info ) ) { - $now = new \DateTime(); - $last_updated = $plugin_info[ $plugin_file ]['last_updated']; - - // Last updated is stored as timestamp, get a real date. - $plugin_last_updated_date = new \DateTime( '@' . $last_updated ); - - // Compute days between now and plugin last updated. - $diff_in_days = $now->diff( $plugin_last_updated_date )->format( '%a' ); - - // Customizable number of days for tolerance. - $tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 ); - - // If we're outside the window for tolerance show a message. - if ( $diff_in_days > $tolerance_in_days ) { - $plugin_meta[] = sprintf( 'This plugin has not been updated by the author in %1$d days!', $diff_in_days ); - } else { - $plugin_meta[] = sprintf( 'This plugin was last updated by the author in %1$d days ago.', $diff_in_days ); + + public static function may_outdate_number_change() { + if ( isset( $_POST['numberdaysOutdatePluginTheme'] ) ) { + $days_outdate = get_option( 'mainwp_child_plugintheme_days_outdate', 365 ); + if ( $days_outdate != $_POST['numberdaysOutdatePluginTheme'] ) { + $days_outdate = intval( $_POST['numberdaysOutdatePluginTheme'] ); + MainWP_Helper::update_option( 'mainwp_child_plugintheme_days_outdate', $days_outdate ); + self::instance()->cleanup_deactivation( false ); + MainWP_Child_Themes_Check::instance()->cleanup_deactivation( false ); } } - - return $plugin_meta; } public function run_check() { diff --git a/class/class-mainwp-child-skeleton-key.php b/class/class-mainwp-child-skeleton-key.php index 2e543f9..fd385ac 100644 --- a/class/class-mainwp-child-skeleton-key.php +++ b/class/class-mainwp-child-skeleton-key.php @@ -128,8 +128,7 @@ class MainWP_Child_Skeleton_Key { $full_url = add_query_arg( $get_args, get_site_url() . $url ); - global $mainWPChild; - add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); + add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 ); $response = wp_remote_post( $full_url, $post_args ); diff --git a/class/class-mainwp-child-updates.php b/class/class-mainwp-child-updates.php new file mode 100644 index 0000000..243b98d --- /dev/null +++ b/class/class-mainwp-child-updates.php @@ -0,0 +1,754 @@ +filterFunction = function( $a ) { + if ( null == $a ) { + return false; } + if ( is_object( $a ) && property_exists( $a, 'last_checked' ) && ! property_exists( $a, 'checked' ) ) { + return false; + } + return $a; + }; + } + + public static function get_instance() { + if ( null === self::$instance ) { + self::$instance = new self(); + } + + return self::$instance; + } + + public function upgrade_plugin_theme() { + // Prevent disable/re-enable at upgrade. + if ( ! defined( 'DOING_CRON' ) ) { + define( 'DOING_CRON', true ); + } + + MainWP_Helper::get_wp_filesystem(); + + include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; + + if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { + include_once ABSPATH . '/wp-admin/includes/screen.php'; + } + if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) { + include_once ABSPATH . '/wp-admin/includes/template.php'; + } + if ( file_exists( ABSPATH . '/wp-admin/includes/misc.php' ) ) { + include_once ABSPATH . '/wp-admin/includes/misc.php'; + } + include_once ABSPATH . '/wp-admin/includes/file.php'; + include_once ABSPATH . '/wp-admin/includes/plugin.php'; + include_once ABSPATH . '/wp-admin/includes/plugin-install.php'; + + $information = array(); + $information['upgrades'] = array(); + $mwp_premium_updates_todo = array(); + $mwp_premium_updates_todo_slugs = array(); + if ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ) { + include_once ABSPATH . '/wp-admin/includes/update.php'; + if ( null !== $this->filterFunction ) { + add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); + } + + $plugins = explode( ',', urldecode( $_POST['list'] ) ); + + if ( in_array( 'backupbuddy/backupbuddy.php', $plugins ) ) { + if ( isset( $GLOBALS['ithemes_updater_path'] ) ) { + if ( ! class_exists( 'Ithemes_Updater_Settings' ) ) { + require $GLOBALS['ithemes_updater_path'] . '/settings.php'; + } + if ( class_exists( 'Ithemes_Updater_Settings' ) ) { + $ithemes_updater = new Ithemes_Updater_Settings(); + $ithemes_updater->update(); + } + } + } + + // to fix: smart-manager-for-wp-e-commerce update. + if ( in_array( 'smart-manager-for-wp-e-commerce/smart-manager.php', $plugins ) ) { + if ( file_exists( plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/smart-manager.php' ) ) { + include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/smart-manager.php'; + include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php'; + } + } + + global $wp_current_filter; + $wp_current_filter[] = 'load-plugins.php'; // phpcs:ignore -- to custom plugin installation. + wp_update_plugins(); + + // trick to prevent some premium plugins re-create update info. + remove_all_filters( 'pre_set_site_transient_update_plugins' ); + + // support cached premium plugins update info, hooking in the bulk_upgrade(). + add_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ) ); + + $information['plugin_updates'] = get_plugin_updates(); + + $plugins = explode( ',', urldecode( $_POST['list'] ) ); + $premiumPlugins = array(); + $premiumUpdates = get_option( 'mainwp_premium_updates' ); + if ( is_array( $premiumUpdates ) ) { + $newPlugins = array(); + foreach ( $plugins as $plugin ) { + if ( in_array( $plugin, $premiumUpdates ) ) { + $premiumPlugins[] = $plugin; + } else { + $newPlugins[] = $plugin; + } + } + $plugins = $newPlugins; + } + + if ( count( $plugins ) > 0 ) { + $failed = true; + // to fix update of Yithemes premiums plugins that hooked to upgrader_pre_download. + $url = 'update.php?action=update-selected&plugins=' . rawurlencode( implode( ',', $plugins ) ); + $nonce = 'bulk-update-plugins'; + + $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); + $result = $upgrader->bulk_upgrade( $plugins ); + + if ( ! empty( $result ) ) { + foreach ( $result as $plugin => $info ) { + if ( empty( $info ) ) { + + $information['upgrades'][ $plugin ] = false; + // try to fix if that is premiums update. + $api = apply_filters( 'plugins_api', false, 'plugin_information', array( 'slug' => $plugin ) ); + + if ( ! is_wp_error( $api ) && ! empty( $api ) ) { + if ( isset( $api->download_link ) ) { + $res = $upgrader->install( $api->download_link ); + if ( ! is_wp_error( $res ) && ! ( is_null( $res ) ) ) { + $information['upgrades'][ $plugin ] = true; + } + } + } + } else { + $information['upgrades'][ $plugin ] = true; + } + } + $failed = false; + } + + if ( $failed ) { + MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); + } + } + + remove_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ), 10 ); + delete_site_transient( 'mainwp_update_plugins_cached' ); // fix cached update info. + + if ( count( $premiumPlugins ) > 0 ) { + $mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() ); + if ( is_array( $mwp_premium_updates ) && is_array( $premiumPlugins ) ) { + foreach ( $premiumPlugins as $premiumPlugin ) { + foreach ( $mwp_premium_updates as $key => $update ) { + $slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] ); + if ( 0 === strcmp( $slug, $premiumPlugin ) ) { + $mwp_premium_updates_todo[ $key ] = $update; + $mwp_premium_updates_todo_slugs[] = $premiumPlugin; + } + } + } + } + unset( $mwp_premium_updates ); + $premiumUpgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); + } + + if ( count( $plugins ) <= 0 && count( $premiumPlugins ) <= 0 ) { + MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); + } + + if ( null !== $this->filterFunction ) { + remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); + } + } elseif ( isset( $_POST['type'] ) && 'theme' === $_POST['type'] ) { + + $last_update = get_site_transient( 'update_themes' ); + + include_once ABSPATH . '/wp-admin/includes/update.php'; + if ( null !== $this->filterFunction ) { + add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); + } + + wp_update_themes(); + include_once ABSPATH . '/wp-admin/includes/theme.php'; + + // to support cached premium themes update info, hooking in the bulk_upgrade(). + add_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ) ); + + $information['theme_updates'] = $this->upgrade_get_theme_updates(); + $themes = explode( ',', $_POST['list'] ); + $premiumThemes = array(); + $premiumUpdates = get_option( 'mainwp_premium_updates' ); + if ( is_array( $premiumUpdates ) ) { + $newThemes = array(); + foreach ( $themes as $theme ) { + if ( in_array( $theme, $premiumUpdates ) ) { + $premiumThemes[] = $theme; + } else { + $newThemes[] = $theme; + } + } + $themes = $newThemes; + } + + if ( count( $themes ) > 0 ) { + $addFilterToFixUpdate_optimizePressTheme = false; + if ( in_array( 'optimizePressTheme', $themes ) ) { + $addFilterToFixUpdate_optimizePressTheme = true; + add_filter( 'site_transient_update_themes', array( $this, 'hook_fix_optimize_press_theme_update' ), 99 ); + } + + if ( null !== $this->filterFunction ) { + remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); + } + + $last_update2 = get_site_transient( 'update_themes' ); + set_site_transient( 'update_themes', $last_update ); + + $failed = true; + $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); + $result = $upgrader->bulk_upgrade( $themes ); + if ( ! empty( $result ) ) { + foreach ( $result as $theme => $info ) { + if ( empty( $info ) ) { + $information['upgrades'][ $theme ] = false; + } else { + $information['upgrades'][ $theme ] = true; + } + } + $failed = false; + } + + if ( $failed ) { + MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); + } + + if ( null !== $this->filterFunction ) { + add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); + } + + set_site_transient( 'update_themes', $last_update2 ); + + if ( $addFilterToFixUpdate_optimizePressTheme ) { + remove_filter( + 'site_transient_update_themes', + array( + $this, + 'hook_fix_optimize_press_theme_update', + ), + 99 + ); + } + } + + remove_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ), 10 ); + delete_site_transient( 'mainwp_update_themes_cached' ); // fix cached update info. + + if ( count( $premiumThemes ) > 0 ) { + $mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() ); + $mwp_premium_updates_todo = array(); + $mwp_premium_updates_todo_slugs = array(); + if ( is_array( $premiumThemes ) && is_array( $mwp_premium_updates ) ) { + foreach ( $premiumThemes as $premiumTheme ) { + foreach ( $mwp_premium_updates as $key => $update ) { + $slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] ); + if ( 0 === strcmp( $slug, $premiumTheme ) ) { + $mwp_premium_updates_todo[ $key ] = $update; + $mwp_premium_updates_todo_slugs[] = $slug; + } + } + } + } + unset( $mwp_premium_updates ); + + $premiumUpgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); + } + if ( count( $themes ) <= 0 && count( $premiumThemes ) <= 0 ) { + MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); + } + + if ( null !== $this->filterFunction ) { + remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); + } + } else { + MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); + } + + if ( count( $mwp_premium_updates_todo ) > 0 ) { + // Upgrade via WP. + // @see wp-admin/update.php. + $result = $premiumUpgrader->bulk_upgrade( $mwp_premium_updates_todo_slugs ); + if ( ! empty( $result ) ) { + foreach ( $result as $plugin => $info ) { + if ( ! empty( $info ) ) { + $information['upgrades'][ $plugin ] = true; + + foreach ( $mwp_premium_updates_todo as $key => $update ) { + $slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] ); + } + } + } + } + + // Upgrade via callback. + foreach ( $mwp_premium_updates_todo as $update ) { + $slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] ); + + if ( isset( $update['url'] ) ) { + $installer = new WP_Upgrader(); + $result = $installer->run( + array( + 'package' => $update['url'], + 'destination' => ( 'plugin' === $update['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ), + 'clear_destination' => true, + 'clear_working' => true, + 'hook_extra' => array(), + ) + ); + $information['upgrades'][ $slug ] = ( ! is_wp_error( $result ) && ! empty( $result ) ); + } elseif ( isset( $update['callback'] ) ) { + if ( is_array( $update['callback'] ) && isset( $update['callback'][0] ) && isset( $update['callback'][1] ) ) { + $update_result = call_user_func( + array( + $update['callback'][0], + $update['callback'][1], + ) + ); + $information['upgrades'][ $slug ] = $update_result && true; + } elseif ( is_string( $update['callback'] ) ) { + $update_result = call_user_func( $update['callback'] ); + $information['upgrades'][ $slug ] = $update_result && true; + } else { + $information['upgrades'][ $slug ] = false; + } + } else { + $information['upgrades'][ $slug ] = false; + } + } + } + $information['sync'] = $this->get_site_stats( array(), false ); + mainwp_child_helper()->write( $information ); + } + + + public function hook_fix_optimize_press_theme_update( $transient ) { + if ( ! defined( 'OP_FUNC' ) ) { + return $transient; + } + + $theme_slug = 'optimizePressTheme'; + + if ( ! function_exists( 'op_sl_update' ) ) { + require_once OP_FUNC . 'options.php'; + require_once OP_FUNC . 'sl_api.php'; + } + $apiResponse = op_sl_update( 'theme' ); + + if ( is_wp_error( $apiResponse ) ) { + return $transient; + } + + $obj = new stdClass(); + $obj->slug = $theme_slug; + $obj->new_version = $apiResponse->new_version; + $obj->url = $apiResponse->url; + $obj->package = $apiResponse->s3_package; + $obj->sections = array( + 'description' => $apiResponse->section->description, + 'changelog' => $apiResponse->section->changelog, + ); + + $transient->response[ $theme_slug ] = (array) $obj; + + return $transient; + } + + + public function set_cached_update_plugins( $false = false, $_transient_data = null ) { + + if ( ! is_object( $_transient_data ) ) { + $_transient_data = new stdClass(); + } + + $pre = false; + $cached_update_info = get_site_transient( 'mainwp_update_plugins_cached' ); + if ( is_array( $cached_update_info ) && count( $cached_update_info ) > 0 ) { + foreach ( $cached_update_info as $slug => $info ) { + if ( ! isset( $_transient_data->response[ $slug ] ) && isset( $info->update ) ) { + $_transient_data->response[ $slug ] = $info->update; + $pre = true; + } + } + } + + if ( false == $pre ) { + return $false; + } + + return $_transient_data; + } + + + public function set_cached_update_themes( $false = false, $_transient_data = null ) { + + if ( ! is_object( $_transient_data ) ) { + $_transient_data = new stdClass(); + } + + $pre = false; + $cached_update_info = get_site_transient( 'mainwp_update_themes_cached' ); + if ( is_array( $cached_update_info ) && count( $cached_update_info ) > 0 ) { + foreach ( $cached_update_info as $slug => $info ) { + if ( ! isset( $_transient_data->response[ $slug ] ) && isset( $info->update ) ) { + $_transient_data->response[ $slug ] = $info->update; + $pre = true; + } + } + } + + if ( false == $pre ) { + return $false; + } + + return $_transient_data; + } + + public function detect_premium_themesplugins_updates() { + + if ( isset( $_GET['_detect_plugins_updates'] ) && 'yes' == $_GET['_detect_plugins_updates'] ) { + // to fix some premium plugins update notification. + $current = get_site_transient( 'update_plugins' ); + set_site_transient( 'update_plugins', $current ); + + add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); + $plugins = get_plugin_updates(); + remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); + + set_site_transient( 'mainwp_update_plugins_cached', $plugins, DAY_IN_SECONDS ); + } + + if ( isset( $_GET['_detect_themes_updates'] ) && 'yes' == $_GET['_detect_themes_updates'] ) { + add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); + $themes = get_theme_updates(); + remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); + + set_site_transient( 'mainwp_update_themes_cached', $themes, DAY_IN_SECONDS ); + } + + $type = isset( $_GET['_request_update_premiums_type'] ) ? $_GET['_request_update_premiums_type'] : ''; + + if ( 'plugin' == $type || 'theme' == $type ) { + $list = isset( $_GET['list'] ) ? $_GET['list'] : ''; + if ( ! empty( $list ) ) { + // to call function upgrade_plugin_theme(). + $_POST['type'] = $type; + $_POST['list'] = $list; + + global $mainWPChild; + $callable = $mainWPChild->get_callable_functions(); + + $function = 'upgradeplugintheme'; + if ( isset( $callable [ $function ] ) ) { + call_user_func( array( $this, $callable [ $function ] ) ); + } + + } + } + } + + + /** + * Functions to support core functionality + */ + public function install_plugin_theme() { + + MainWP_Helper::check_wp_filesystem(); + + 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'; + + $urlgot = json_decode( stripslashes( $_POST['url'] ) ); + + $urls = array(); + if ( ! is_array( $urlgot ) ) { + $urls[] = $urlgot; + } else { + $urls = $urlgot; + } + + $result = array(); + foreach ( $urls as $url ) { + $installer = new WP_Upgrader(); + $ssl_verify = true; + // @see wp-admin/includes/class-wp-upgrader.php + if ( isset( $_POST['sslVerify'] ) && '0' === $_POST['sslVerify'] ) { + add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'no_ssl_filter_function' ), 99, 2 ); + $ssl_verify = false; + } + add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 ); + + $result = $installer->run( + array( + 'package' => $url, + 'destination' => ( 'plugin' === $_POST['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ), + 'clear_destination' => ( isset( $_POST['overwrite'] ) && $_POST['overwrite'] ), + 'clear_working' => true, + 'hook_extra' => array(), + ) + ); + + if ( is_wp_error( $result ) ) { + if ( true == $ssl_verify && strpos( $url, 'https://' ) === 0 ) { + add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'no_ssl_filter_function' ), 99, 2 ); + $ssl_verify = false; + $result = $installer->run( + array( + 'package' => $url, + 'destination' => ( 'plugin' === $_POST['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ), + 'clear_destination' => ( isset( $_POST['overwrite'] ) && $_POST['overwrite'] ), + 'clear_working' => true, + 'hook_extra' => array(), + ) + ); + } + + if ( is_wp_error( $result ) ) { + $err_code = $result->get_error_code(); + if ( $result->get_error_data() && is_string( $result->get_error_data() ) ) { + $error = $result->get_error_data(); + MainWP_Helper::error( $error, $err_code ); + } else { + MainWP_Helper::error( implode( ', ', $error ), $err_code ); + } + } + } + + remove_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 ); + 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 = ''; + $rslt = null; + 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 ); + } + } + $information['installation'] = 'SUCCESS'; + $information['destination_name'] = $result['destination_name']; + mainwp_child_helper()->write( $information ); + } + + + + // This will upgrade WP! + public function upgrade_wp() { + global $wp_version; + MainWP_Helper::get_wp_filesystem(); + + $information = array(); + + include_once ABSPATH . '/wp-admin/includes/update.php'; + include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; + + if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { + include_once ABSPATH . '/wp-admin/includes/screen.php'; + } + if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) { + include_once ABSPATH . '/wp-admin/includes/template.php'; + } + include_once ABSPATH . '/wp-admin/includes/file.php'; + include_once ABSPATH . '/wp-admin/includes/misc.php'; + + if ( null !== $this->filterFunction ) { + add_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 ); + } + if ( null !== $this->filterFunction ) { + add_filter( 'pre_transient_update_core', $this->filterFunction, 99 ); + } + + // Check for new versions. + wp_version_check(); + + $core_updates = get_core_updates(); + if ( is_array( $core_updates ) && count( $core_updates ) > 0 ) { + foreach ( $core_updates as $core_update ) { + if ( 'latest' === $core_update->response ) { + $information['upgrade'] = 'SUCCESS'; + } elseif ( 'upgrade' === $core_update->response && get_locale() === $core_update->locale && version_compare( $wp_version, $core_update->current, '<=' ) ) { + // Upgrade! + $upgrade = false; + if ( class_exists( 'Core_Upgrader' ) ) { + $core = new Core_Upgrader(); + $upgrade = $core->upgrade( $core_update ); + } + // If this does not work - add code from /wp-admin/includes/class-wp-upgrader.php in the newer versions. + // So users can upgrade older versions too. + // 3rd option: 'wp_update_core'. + + if ( ! is_wp_error( $upgrade ) ) { + $information['upgrade'] = 'SUCCESS'; + } else { + $information['upgrade'] = 'WPERROR'; + } + break; + } + } + + if ( ! isset( $information['upgrade'] ) ) { + foreach ( $core_updates as $core_update ) { + if ( 'upgrade' === $core_update->response && version_compare( $wp_version, $core_update->current, '<=' ) ) { + // Upgrade! + $upgrade = false; + if ( class_exists( 'Core_Upgrader' ) ) { + $core = new Core_Upgrader(); + $upgrade = $core->upgrade( $core_update ); + } + // If this does not work - add code from /wp-admin/includes/class-wp-upgrader.php in the newer versions + // So users can upgrade older versions too. + // 3rd option: 'wp_update_core'. + if ( ! is_wp_error( $upgrade ) ) { + $information['upgrade'] = 'SUCCESS'; + } else { + $information['upgrade'] = 'WPERROR'; + } + break; + } + } + } + } else { + $information['upgrade'] = 'NORESPONSE'; + } + if ( null !== $this->filterFunction ) { + remove_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 ); + } + if ( null !== $this->filterFunction ) { + remove_filter( 'pre_transient_update_core', $this->filterFunction, 99 ); + } + + mainwp_child_helper()->write( $information ); + } + + public function upgrade_translation() { + // Prevent disable/re-enable at upgrade. + define( 'DOING_CRON', true ); + + MainWP_Helper::get_wp_filesystem(); + include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; + if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { + include_once ABSPATH . '/wp-admin/includes/screen.php'; + } + if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) { + include_once ABSPATH . '/wp-admin/includes/template.php'; + } + if ( file_exists( ABSPATH . '/wp-admin/includes/misc.php' ) ) { + include_once ABSPATH . '/wp-admin/includes/misc.php'; + } + include_once ABSPATH . '/wp-admin/includes/file.php'; + + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; + + wp_version_check(); + wp_update_themes(); + wp_update_plugins(); + + $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) ); + $translations = explode( ',', urldecode( $_POST['list'] ) ); + $all_language_updates = wp_get_translation_updates(); + + $language_updates = array(); + foreach ( $all_language_updates as $current_language_update ) { + if ( in_array( $current_language_update->slug, $translations ) ) { + $language_updates[] = $current_language_update; + } + } + + $result = count( $language_updates ) == 0 ? false : $upgrader->bulk_upgrade( $language_updates ); + if ( ! empty( $result ) ) { + $count_result = count( $result ); + for ( $i = 0; $i < $count_result; $i++ ) { + if ( empty( $result[ $i ] ) || is_wp_error( $result[ $i ] ) ) { + $information['upgrades'][ $language_updates[ $i ]->slug ] = false; + } else { + $information['upgrades'][ $language_updates[ $i ]->slug ] = true; + } + } + } else { + $information['upgrades'] = array(); // to fix error message when translations updated. + } + + $information['sync'] = $this->get_site_stats( array(), false ); + mainwp_child_helper()->write( $information ); + } +} diff --git a/class/class-mainwp-child.php b/class/class-mainwp-child.php index 116c441..0be942d 100644 --- a/class/class-mainwp-child.php +++ b/class/class-mainwp-child.php @@ -133,8 +133,8 @@ class MainWP_Child { add_action( 'admin_init', array( &$this, 'admin_init' ) ); add_action( 'admin_head', array( &$this, 'admin_head' ) ); add_action( 'init', array( &$this, 'localization' ), 33 ); - add_action( 'pre_current_active_plugins', array( &$this, 'detect_premium_themesplugins_updates' ) ); // to support detect premium plugins update. - add_action( 'core_upgrade_preamble', array( &$this, 'detect_premium_themesplugins_updates' ) ); // to support detect premium themes. + add_action( 'pre_current_active_plugins', array( MainWP_Child_Updates::get_instance(), 'detect_premium_themesplugins_updates' ) ); // to support detect premium plugins update. + add_action( 'core_upgrade_preamble', array( MainWP_Child_Updates::get_instance(), 'detect_premium_themesplugins_updates' ) ); // to support detect premium themes. if ( is_admin() ) { MainWP_Helper::update_option( 'mainwp_child_plugin_version', self::$version, 'yes' ); @@ -430,44 +430,6 @@ class MainWP_Child { load_plugin_textdomain( 'mainwp-child', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' ); } - public function detect_premium_themesplugins_updates() { - - if ( isset( $_GET['_detect_plugins_updates'] ) && 'yes' == $_GET['_detect_plugins_updates'] ) { - // to fix some premium plugins update notification. - $current = get_site_transient( 'update_plugins' ); - set_site_transient( 'update_plugins', $current ); - - add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); - $plugins = get_plugin_updates(); - remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); - - set_site_transient( 'mainwp_update_plugins_cached', $plugins, DAY_IN_SECONDS ); - } - - if ( isset( $_GET['_detect_themes_updates'] ) && 'yes' == $_GET['_detect_themes_updates'] ) { - add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); - $themes = get_theme_updates(); - remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); - - set_site_transient( 'mainwp_update_themes_cached', $themes, DAY_IN_SECONDS ); - } - - $type = isset( $_GET['_request_update_premiums_type'] ) ? $_GET['_request_update_premiums_type'] : ''; - if ( 'plugin' == $type || 'theme' == $type ) { - $list = isset( $_GET['list'] ) ? $_GET['list'] : ''; - if ( ! empty( $list ) ) { - // to call function upgrade_plugin_theme(). - $_POST['type'] = $type; - $_POST['list'] = $list; - - $function = 'upgradeplugintheme'; - if ( isset( $this->callableFunctions[ $function ] ) ) { - call_user_func( array( $this, $this->callableFunctions[ $function ] ) ); - } - } - } - } - public function check_other_auth() { $auths = get_option( 'mainwp_child_auth' ); @@ -521,6 +483,10 @@ class MainWP_Child { return apply_filters( 'mainwp_child_plugin_row_meta', $plugin_meta, $plugin_file, $this->plugin_slug ); } + public function get_callable_functions() { + return $this->callableFunctions; + } + public function admin_menu() { $branding_opts = MainWP_Child_Branding::instance()->get_branding_options(); $is_hide = isset( $branding_opts['hide'] ) ? $branding_opts['hide'] : ''; @@ -1528,682 +1494,24 @@ class MainWP_Child { return false; } - public function no_ssl_filter_function( $r, $url ) { - $r['sslverify'] = false; - - return $r; - } - - public function http_request_reject_unsafe_urls( $r, $url ) { - $r['reject_unsafe_urls'] = false; - if ( isset( $_POST['wpadmin_user'] ) && ! empty( $_POST['wpadmin_user'] ) && isset( $_POST['wpadmin_passwd'] ) && ! empty( $_POST['wpadmin_passwd'] ) ) { - $auth = base64_encode( $_POST['wpadmin_user'] . ':' . $_POST['wpadmin_passwd'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons. - $r['headers']['Authorization'] = "Basic $auth"; - } - return $r; - } /** - * Functions to support core functionality - */ + * Functions to support core functionality + */ public function install_plugin_theme() { - $wp_filesystem = $this->get_wp_filesystem(); - - 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'; - - $urlgot = json_decode( stripslashes( $_POST['url'] ) ); - - $urls = array(); - if ( ! is_array( $urlgot ) ) { - $urls[] = $urlgot; - } else { - $urls = $urlgot; - } - - $result = array(); - foreach ( $urls as $url ) { - $installer = new WP_Upgrader(); - $ssl_verify = true; - // @see wp-admin/includes/class-wp-upgrader.php - if ( isset( $_POST['sslVerify'] ) && '0' === $_POST['sslVerify'] ) { - add_filter( 'http_request_args', array( &$this, 'no_ssl_filter_function' ), 99, 2 ); - $ssl_verify = false; - } - add_filter( 'http_request_args', array( &$this, 'http_request_reject_unsafe_urls' ), 99, 2 ); - - $result = $installer->run( - array( - 'package' => $url, - 'destination' => ( 'plugin' === $_POST['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ), - 'clear_destination' => ( isset( $_POST['overwrite'] ) && $_POST['overwrite'] ), - 'clear_working' => true, - 'hook_extra' => array(), - ) - ); - - if ( is_wp_error( $result ) ) { - if ( true == $ssl_verify && strpos( $url, 'https://' ) === 0 ) { - add_filter( 'http_request_args', array( &$this, 'no_ssl_filter_function' ), 99, 2 ); - $ssl_verify = false; - $result = $installer->run( - array( - 'package' => $url, - 'destination' => ( 'plugin' === $_POST['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ), - 'clear_destination' => ( isset( $_POST['overwrite'] ) && $_POST['overwrite'] ), - 'clear_working' => true, - 'hook_extra' => array(), - ) - ); - } - - if ( is_wp_error( $result ) ) { - $err_code = $result->get_error_code(); - if ( $result->get_error_data() && is_string( $result->get_error_data() ) ) { - $error = $result->get_error_data(); - MainWP_Helper::error( $error, $err_code ); - } else { - MainWP_Helper::error( implode( ', ', $error ), $err_code ); - } - } - } - - remove_filter( 'http_request_args', array( &$this, 'http_request_reject_unsafe_urls' ), 99, 2 ); - if ( false == $ssl_verify ) { - remove_filter( 'http_request_args', array( &$this, 'no_ssl_filter_function' ), 99 ); - } - - $args = array( - 'success' => 1, - 'action' => 'install', - ); - if ( 'plugin' === $_POST['type'] ) { - $path = $result['destination']; - $fileName = ''; - $rslt = null; - 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 ); - } - } - $information['installation'] = 'SUCCESS'; - $information['destination_name'] = $result['destination_name']; - mainwp_child_helper()->write( $information ); + MainWP_Child_Install::get_instance()->install_plugin_theme(); } - - // This will upgrade WP! + public function upgrade_wp() { - global $wp_version; - $wp_filesystem = $this->get_wp_filesystem(); - - $information = array(); - - include_once ABSPATH . '/wp-admin/includes/update.php'; - include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; - - if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/screen.php'; - } - if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/template.php'; - } - include_once ABSPATH . '/wp-admin/includes/file.php'; - include_once ABSPATH . '/wp-admin/includes/misc.php'; - - if ( null !== $this->filterFunction ) { - add_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 ); - } - if ( null !== $this->filterFunction ) { - add_filter( 'pre_transient_update_core', $this->filterFunction, 99 ); - } - - // Check for new versions. - wp_version_check(); - - $core_updates = get_core_updates(); - if ( is_array( $core_updates ) && count( $core_updates ) > 0 ) { - foreach ( $core_updates as $core_update ) { - if ( 'latest' === $core_update->response ) { - $information['upgrade'] = 'SUCCESS'; - } elseif ( 'upgrade' === $core_update->response && get_locale() === $core_update->locale && version_compare( $wp_version, $core_update->current, '<=' ) ) { - // Upgrade! - $upgrade = false; - if ( class_exists( 'Core_Upgrader' ) ) { - $core = new Core_Upgrader(); - $upgrade = $core->upgrade( $core_update ); - } - // If this does not work - add code from /wp-admin/includes/class-wp-upgrader.php in the newer versions. - // So users can upgrade older versions too. - // 3rd option: 'wp_update_core'. - - if ( ! is_wp_error( $upgrade ) ) { - $information['upgrade'] = 'SUCCESS'; - } else { - $information['upgrade'] = 'WPERROR'; - } - break; - } - } - - if ( ! isset( $information['upgrade'] ) ) { - foreach ( $core_updates as $core_update ) { - if ( 'upgrade' === $core_update->response && version_compare( $wp_version, $core_update->current, '<=' ) ) { - // Upgrade! - $upgrade = false; - if ( class_exists( 'Core_Upgrader' ) ) { - $core = new Core_Upgrader(); - $upgrade = $core->upgrade( $core_update ); - } - // If this does not work - add code from /wp-admin/includes/class-wp-upgrader.php in the newer versions - // So users can upgrade older versions too. - // 3rd option: 'wp_update_core'. - if ( ! is_wp_error( $upgrade ) ) { - $information['upgrade'] = 'SUCCESS'; - } else { - $information['upgrade'] = 'WPERROR'; - } - break; - } - } - } - } else { - $information['upgrade'] = 'NORESPONSE'; - } - if ( null !== $this->filterFunction ) { - remove_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 ); - } - if ( null !== $this->filterFunction ) { - remove_filter( 'pre_transient_update_core', $this->filterFunction, 99 ); - } - - mainwp_child_helper()->write( $information ); + MainWP_Child_Updates::get_instance()->upgrade_wp(); } - + public function upgrade_translation() { - // Prevent disable/re-enable at upgrade. - define( 'DOING_CRON', true ); - - MainWP_Helper::get_wp_filesystem(); - include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; - if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/screen.php'; - } - if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/template.php'; - } - if ( file_exists( ABSPATH . '/wp-admin/includes/misc.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/misc.php'; - } - include_once ABSPATH . '/wp-admin/includes/file.php'; - - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; - - wp_version_check(); - wp_update_themes(); - wp_update_plugins(); - - $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) ); - $translations = explode( ',', urldecode( $_POST['list'] ) ); - $all_language_updates = wp_get_translation_updates(); - - $language_updates = array(); - foreach ( $all_language_updates as $current_language_update ) { - if ( in_array( $current_language_update->slug, $translations ) ) { - $language_updates[] = $current_language_update; - } - } - - $result = count( $language_updates ) == 0 ? false : $upgrader->bulk_upgrade( $language_updates ); - if ( ! empty( $result ) ) { - $count_result = count( $result ); - for ( $i = 0; $i < $count_result; $i++ ) { - if ( empty( $result[ $i ] ) || is_wp_error( $result[ $i ] ) ) { - $information['upgrades'][ $language_updates[ $i ]->slug ] = false; - } else { - $information['upgrades'][ $language_updates[ $i ]->slug ] = true; - } - } - } else { - $information['upgrades'] = array(); // to fix error message when translations updated. - } - - $information['sync'] = $this->get_site_stats( array(), false ); - mainwp_child_helper()->write( $information ); + MainWP_Child_Updates::get_instance()->upgrade_translation(); } public function upgrade_plugin_theme() { - // Prevent disable/re-enable at upgrade. - if ( ! defined( 'DOING_CRON' ) ) { - define( 'DOING_CRON', true ); - } - - MainWP_Helper::get_wp_filesystem(); - - include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; - - if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/screen.php'; - } - if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/template.php'; - } - if ( file_exists( ABSPATH . '/wp-admin/includes/misc.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/misc.php'; - } - include_once ABSPATH . '/wp-admin/includes/file.php'; - include_once ABSPATH . '/wp-admin/includes/plugin.php'; - include_once ABSPATH . '/wp-admin/includes/plugin-install.php'; - - $information = array(); - $information['upgrades'] = array(); - $mwp_premium_updates_todo = array(); - $mwp_premium_updates_todo_slugs = array(); - if ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ) { - include_once ABSPATH . '/wp-admin/includes/update.php'; - if ( null !== $this->filterFunction ) { - add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); - } - - $plugins = explode( ',', urldecode( $_POST['list'] ) ); - - if ( in_array( 'backupbuddy/backupbuddy.php', $plugins ) ) { - if ( isset( $GLOBALS['ithemes_updater_path'] ) ) { - if ( ! class_exists( 'Ithemes_Updater_Settings' ) ) { - require $GLOBALS['ithemes_updater_path'] . '/settings.php'; - } - if ( class_exists( 'Ithemes_Updater_Settings' ) ) { - $ithemes_updater = new Ithemes_Updater_Settings(); - $ithemes_updater->update(); - } - } - } - - // to fix: smart-manager-for-wp-e-commerce update. - if ( in_array( 'smart-manager-for-wp-e-commerce/smart-manager.php', $plugins ) ) { - if ( file_exists( plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/smart-manager.php' ) ) { - include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/smart-manager.php'; - include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php'; - } - } - - global $wp_current_filter; - $wp_current_filter[] = 'load-plugins.php'; // phpcs:ignore -- to custom plugin installation. - wp_update_plugins(); - - // trick to prevent some premium plugins re-create update info. - remove_all_filters( 'pre_set_site_transient_update_plugins' ); - - // support cached premium plugins update info, hooking in the bulk_upgrade(). - add_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ) ); - - $information['plugin_updates'] = get_plugin_updates(); - - $plugins = explode( ',', urldecode( $_POST['list'] ) ); - $premiumPlugins = array(); - $premiumUpdates = get_option( 'mainwp_premium_updates' ); - if ( is_array( $premiumUpdates ) ) { - $newPlugins = array(); - foreach ( $plugins as $plugin ) { - if ( in_array( $plugin, $premiumUpdates ) ) { - $premiumPlugins[] = $plugin; - } else { - $newPlugins[] = $plugin; - } - } - $plugins = $newPlugins; - } - - if ( count( $plugins ) > 0 ) { - $failed = true; - // to fix update of Yithemes premiums plugins that hooked to upgrader_pre_download. - $url = 'update.php?action=update-selected&plugins=' . rawurlencode( implode( ',', $plugins ) ); - $nonce = 'bulk-update-plugins'; - - $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); - $result = $upgrader->bulk_upgrade( $plugins ); - - if ( ! empty( $result ) ) { - foreach ( $result as $plugin => $info ) { - if ( empty( $info ) ) { - - $information['upgrades'][ $plugin ] = false; - // try to fix if that is premiums update. - $api = apply_filters( 'plugins_api', false, 'plugin_information', array( 'slug' => $plugin ) ); - - if ( ! is_wp_error( $api ) && ! empty( $api ) ) { - if ( isset( $api->download_link ) ) { - $res = $upgrader->install( $api->download_link ); - if ( ! is_wp_error( $res ) && ! ( is_null( $res ) ) ) { - $information['upgrades'][ $plugin ] = true; - } - } - } - } else { - $information['upgrades'][ $plugin ] = true; - } - } - $failed = false; - } - - if ( $failed ) { - MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); - } - } - - remove_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ), 10 ); - delete_site_transient( 'mainwp_update_plugins_cached' ); // fix cached update info. - - if ( count( $premiumPlugins ) > 0 ) { - $mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() ); - if ( is_array( $mwp_premium_updates ) && is_array( $premiumPlugins ) ) { - foreach ( $premiumPlugins as $premiumPlugin ) { - foreach ( $mwp_premium_updates as $key => $update ) { - $slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] ); - if ( 0 === strcmp( $slug, $premiumPlugin ) ) { - $mwp_premium_updates_todo[ $key ] = $update; - $mwp_premium_updates_todo_slugs[] = $premiumPlugin; - } - } - } - } - unset( $mwp_premium_updates ); - $premiumUpgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); - } - - if ( count( $plugins ) <= 0 && count( $premiumPlugins ) <= 0 ) { - MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); - } - - if ( null !== $this->filterFunction ) { - remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); - } - } elseif ( isset( $_POST['type'] ) && 'theme' === $_POST['type'] ) { - - $last_update = get_site_transient( 'update_themes' ); - - include_once ABSPATH . '/wp-admin/includes/update.php'; - if ( null !== $this->filterFunction ) { - add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); - } - - wp_update_themes(); - include_once ABSPATH . '/wp-admin/includes/theme.php'; - - // to support cached premium themes update info, hooking in the bulk_upgrade(). - add_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ) ); - - $information['theme_updates'] = $this->upgrade_get_theme_updates(); - $themes = explode( ',', $_POST['list'] ); - $premiumThemes = array(); - $premiumUpdates = get_option( 'mainwp_premium_updates' ); - if ( is_array( $premiumUpdates ) ) { - $newThemes = array(); - foreach ( $themes as $theme ) { - if ( in_array( $theme, $premiumUpdates ) ) { - $premiumThemes[] = $theme; - } else { - $newThemes[] = $theme; - } - } - $themes = $newThemes; - } - - if ( count( $themes ) > 0 ) { - $addFilterToFixUpdate_optimizePressTheme = false; - if ( in_array( 'optimizePressTheme', $themes ) ) { - $addFilterToFixUpdate_optimizePressTheme = true; - add_filter( 'site_transient_update_themes', array( $this, 'hook_fix_optimize_press_theme_update' ), 99 ); - } - - if ( null !== $this->filterFunction ) { - remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); - } - - $last_update2 = get_site_transient( 'update_themes' ); - set_site_transient( 'update_themes', $last_update ); - - $failed = true; - $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); - $result = $upgrader->bulk_upgrade( $themes ); - if ( ! empty( $result ) ) { - foreach ( $result as $theme => $info ) { - if ( empty( $info ) ) { - $information['upgrades'][ $theme ] = false; - } else { - $information['upgrades'][ $theme ] = true; - } - } - $failed = false; - } - - if ( $failed ) { - MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); - } - - if ( null !== $this->filterFunction ) { - add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); - } - - set_site_transient( 'update_themes', $last_update2 ); - - if ( $addFilterToFixUpdate_optimizePressTheme ) { - remove_filter( - 'site_transient_update_themes', - array( - $this, - 'hook_fix_optimize_press_theme_update', - ), - 99 - ); - } - } - - remove_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ), 10 ); - delete_site_transient( 'mainwp_update_themes_cached' ); // fix cached update info. - - if ( count( $premiumThemes ) > 0 ) { - $mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() ); - $mwp_premium_updates_todo = array(); - $mwp_premium_updates_todo_slugs = array(); - if ( is_array( $premiumThemes ) && is_array( $mwp_premium_updates ) ) { - foreach ( $premiumThemes as $premiumTheme ) { - foreach ( $mwp_premium_updates as $key => $update ) { - $slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] ); - if ( 0 === strcmp( $slug, $premiumTheme ) ) { - $mwp_premium_updates_todo[ $key ] = $update; - $mwp_premium_updates_todo_slugs[] = $slug; - } - } - } - } - unset( $mwp_premium_updates ); - - $premiumUpgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); - } - if ( count( $themes ) <= 0 && count( $premiumThemes ) <= 0 ) { - MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); - } - - if ( null !== $this->filterFunction ) { - remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); - } - } else { - MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); - } - - if ( count( $mwp_premium_updates_todo ) > 0 ) { - // Upgrade via WP. - // @see wp-admin/update.php. - $result = $premiumUpgrader->bulk_upgrade( $mwp_premium_updates_todo_slugs ); - if ( ! empty( $result ) ) { - foreach ( $result as $plugin => $info ) { - if ( ! empty( $info ) ) { - $information['upgrades'][ $plugin ] = true; - - foreach ( $mwp_premium_updates_todo as $key => $update ) { - $slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] ); - } - } - } - } - - // Upgrade via callback. - foreach ( $mwp_premium_updates_todo as $update ) { - $slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] ); - - if ( isset( $update['url'] ) ) { - $installer = new WP_Upgrader(); - $result = $installer->run( - array( - 'package' => $update['url'], - 'destination' => ( 'plugin' === $update['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ), - 'clear_destination' => true, - 'clear_working' => true, - 'hook_extra' => array(), - ) - ); - $information['upgrades'][ $slug ] = ( ! is_wp_error( $result ) && ! empty( $result ) ); - } elseif ( isset( $update['callback'] ) ) { - if ( is_array( $update['callback'] ) && isset( $update['callback'][0] ) && isset( $update['callback'][1] ) ) { - $update_result = call_user_func( - array( - $update['callback'][0], - $update['callback'][1], - ) - ); - $information['upgrades'][ $slug ] = $update_result && true; - } elseif ( is_string( $update['callback'] ) ) { - $update_result = call_user_func( $update['callback'] ); - $information['upgrades'][ $slug ] = $update_result && true; - } else { - $information['upgrades'][ $slug ] = false; - } - } else { - $information['upgrades'][ $slug ] = false; - } - } - } - $information['sync'] = $this->get_site_stats( array(), false ); - mainwp_child_helper()->write( $information ); - } - - public function set_cached_update_plugins( $false = false, $_transient_data = null ) { - - if ( ! is_object( $_transient_data ) ) { - $_transient_data = new stdClass(); - } - - $pre = false; - $cached_update_info = get_site_transient( 'mainwp_update_plugins_cached' ); - if ( is_array( $cached_update_info ) && count( $cached_update_info ) > 0 ) { - foreach ( $cached_update_info as $slug => $info ) { - if ( ! isset( $_transient_data->response[ $slug ] ) && isset( $info->update ) ) { - $_transient_data->response[ $slug ] = $info->update; - $pre = true; - } - } - } - - if ( false == $pre ) { - return $false; - } - - return $_transient_data; - } - - public function set_cached_update_themes( $false = false, $_transient_data = null ) { - - if ( ! is_object( $_transient_data ) ) { - $_transient_data = new stdClass(); - } - - $pre = false; - $cached_update_info = get_site_transient( 'mainwp_update_themes_cached' ); - if ( is_array( $cached_update_info ) && count( $cached_update_info ) > 0 ) { - foreach ( $cached_update_info as $slug => $info ) { - if ( ! isset( $_transient_data->response[ $slug ] ) && isset( $info->update ) ) { - $_transient_data->response[ $slug ] = $info->update; - $pre = true; - } - } - } - - if ( false == $pre ) { - return $false; - } - - return $_transient_data; - } - - public function hook_fix_optimize_press_theme_update( $transient ) { - if ( ! defined( 'OP_FUNC' ) ) { - return $transient; - } - - $theme_slug = 'optimizePressTheme'; - - if ( ! function_exists( 'op_sl_update' ) ) { - require_once OP_FUNC . 'options.php'; - require_once OP_FUNC . 'sl_api.php'; - } - $apiResponse = op_sl_update( 'theme' ); - - if ( is_wp_error( $apiResponse ) ) { - return $transient; - } - - $obj = new stdClass(); - $obj->slug = $theme_slug; - $obj->new_version = $apiResponse->new_version; - $obj->url = $apiResponse->url; - $obj->package = $apiResponse->s3_package; - $obj->sections = array( - 'description' => $apiResponse->section->description, - 'changelog' => $apiResponse->section->changelog, - ); - - $transient->response[ $theme_slug ] = (array) $obj; - - return $transient; + MainWP_Child_Updates::get_instance()->upgrade_plugin_theme(); } // This will register the current wp - thus generating the public key etc. @@ -3393,15 +2701,7 @@ class MainWP_Child { MainWP_Helper::update_option( 'mainwp_child_server', $_POST['server'] ); } - if ( isset( $_POST['numberdaysOutdatePluginTheme'] ) ) { - $days_outdate = get_option( 'mainwp_child_plugintheme_days_outdate', 365 ); - if ( $days_outdate != $_POST['numberdaysOutdatePluginTheme'] ) { - $days_outdate = intval( $_POST['numberdaysOutdatePluginTheme'] ); - MainWP_Helper::update_option( 'mainwp_child_plugintheme_days_outdate', $days_outdate ); - MainWP_Child_Plugins_Check::instance()->cleanup_deactivation( false ); - MainWP_Child_Themes_Check::instance()->cleanup_deactivation( false ); - } - } + MainWP_Child_Plugins_Check::may_outdate_number_change(); $information['version'] = self::$version; $information['wpversion'] = $wp_version; @@ -3667,40 +2967,7 @@ class MainWP_Child { $information['recent_posts'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number ); $information['recent_pages'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number, 'page' ); - - $securityIssuess = 0; - if ( ! MainWP_Security::prevent_listing_ok() ) { - $securityIssuess ++; - } - if ( ! MainWP_Security::remove_wp_version_ok() ) { - $securityIssuess ++; - } - if ( ! MainWP_Security::remove_rsd_ok() ) { - $securityIssuess ++; - } - if ( ! MainWP_Security::remove_wlw_ok() ) { - $securityIssuess ++; - } - if ( ! MainWP_Security::remove_database_reporting_ok() ) { - $securityIssuess ++; - } - if ( ! MainWP_Security::remove_php_reporting_ok() ) { - $securityIssuess ++; - } - if ( ! MainWP_Security::remove_scripts_version_ok() || ! MainWP_Security::remove_styles_version_ok() || ! MainWP_Security::remove_generator_version_ok() ) { - $securityIssuess ++; - } - if ( ! MainWP_Security::remove_registered_versions_ok() ) { - $securityIssuess ++; - } - if ( ! MainWP_Security::admin_user_ok() ) { - $securityIssuess ++; - } - if ( ! MainWP_Security::remove_readme_ok() ) { - $securityIssuess ++; - } - - $information['securityIssues'] = $securityIssuess; + $information['securityIssues'] = MainWP_Security::get_stats_security();; // Directory listings! $information['directories'] = $this->scan_dir( ABSPATH, 3 ); @@ -4340,8 +3607,11 @@ class MainWP_Child { include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php'; include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php'; - - $wp_filesystem = $this->get_wp_filesystem(); + + global $wp_filesystem; + + MainWP_Helper::check_wp_filesystem(); + if ( empty( $wp_filesystem ) ) { $wp_filesystem = new WP_Filesystem_Direct( null ); } @@ -4467,7 +3737,9 @@ class MainWP_Child { include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php'; include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php'; - $wp_filesystem = $this->get_wp_filesystem(); + global $wp_filesystem; + MainWP_Helper::check_wp_filesystem(); + if ( null === $wp_filesystem ) { $wp_filesystem = new WP_Filesystem_Direct( null ); } @@ -4773,37 +4045,6 @@ class MainWP_Child { } } - public function get_wp_filesystem() { - global $wp_filesystem; - - if ( empty( $wp_filesystem ) ) { - ob_start(); - if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/screen.php'; - } - if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) { - include_once ABSPATH . '/wp-admin/includes/template.php'; - } - $creds = request_filesystem_credentials( 'test', '', false, false, $extra_fields = null ); - ob_end_clean(); - if ( empty( $creds ) ) { - define( 'FS_METHOD', 'direct' ); - } - WP_Filesystem( $creds ); - } - - if ( empty( $wp_filesystem ) ) { - MainWP_Helper::error( $this->FTP_ERROR ); - } elseif ( is_wp_error( $wp_filesystem->errors ) ) { - $errorCodes = $wp_filesystem->errors->get_error_codes(); - if ( ! empty( $errorCodes ) ) { - MainWP_Helper::error( __( 'WordPress Filesystem error: ', 'mainwp-child' ) . $wp_filesystem->errors->get_error_message() ); - } - } - - return $wp_filesystem; - } - public function get_total_file_size( $directory = WP_CONTENT_DIR ) { try { if ( MainWP_Helper::function_exists( 'popen' ) ) { diff --git a/class/class-mainwp-helper.php b/class/class-mainwp-helper.php index a1779d5..65c27ac 100644 --- a/class/class-mainwp-helper.php +++ b/class/class-mainwp-helper.php @@ -6,6 +6,17 @@ class MainWP_Helper { public static $instance = null; + /** + * Method get_class_name() + * + * Get Class Name. + * + * @return object + */ + public static function get_class_name() { + return __CLASS__; + } + public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); @@ -214,12 +225,12 @@ class MainWP_Helper { if ( ! is_array( $img_data ) ) { $img_data = array(); } - global $mainWPChild; + include_once ABSPATH . 'wp-admin/includes/file.php'; $upload_dir = wp_upload_dir(); - add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); + add_filter( 'http_request_args', array( self::get_class_name(), 'reject_unsafe_urls' ), 99, 2 ); $temporary_file = download_url( $img_url ); - remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); + remove_filter( 'http_request_args', array( self::get_class_name(), 'reject_unsafe_urls' ), 99, 2 ); if ( is_wp_error( $temporary_file ) ) { throw new \Exception( 'Error: ' . $temporary_file->get_error_message() ); @@ -991,6 +1002,38 @@ class MainWP_Helper { return $init; } + + public static function check_wp_filesystem() { + + self::get_wp_filesystem(); + global $wp_filesystem; + + if ( empty( $wp_filesystem ) ) { + MainWP_Helper::error( $this->FTP_ERROR ); + } elseif ( is_wp_error( $wp_filesystem->errors ) ) { + $errorCodes = $wp_filesystem->errors->get_error_codes(); + if ( ! empty( $errorCodes ) ) { + MainWP_Helper::error( __( 'WordPress Filesystem error: ', 'mainwp-child' ) . $wp_filesystem->errors->get_error_message() ); + } + } + + return $wp_filesystem; + } + + public static function no_ssl_filter_function( $r, $url ) { + $r['sslverify'] = false; + return $r; + } + + public static function reject_unsafe_urls( $r, $url ) { + $r['reject_unsafe_urls'] = false; + if ( isset( $_POST['wpadmin_user'] ) && ! empty( $_POST['wpadmin_user'] ) && isset( $_POST['wpadmin_passwd'] ) && ! empty( $_POST['wpadmin_passwd'] ) ) { + $auth = base64_encode( $_POST['wpadmin_user'] . ':' . $_POST['wpadmin_passwd'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons. + $r['headers']['Authorization'] = "Basic $auth"; + } + return $r; + } + public static function starts_with( $haystack, $needle ) { return ! strncmp( $haystack, $needle, strlen( $needle ) ); } diff --git a/class/class-mainwp-security.php b/class/class-mainwp-security.php index 7ccdc0b..c366c1a 100644 --- a/class/class-mainwp-security.php +++ b/class/class-mainwp-security.php @@ -268,6 +268,41 @@ class MainWP_Security { return false; } + public static function get_stats_security() { + $securityIssuess = 0; + if ( ! self::prevent_listing_ok() ) { + $securityIssuess ++; + } + if ( ! self::remove_wp_version_ok() ) { + $securityIssuess ++; + } + if ( ! self::remove_rsd_ok() ) { + $securityIssuess ++; + } + if ( ! self::remove_wlw_ok() ) { + $securityIssuess ++; + } + if ( ! self::remove_database_reporting_ok() ) { + $securityIssuess ++; + } + if ( ! self::remove_php_reporting_ok() ) { + $securityIssuess ++; + } + if ( ! self::remove_scripts_version_ok() || ! self::remove_styles_version_ok() || ! self::remove_generator_version_ok() ) { + $securityIssuess ++; + } + if ( ! self::remove_registered_versions_ok() ) { + $securityIssuess ++; + } + if ( ! self::admin_user_ok() ) { + $securityIssuess ++; + } + if ( ! self::remove_readme_ok() ) { + $securityIssuess ++; + } + return $securityIssuess; + } + public static function update_security_option( $key, $value ) { $security = get_option( 'mainwp_security' ); if ( ! empty( $key ) ) { diff --git a/class/class-mainwp-wordpress-seo.php b/class/class-mainwp-wordpress-seo.php index 897e7ee..31c7161 100644 --- a/class/class-mainwp-wordpress-seo.php +++ b/class/class-mainwp-wordpress-seo.php @@ -55,12 +55,12 @@ class MainWP_WordPress_SEO { if ( isset( $_POST['file_url'] ) ) { $file_url = base64_decode( $_POST['file_url'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons. $temporary_file = ''; - global $mainWPChild; + try { include_once ABSPATH . 'wp-admin/includes/file.php'; - add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); + add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 ); $temporary_file = download_url( $file_url ); - remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); + remove_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 ); if ( is_wp_error( $temporary_file ) ) { throw new \Exception( 'Error: ' . $temporary_file->get_error_message() ); } else {