[CodeFactor] Apply fixes to commit 6467036

[ci skip] [skip ci]
This commit is contained in:
codefactor-io 2020-03-27 13:05:05 +00:00
parent 6467036af9
commit c037098788
3 changed files with 266 additions and 278 deletions

View file

@ -4,7 +4,7 @@ if ( defined( 'MAINWP_DEBUG' ) && MAINWP_DEBUG === true ) {
@ini_set( 'display_errors', true ); @ini_set( 'display_errors', true );
@ini_set( 'display_startup_errors', true ); @ini_set( 'display_startup_errors', true );
} else { } else {
if (isset($_REQUEST['mainwpsignature'])) { if ( isset($_REQUEST['mainwpsignature']) ) {
@ini_set( 'display_errors', false ); @ini_set( 'display_errors', false );
@error_reporting( 0 ); @error_reporting( 0 );
} }
@ -63,7 +63,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus
// To fix verify nonce conflict #1 // To fix verify nonce conflict #1
// this is fake post field to fix some conflict of wp_verify_nonce() // this is fake post field to fix some conflict of wp_verify_nonce()
// just return false to unverify nonce, does not exit // just return false to unverify nonce, does not exit
if ( isset($_POST[ $action ]) && ( $_POST[ $action ] == 'mainwp-bsm-unverify-nonce' )) { if ( isset($_POST[ $action ]) && ( $_POST[ $action ] == 'mainwp-bsm-unverify-nonce' ) ) {
return false; return false;
} }
@ -77,7 +77,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus
// To fix verify nonce conflict #2 // To fix verify nonce conflict #2
// this is fake nonce to fix some conflict of wp_verify_nonce() // this is fake nonce to fix some conflict of wp_verify_nonce()
// just return false to unverify nonce, does not exit // just return false to unverify nonce, does not exit
if ($nonce == 'mainwp-bsm-unverify-nonce') { if ( $nonce == 'mainwp-bsm-unverify-nonce' ) {
return false; return false;
} }
@ -99,7 +99,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus
// To fix verify nonce conflict #3 // To fix verify nonce conflict #3
// this is fake post field to fix some conflict of wp_verify_nonce() // this is fake post field to fix some conflict of wp_verify_nonce()
// just return false to unverify nonce, does not exit // just return false to unverify nonce, does not exit
if ( isset($_POST[ $action ]) && ( $_POST[ $action ] == 'mainwp-bsm-unverify-nonce' )) { if ( isset($_POST[ $action ]) && ( $_POST[ $action ] == 'mainwp-bsm-unverify-nonce' ) ) {
return false; return false;
} }
@ -211,10 +211,10 @@ class MainWP_Child {
public function __construct( $plugin_file ) { public function __construct( $plugin_file ) {
$this->update(); $this->update();
$this->load_all_options(); $this->load_all_options();
$this->filterFunction = function( $a) { $this->filterFunction = function( $a ) {
if ($a == null) { if ( $a == null ) {
return false; } return false; }
if (is_object($a) && property_exists($a, 'last_checked') && ! property_exists($a, 'checked')) { if ( is_object($a) && property_exists($a, 'last_checked') && ! property_exists($a, 'checked') ) {
return false; return false;
} }
return $a; return $a;
@ -321,7 +321,7 @@ class MainWP_Child {
'mainwp_child_plugintheme_days_outdate', 'mainwp_child_plugintheme_days_outdate',
); );
$query = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name in ("; $query = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name in (";
foreach ($options as $option) { foreach ( $options as $option ) {
$query .= "'" . $option . "', "; $query .= "'" . $option . "', ";
} }
$query = substr($query, 0, strlen($query) - 2); $query = substr($query, 0, strlen($query) - 2);
@ -337,7 +337,7 @@ class MainWP_Child {
$alloptions[ $o->option_name ] = $o->option_value; $alloptions[ $o->option_name ] = $o->option_value;
unset($options[ array_search($o->option_name, $options) ]); unset($options[ array_search($o->option_name, $options) ]);
} }
foreach ($options as $option ) { foreach ( $options as $option ) {
$notoptions[ $option ] = true; $notoptions[ $option ] = true;
} }
if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) { if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
@ -514,7 +514,6 @@ class MainWP_Child {
} }
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $convertBranding ); MainWP_Helper::update_option( 'mainwp_child_branding_settings', $convertBranding );
} }
} }
MainWP_Helper::update_option( 'mainwp_child_update_version', $this->update_version, 'yes' ); MainWP_Helper::update_option( 'mainwp_child_update_version', $this->update_version, 'yes' );
@ -570,7 +569,7 @@ class MainWP_Child {
public function detect_premium_themesplugins_updates() { public function detect_premium_themesplugins_updates() {
if (isset($_GET['_detect_plugins_updates']) && $_GET['_detect_plugins_updates'] == 'yes') { if ( isset($_GET['_detect_plugins_updates']) && $_GET['_detect_plugins_updates'] == 'yes' ) {
// to fix some premium plugins update notification // to fix some premium plugins update notification
$current = get_site_transient( 'update_plugins' ); $current = get_site_transient( 'update_plugins' );
set_site_transient( 'update_plugins', $current ); set_site_transient( 'update_plugins', $current );
@ -584,7 +583,7 @@ class MainWP_Child {
} }
if (isset($_GET['_detect_themes_updates']) && $_GET['_detect_themes_updates'] == 'yes') { if ( isset($_GET['_detect_themes_updates']) && $_GET['_detect_themes_updates'] == 'yes' ) {
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
$themes = get_theme_updates(); $themes = get_theme_updates();
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
@ -603,7 +602,7 @@ class MainWP_Child {
$_POST['list'] = $list; $_POST['list'] = $list;
$function = 'upgradeplugintheme'; $function = 'upgradeplugintheme';
if (isset($this->callableFunctions[ $function ])) { if ( isset($this->callableFunctions[ $function ]) ) {
call_user_func( array( $this, $this->callableFunctions[ $function ] ) ); call_user_func( array( $this, $this->callableFunctions[ $function ] ) );
} }
// wp_destroy_current_session(); // to fix issue multi user session // wp_destroy_current_session(); // to fix issue multi user session
@ -766,7 +765,7 @@ class MainWP_Child {
global $submenu; global $submenu;
if ( isset( $submenu['options-general.php'] ) ) { if ( isset( $submenu['options-general.php'] ) ) {
foreach ( $submenu['options-general.php'] as $index => $item ) { foreach ( $submenu['options-general.php'] as $index => $item ) {
if ( 'mainwp-reports-page' === $item[2] || 'mainwp-reports-settings' === $item[2]) { if ( 'mainwp-reports-page' === $item[2] || 'mainwp-reports-settings' === $item[2] ) {
unset( $submenu['options-general.php'][ $index ] ); unset( $submenu['options-general.php'][ $index ] );
} }
} }
@ -774,7 +773,7 @@ class MainWP_Child {
} }
} }
function render_pages( $shownPage) { function render_pages( $shownPage ) {
$shownPage = ''; $shownPage = '';
if ( isset($_GET['tab']) ) { if ( isset($_GET['tab']) ) {
$shownPage = $_GET['tab']; $shownPage = $_GET['tab'];
@ -788,14 +787,14 @@ class MainWP_Child {
$hide_style = 'style="display:none"'; $hide_style = 'style="display:none"';
if ($shownPage == '') { if ( $shownPage == '' ) {
if ( ! $hide_settings ) { if ( ! $hide_settings ) {
$shownPage = 'settings'; $shownPage = 'settings';
} elseif ( ! $hide_restore) { } elseif ( ! $hide_restore ) {
$shownPage = 'restore-clone'; $shownPage = 'restore-clone';
} elseif ( ! $hide_server_info) { } elseif ( ! $hide_server_info ) {
$shownPage = 'server-info'; $shownPage = 'server-info';
} elseif ( ! $hide_connection_detail) { } elseif ( ! $hide_connection_detail ) {
$shownPage = 'connection-detail'; $shownPage = 'connection-detail';
} }
} }
@ -829,13 +828,13 @@ class MainWP_Child {
</div> </div>
<?php } ?> <?php } ?>
<?php if ( ! $hide_server_info ) { ?> <?php if ( ! $hide_server_info ) { ?>
<div class="mainwp-child-setting-tab server-info" <?php echo ( 'server-info' !== $shownPage ) ? $hide_style : ''; ?>> <div class="mainwp-child-setting-tab server-info" <?php echo ( 'server-info' !== $shownPage ) ? $hide_style : ''; ?>>
<?php MainWP_Child_Server_Information::renderPage(); ?> <?php MainWP_Child_Server_Information::renderPage(); ?>
</div> </div>
<?php } ?> <?php } ?>
<?php if ( ! $hide_connection_detail ) { ?> <?php if ( ! $hide_connection_detail ) { ?>
<div class="mainwp-child-setting-tab connection-detail" <?php echo ( 'connection-detail' !== $shownPage ) ? $hide_style : ''; ?>> <div class="mainwp-child-setting-tab connection-detail" <?php echo ( 'connection-detail' !== $shownPage ) ? $hide_style : ''; ?>>
<?php MainWP_Child_Server_Information::renderConnectionDetails(); ?> <?php MainWP_Child_Server_Information::renderConnectionDetails(); ?>
</div> </div>
@ -847,12 +846,12 @@ class MainWP_Child {
self::render_footer(); self::render_footer();
} }
public static function render_header( $shownPage, $subpage = true) { public static function render_header( $shownPage, $subpage = true ) {
if ( isset($_GET['tab']) ) { if ( isset($_GET['tab']) ) {
$shownPage = $_GET['tab']; $shownPage = $_GET['tab'];
} }
if (empty($shownPage)) { if ( empty($shownPage) ) {
$shownPage = 'settings'; $shownPage = 'settings';
} }
@ -1012,7 +1011,7 @@ class MainWP_Child {
} }
function admin_head() { function admin_head() {
if (isset($_GET['page']) && $_GET['page'] == 'mainwp_child_tab') { if ( isset($_GET['page']) && $_GET['page'] == 'mainwp_child_tab' ) {
?> ?>
<style type="text/css"> <style type="text/css">
.mainwp-postbox-actions-top { .mainwp-postbox-actions-top {
@ -1196,7 +1195,7 @@ class MainWP_Child {
if ( isset( $_POST['function'] ) && 'visitPermalink' === $_POST['function'] ) { if ( isset( $_POST['function'] ) && 'visitPermalink' === $_POST['function'] ) {
if (empty($auth_user)) { if ( empty($auth_user) ) {
$auth_user = $_POST['user']; $auth_user = $_POST['user'];
} }
@ -1520,7 +1519,7 @@ class MainWP_Child {
if ( isset( $_POST['function'] ) && 'visitPermalink' === $_POST['function'] ) { if ( isset( $_POST['function'] ) && 'visitPermalink' === $_POST['function'] ) {
if (empty($auth_user)) { if ( empty($auth_user) ) {
$auth_user = $_POST['user']; $auth_user = $_POST['user'];
} }
@ -1556,7 +1555,7 @@ class MainWP_Child {
MainWP_Child_Links_Checker::Instance()->init(); MainWP_Child_Links_Checker::Instance()->init();
MainWP_Child_WPvivid_BackupRestore::Instance()->init(); MainWP_Child_WPvivid_BackupRestore::Instance()->init();
global $_wp_submenu_nopriv; global $_wp_submenu_nopriv;
if ($_wp_submenu_nopriv === null) { if ( $_wp_submenu_nopriv === null ) {
$_wp_submenu_nopriv = array(); // fix warning $_wp_submenu_nopriv = array(); // fix warning
} }
@ -1574,7 +1573,7 @@ class MainWP_Child {
define( 'DOING_CRON', true ); define( 'DOING_CRON', true );
self::fix_for_custom_themes(); self::fix_for_custom_themes();
call_user_func( array( $this, $this->callableFunctionsNoAuth[ $_POST['function'] ] ) ); call_user_func( array( $this, $this->callableFunctionsNoAuth[ $_POST['function'] ] ) );
} elseif (isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) && ! isset($this->callableFunctions[ $_POST['function'] ]) && ! isset( $this->callableFunctionsNoAuth[ $_POST['function'] ]) ) { } elseif ( isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) && ! isset($this->callableFunctions[ $_POST['function'] ]) && ! isset( $this->callableFunctionsNoAuth[ $_POST['function'] ]) ) {
MainWP_Helper::error( __( 'Required version has not been detected. Please, make sure that you are using the latest version of the MainWP Child plugin on your site.', 'mainwp-child' ) ); MainWP_Helper::error( __( 'Required version has not been detected. Please, make sure that you are using the latest version of the MainWP Child plugin on your site.', 'mainwp-child' ) );
} }
@ -1637,7 +1636,7 @@ class MainWP_Child {
$auth = hash_equals( md5( $func . $nonce . get_option( 'mainwp_child_nossl_key' ) ), base64_decode( $signature ) ); $auth = hash_equals( md5( $func . $nonce . get_option( 'mainwp_child_nossl_key' ) ), base64_decode( $signature ) );
} else { } else {
$auth = openssl_verify( $func . $nonce, base64_decode( $signature ), base64_decode( get_option( 'mainwp_child_pubkey' ) ) ); $auth = openssl_verify( $func . $nonce, base64_decode( $signature ), base64_decode( get_option( 'mainwp_child_pubkey' ) ) );
if ($auth !== 1) { if ( $auth !== 1 ) {
$auth = false; $auth = false;
} }
} }
@ -1747,7 +1746,7 @@ class MainWP_Child {
) ); ) );
if ( is_wp_error( $result ) ) { if ( is_wp_error( $result ) ) {
if ( true == $ssl_verify && strpos( $url, 'https://' ) === 0) { if ( true == $ssl_verify && strpos( $url, 'https://' ) === 0 ) {
// retry // retry
add_filter( 'http_request_args', array( &$this, 'noSSLFilterFunction' ), 99, 2 ); add_filter( 'http_request_args', array( &$this, 'noSSLFilterFunction' ), 99, 2 );
$ssl_verify = false; $ssl_verify = false;
@ -1806,7 +1805,7 @@ class MainWP_Child {
do_action( 'mainwp_child_installPluginTheme', $args ); do_action( 'mainwp_child_installPluginTheme', $args );
if ( isset( $_POST['activatePlugin'] ) && 'yes' === $_POST['activatePlugin'] ) { if ( isset( $_POST['activatePlugin'] ) && 'yes' === $_POST['activatePlugin'] ) {
// to fix activate issue // to fix activate issue
if ('quotes-collection/quotes-collection.php' == $args['slug']) { if ( 'quotes-collection/quotes-collection.php' == $args['slug'] ) {
activate_plugin( $path . $fileName, '', false, true ); activate_plugin( $path . $fileName, '', false, true );
} else { } else {
activate_plugin( $path . $fileName, '' /* false, true */ ); activate_plugin( $path . $fileName, '' /* false, true */ );
@ -2039,8 +2038,8 @@ class MainWP_Child {
} }
// to fix: smart-manager-for-wp-e-commerce update // to fix: smart-manager-for-wp-e-commerce update
if (in_array('smart-manager-for-wp-e-commerce/smart-manager.php', $plugins)) { 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')) { 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/smart-manager.php';
include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php'; include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php';
} }
@ -2091,7 +2090,7 @@ class MainWP_Child {
// try to fix if that is premiums update // try to fix if that is premiums update
$api = apply_filters( 'plugins_api', false, 'plugin_information', array( 'slug' => $plugin ) ); $api = apply_filters( 'plugins_api', false, 'plugin_information', array( 'slug' => $plugin ) );
if ( ! is_wp_error( $api ) && ! empty($api)) { if ( ! is_wp_error( $api ) && ! empty($api) ) {
if ( isset($api->download_link) ) { if ( isset($api->download_link) ) {
$res = $upgrader->install($api->download_link); $res = $upgrader->install($api->download_link);
if ( ! is_wp_error( $res ) && ! ( is_null( $res ) ) ) { if ( ! is_wp_error( $res ) && ! ( is_null( $res ) ) ) {
@ -2099,8 +2098,7 @@ class MainWP_Child {
} }
} }
} }
} else {
} else {
$information['upgrades'][ $plugin ] = true; $information['upgrades'][ $plugin ] = true;
// to fix logging update // to fix logging update
// if (isset($information['plugin_updates']) && isset($information['plugin_updates'][$plugin])) { // if (isset($information['plugin_updates']) && isset($information['plugin_updates'][$plugin])) {
@ -2119,7 +2117,7 @@ class MainWP_Child {
$failed = false; $failed = false;
} }
if ($failed) { if ( $failed ) {
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
} }
} }
@ -2233,7 +2231,7 @@ class MainWP_Child {
$failed = false; $failed = false;
} }
if ($failed) { if ( $failed ) {
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) ); MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
} }
@ -2249,7 +2247,6 @@ class MainWP_Child {
'hookFixOptimizePressThemeUpdate', 'hookFixOptimizePressThemeUpdate',
), 99 ); ), 99 );
} }
} }
remove_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ), 10 ); remove_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ), 10 );
@ -2366,7 +2363,7 @@ class MainWP_Child {
} }
} }
if ($pre == false) { if ( $pre == false ) {
return $false; return $false;
} }
@ -2390,7 +2387,7 @@ class MainWP_Child {
} }
} }
if ($pre == false) { if ( $pre == false ) {
return $false; return $false;
} }
@ -2504,13 +2501,13 @@ class MainWP_Child {
} }
$others = array(); $others = array();
if ( isset( $_POST['featured_image_data'] ) && ! empty($_POST['featured_image_data'])) { if ( isset( $_POST['featured_image_data'] ) && ! empty($_POST['featured_image_data']) ) {
$others['featured_image_data'] = unserialize(base64_decode( $_POST['featured_image_data'] )); $others['featured_image_data'] = unserialize(base64_decode( $_POST['featured_image_data'] ));
} }
$res = MainWP_Helper::createPost( $new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags, $others ); $res = MainWP_Helper::createPost( $new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags, $others );
if (is_array($res) && isset($res['error'])) { if ( is_array($res) && isset($res['error']) ) {
MainWP_Helper::error( $res['error'] ); MainWP_Helper::error( $res['error'] );
} }
@ -2602,7 +2599,7 @@ class MainWP_Child {
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} }
function get_post_edit( $id) { function get_post_edit( $id ) {
$post = get_post( $id ); $post = get_post( $id );
if ( $post ) { if ( $post ) {
$categoryObjects = get_the_category( $post->ID ); $categoryObjects = get_the_category( $post->ID );
@ -2689,7 +2686,7 @@ class MainWP_Child {
return false; return false;
} }
function get_page_edit( $id) { function get_page_edit( $id ) {
$post = get_post( $id ); $post = get_post( $id );
if ( $post ) { if ( $post ) {
$post_custom = get_post_custom( $id ); $post_custom = get_post_custom( $id );
@ -2779,21 +2776,21 @@ class MainWP_Child {
wp_update_user( $my_user ); wp_update_user( $my_user );
} elseif ( 'edit' === $action ) { } elseif ( 'edit' === $action ) {
$user_data = $this->get_user_to_edit($userId); $user_data = $this->get_user_to_edit($userId);
if ( ! empty($user_data)) { if ( ! empty($user_data) ) {
$information['user_data'] = $user_data; $information['user_data'] = $user_data;
} else { } else {
$failed = true; $failed = true;
} }
} elseif ( 'update_user' === $action ) { } elseif ( 'update_user' === $action ) {
$my_user = $_POST['extra']; $my_user = $_POST['extra'];
if (is_array($my_user)) { if ( is_array($my_user) ) {
foreach ($my_user as $idx => $val) { foreach ( $my_user as $idx => $val ) {
if ($val === 'donotupdate' || ( empty($val) && $idx !== 'role' )) { if ( $val === 'donotupdate' || ( empty($val) && $idx !== 'role' ) ) {
unset($my_user[ $idx ]); unset($my_user[ $idx ]);
} }
} }
$result = $this->edit_user( $userId, $my_user ); $result = $this->edit_user( $userId, $my_user );
if (is_array($result) && isset($result['error'])) { if ( is_array($result) && isset($result['error']) ) {
$information['error'] = $result['error']; $information['error'] = $result['error'];
} }
} else { } else {
@ -2803,21 +2800,20 @@ class MainWP_Child {
$failed = true; $failed = true;
} }
if ($failed) { if ( $failed ) {
$information['status'] = 'FAIL'; $information['status'] = 'FAIL';
} }
if ( ! isset( $information['status'] ) && ! isset($information['error']) ) { if ( ! isset( $information['status'] ) && ! isset($information['error']) ) {
$information['status'] = 'SUCCESS'; $information['status'] = 'SUCCESS';
if ('update_user' === $action && isset($_POST['optimize']) && ! empty($_POST['optimize'])) { if ( 'update_user' === $action && isset($_POST['optimize']) && ! empty($_POST['optimize']) ) {
$information['users'] = $this->get_all_users_int(500); // to fix $information['users'] = $this->get_all_users_int(500); // to fix
} }
} }
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} }
function edit_user( $user_id, $data) { function edit_user( $user_id, $data ) {
$wp_roles = wp_roles(); $wp_roles = wp_roles();
$user = new stdClass(); $user = new stdClass();
@ -2882,7 +2878,7 @@ class MainWP_Child {
if ( isset( $data['last_name'] ) ) { if ( isset( $data['last_name'] ) ) {
$user->last_name = sanitize_text_field( $data['last_name'] ); $user->last_name = sanitize_text_field( $data['last_name'] );
} }
if ( isset( $data['nickname'] ) && ! empty($data['nickname'])) { if ( isset( $data['nickname'] ) && ! empty($data['nickname']) ) {
$user->nickname = sanitize_text_field( $data['nickname'] ); $user->nickname = sanitize_text_field( $data['nickname'] );
} }
if ( isset( $data['display_name'] ) ) { if ( isset( $data['display_name'] ) ) {
@ -2901,7 +2897,7 @@ class MainWP_Child {
do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) ); do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) );
if ( ! empty($pass1) || ! empty($pass2)) { if ( ! empty($pass1) || ! empty($pass2) ) {
// Check for blank password when adding a user. // Check for blank password when adding a user.
if ( ! $update && empty( $pass1 ) ) { if ( ! $update && empty( $pass1 ) ) {
$errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter a password.' ), array( 'form-field' => 'pass1' ) ); $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter a password.' ), array( 'form-field' => 'pass1' ) );
@ -2948,7 +2944,6 @@ class MainWP_Child {
if ( is_string( $message ) ) { if ( is_string( $message ) ) {
$error_str .= ' ' . esc_html( strip_tags( $message ) ); $error_str .= ' ' . esc_html( strip_tags( $message ) );
} }
} }
return array( 'error' => $error_str ); return array( 'error' => $error_str );
} }
@ -2963,7 +2958,7 @@ class MainWP_Child {
$profileuser = get_user_to_edit($user_id); $profileuser = get_user_to_edit($user_id);
$edit_data = array(); $edit_data = array();
if (is_object($profileuser)) { if ( is_object($profileuser) ) {
$user_roles = array_intersect( array_values( $profileuser->roles ), array_keys( get_editable_roles() ) ); $user_roles = array_intersect( array_values( $profileuser->roles ), array_keys( get_editable_roles() ) );
$user_role = reset( $user_roles ); $user_role = reset( $user_roles );
$edit_data['role'] = $user_role; $edit_data['role'] = $user_role;
@ -3097,7 +3092,7 @@ class MainWP_Child {
$new_user = maybe_unserialize( base64_decode( $_POST['new_user'] ) ); $new_user = maybe_unserialize( base64_decode( $_POST['new_user'] ) );
$send_password = $_POST['send_password']; $send_password = $_POST['send_password'];
// check role existed // check role existed
if (isset( $new_user['role'] )) { if ( isset( $new_user['role'] ) ) {
if ( ! get_role( $new_user['role'] ) ) { if ( ! get_role( $new_user['role'] ) ) {
$new_user['role'] = 'subscriber'; $new_user['role'] = 'subscriber';
} }
@ -3831,7 +3826,7 @@ class MainWP_Child {
} }
// to fix incorrect info // to fix incorrect info
if ( ! property_exists( $plugin_update, 'update' ) || ! property_exists( $plugin_update->update, 'new_version' ) || empty($plugin_update->update->new_version)) { if ( ! property_exists( $plugin_update, 'update' ) || ! property_exists( $plugin_update->update, 'new_version' ) || empty($plugin_update->update->new_version) ) {
continue; continue;
} }
@ -3846,7 +3841,7 @@ class MainWP_Child {
// to fix premium plugs update // to fix premium plugs update
$cached_plugins_update = get_site_transient( 'mainwp_update_plugins_cached' ); $cached_plugins_update = get_site_transient( 'mainwp_update_plugins_cached' );
if ( is_array( $cached_plugins_update ) && ( count( $cached_plugins_update ) > 0 ) ) { if ( is_array( $cached_plugins_update ) && ( count( $cached_plugins_update ) > 0 ) ) {
if ( ! isset($information['plugin_updates'])) { if ( ! isset($information['plugin_updates']) ) {
$information['plugin_updates'] = array(); $information['plugin_updates'] = array();
} }
foreach ( $cached_plugins_update as $slug => $plugin_update ) { foreach ( $cached_plugins_update as $slug => $plugin_update ) {
@ -3861,8 +3856,7 @@ class MainWP_Child {
} else { } else {
continue; continue;
} }
}
}
if ( ! isset( $information['plugin_updates'][ $slug ] ) ) { if ( ! isset( $information['plugin_updates'][ $slug ] ) ) {
$information['plugin_updates'][ $slug ] = $plugin_update; $information['plugin_updates'][ $slug ] = $plugin_update;
@ -3895,7 +3889,7 @@ class MainWP_Child {
// to fix premium themes update // to fix premium themes update
$cached_themes_update = get_site_transient( 'mainwp_update_themes_cached' ); $cached_themes_update = get_site_transient( 'mainwp_update_themes_cached' );
if ( is_array( $cached_themes_update ) && ( count( $cached_themes_update ) > 0 ) ) { if ( is_array( $cached_themes_update ) && ( count( $cached_themes_update ) > 0 ) ) {
if ( ! isset($information['theme_updates'])) { if ( ! isset($information['theme_updates']) ) {
$information['theme_updates'] = array(); $information['theme_updates'] = array();
} }
@ -3914,7 +3908,7 @@ class MainWP_Child {
$translation_updates = wp_get_translation_updates(); $translation_updates = wp_get_translation_updates();
if ( ! empty( $translation_updates ) ) { if ( ! empty( $translation_updates ) ) {
$information['translation_updates'] = array(); $information['translation_updates'] = array();
foreach ($translation_updates as $translation_update) { foreach ( $translation_updates as $translation_update ) {
$new_translation_update = array( $new_translation_update = array(
'type' => $translation_update->type, 'type' => $translation_update->type,
'slug' => $translation_update->slug, 'slug' => $translation_update->slug,
@ -3944,16 +3938,16 @@ class MainWP_Child {
$recent_number = 5; $recent_number = 5;
if (isset($_POST) && isset( $_POST['recent_number'] )) { if ( isset($_POST) && isset( $_POST['recent_number'] ) ) {
$recent_number = $_POST['recent_number']; $recent_number = $_POST['recent_number'];
if ($recent_number != get_option('mainwp_child_recent_number', 5)) { if ( $recent_number != get_option('mainwp_child_recent_number', 5) ) {
update_option( 'mainwp_child_recent_number', $recent_number ); update_option( 'mainwp_child_recent_number', $recent_number );
} }
} else { } else {
$recent_number = get_option('mainwp_child_recent_number', 5); $recent_number = get_option('mainwp_child_recent_number', 5);
} }
if ($recent_number <= 0 || $recent_number > 30) { if ( $recent_number <= 0 || $recent_number > 30 ) {
$recent_number = 5; $recent_number = 5;
} }
@ -4019,7 +4013,7 @@ class MainWP_Child {
$get_file_size = apply_filters('mainwp-child-get-total-size', true); $get_file_size = apply_filters('mainwp-child-get-total-size', true);
if ( $get_file_size && isset( $_POST['cloneSites'] ) && ( '0' !== $_POST['cloneSites'] ) ) { if ( $get_file_size && isset( $_POST['cloneSites'] ) && ( '0' !== $_POST['cloneSites'] ) ) {
$max_exe = ini_get( 'max_execution_time' ); // to fix issue of some hosts have limit of execution time $max_exe = ini_get( 'max_execution_time' ); // to fix issue of some hosts have limit of execution time
if ($max_exe > 20) { if ( $max_exe > 20 ) {
$information['totalsize'] = $this->getTotalFileSize(); $information['totalsize'] = $this->getTotalFileSize();
} }
} }
@ -4037,7 +4031,7 @@ class MainWP_Child {
$information['users'] = $this->get_all_users_int(500); // to fix $information['users'] = $this->get_all_users_int(500); // to fix
} }
if (isset($_POST['primaryBackup']) && ! empty($_POST['primaryBackup'])) { if ( isset($_POST['primaryBackup']) && ! empty($_POST['primaryBackup']) ) {
$primary_bk = $_POST['primaryBackup']; $primary_bk = $_POST['primaryBackup'];
$information['primaryLasttimeBackup'] = MainWP_Helper::get_lasttime_backup($primary_bk); $information['primaryLasttimeBackup'] = MainWP_Helper::get_lasttime_backup($primary_bk);
} }
@ -4054,9 +4048,9 @@ class MainWP_Child {
$information['plugins_outdate_info'] = MainWP_Child_Plugins_Check::Instance()->get_plugins_outdate_info(); $information['plugins_outdate_info'] = MainWP_Child_Plugins_Check::Instance()->get_plugins_outdate_info();
$information['themes_outdate_info'] = MainWP_Child_Themes_Check::Instance()->get_themes_outdate_info(); $information['themes_outdate_info'] = MainWP_Child_Themes_Check::Instance()->get_themes_outdate_info();
if (isset( $_POST['user'] )) { if ( isset( $_POST['user'] ) ) {
$user = get_user_by( 'login', $_POST['user'] ); $user = get_user_by( 'login', $_POST['user'] );
if ( $user && property_exists($user, 'ID') && $user->ID) { if ( $user && property_exists($user, 'ID') && $user->ID ) {
$information['admin_nicename'] = $user->data->user_nicename; $information['admin_nicename'] = $user->data->user_nicename;
$information['admin_useremail'] = $user->data->user_email; $information['admin_useremail'] = $user->data->user_email;
} }
@ -4064,7 +4058,7 @@ class MainWP_Child {
try { try {
do_action('mainwp_child_site_stats'); do_action('mainwp_child_site_stats');
} catch (Exception $e) { } catch ( Exception $e ) {
} }
@ -4083,7 +4077,7 @@ class MainWP_Child {
try { try {
$information = apply_filters( 'mainwp-site-sync-others-data', $information, $othersData ); $information = apply_filters( 'mainwp-site-sync-others-data', $information, $othersData );
} catch (Exception $e) { } catch ( Exception $e ) {
// do not exit // do not exit
} }
} }
@ -4130,9 +4124,9 @@ class MainWP_Child {
} }
} }
if ($parse_page) { if ( $parse_page ) {
// try to parse page // try to parse page
if (empty($favi_url)) { if ( empty($favi_url) ) {
$request = wp_remote_get( $site_url, array( 'timeout' => 50 ) ); $request = wp_remote_get( $site_url, array( 'timeout' => 50 ) );
$favi = ''; $favi = '';
if ( is_array( $request ) && isset( $request['body'] ) ) { if ( is_array( $request ) && isset( $request['body'] ) ) {
@ -4148,9 +4142,9 @@ class MainWP_Child {
} }
if ( ! empty( $favi ) ) { if ( ! empty( $favi ) ) {
if ( false === strpos( $favi, 'http' )) { if ( false === strpos( $favi, 'http' ) ) {
if (0 === strpos( $favi, '//' )) { if ( 0 === strpos( $favi, '//' ) ) {
if (0 === strpos( $site_url, 'https' )) { if ( 0 === strpos( $site_url, 'https' ) ) {
$favi_url = 'https:' . $favi; $favi_url = 'https:' . $favi;
} else { } else {
$favi_url = 'http:' . $favi; $favi_url = 'http:' . $favi;
@ -4295,15 +4289,15 @@ class MainWP_Child {
*/ */
$wp_seo_enabled = false; $wp_seo_enabled = false;
if ( isset( $_POST['WPSEOEnabled'] ) && $_POST['WPSEOEnabled']) { if ( isset( $_POST['WPSEOEnabled'] ) && $_POST['WPSEOEnabled'] ) {
if (is_plugin_active('wordpress-seo/wp-seo.php') && class_exists('WPSEO_Link_Column_Count') && class_exists('WPSEO_Meta')) { if ( is_plugin_active('wordpress-seo/wp-seo.php') && class_exists('WPSEO_Link_Column_Count') && class_exists('WPSEO_Meta') ) {
$wp_seo_enabled = true; $wp_seo_enabled = true;
} }
} }
$posts = get_posts( $args ); $posts = get_posts( $args );
if ( is_array( $posts ) ) { if ( is_array( $posts ) ) {
if ($wp_seo_enabled) { if ( $wp_seo_enabled ) {
$post_ids = array(); $post_ids = array();
foreach ( $posts as $post ) { foreach ( $posts as $post ) {
$post_ids[] = $post->ID; $post_ids[] = $post->ID;
@ -4326,7 +4320,7 @@ class MainWP_Child {
$outPost['dts'] = strtotime( $post->post_modified_gmt ); $outPost['dts'] = strtotime( $post->post_modified_gmt );
} }
if ($post->post_status == 'future') { if ( $post->post_status == 'future' ) {
$outPost['dts'] = strtotime( $post->post_date_gmt ); $outPost['dts'] = strtotime( $post->post_date_gmt );
} }
@ -4366,7 +4360,7 @@ class MainWP_Child {
} }
} }
if ($wp_seo_enabled) { if ( $wp_seo_enabled ) {
$post_id = $post->ID; $post_id = $post->ID;
$outPost['seo_data'] = array( $outPost['seo_data'] = array(
'count_seo_links' => $link_count->get( $post_id, 'internal_link_count' ), 'count_seo_links' => $link_count->get( $post_id, 'internal_link_count' ),
@ -4577,23 +4571,23 @@ class MainWP_Child {
} else { } else {
if ( isset( $_POST['keyword'] ) ) { if ( isset( $_POST['keyword'] ) ) {
$search_on = isset($_POST['search_on']) ? $_POST['search_on'] : ''; $search_on = isset($_POST['search_on']) ? $_POST['search_on'] : '';
if ($search_on == 'title') { if ( $search_on == 'title' ) {
$this->posts_where_suffix .= " AND ( $wpdb->posts.post_title LIKE '%" . $_POST['keyword'] . "%' )"; $this->posts_where_suffix .= " AND ( $wpdb->posts.post_title LIKE '%" . $_POST['keyword'] . "%' )";
} elseif ($search_on == 'content') { } elseif ( $search_on == 'content' ) {
$this->posts_where_suffix .= " AND ($wpdb->posts.post_content LIKE '%" . $_POST['keyword'] . "%' )"; $this->posts_where_suffix .= " AND ($wpdb->posts.post_content LIKE '%" . $_POST['keyword'] . "%' )";
} else { } else {
$this->posts_where_suffix .= " AND ($wpdb->posts.post_content LIKE '%" . $_POST['keyword'] . "%' OR $wpdb->posts.post_title LIKE '%" . $_POST['keyword'] . "%' )"; $this->posts_where_suffix .= " AND ($wpdb->posts.post_content LIKE '%" . $_POST['keyword'] . "%' OR $wpdb->posts.post_title LIKE '%" . $_POST['keyword'] . "%' )";
} }
} }
if ( isset( $_POST['dtsstart'] ) && '' !== $_POST['dtsstart'] ) { if ( isset( $_POST['dtsstart'] ) && '' !== $_POST['dtsstart'] ) {
if ($where_post_date) { if ( $where_post_date ) {
$this->posts_where_suffix .= " AND $wpdb->posts.post_date > '" . $_POST['dtsstart'] . "'"; $this->posts_where_suffix .= " AND $wpdb->posts.post_date > '" . $_POST['dtsstart'] . "'";
} else { } else {
$this->posts_where_suffix .= " AND $wpdb->posts.post_modified > '" . $_POST['dtsstart'] . "'"; $this->posts_where_suffix .= " AND $wpdb->posts.post_modified > '" . $_POST['dtsstart'] . "'";
} }
} }
if ( isset( $_POST['dtsstop'] ) && '' !== $_POST['dtsstop'] ) { if ( isset( $_POST['dtsstop'] ) && '' !== $_POST['dtsstop'] ) {
if ($where_post_date) { if ( $where_post_date ) {
$this->posts_where_suffix .= " AND $wpdb->posts.post_date < '" . $_POST['dtsstop'] . "'"; $this->posts_where_suffix .= " AND $wpdb->posts.post_date < '" . $_POST['dtsstop'] . "'";
} else { } else {
$this->posts_where_suffix .= " AND $wpdb->posts.post_modified < '" . $_POST['dtsstop'] . "'"; $this->posts_where_suffix .= " AND $wpdb->posts.post_modified < '" . $_POST['dtsstop'] . "'";
@ -4690,9 +4684,9 @@ class MainWP_Child {
$outComment['author_url'] = get_comment_author_url( $comment->comment_ID ); $outComment['author_url'] = get_comment_author_url( $comment->comment_ID );
$outComment['author_ip'] = get_comment_author_IP( $comment->comment_ID ); $outComment['author_ip'] = get_comment_author_IP( $comment->comment_ID );
$outComment['author_email'] = $email = apply_filters( 'comment_email', $comment->comment_author_email ); $outComment['author_email'] = $email = apply_filters( 'comment_email', $comment->comment_author_email );
// if ( ( ! empty( $outComment['author_email'] ) ) && ( '@' !== $outComment['author_email'] ) ) { // if ( ( ! empty( $outComment['author_email'] ) ) && ( '@' !== $outComment['author_email'] ) ) {
// $outComment['author_email'] = '<a href="mailto:' . $outComment['author_email'] . '">' . $outComment['author_email'] . '</a>'; // $outComment['author_email'] = '<a href="mailto:' . $outComment['author_email'] . '">' . $outComment['author_email'] . '</a>';
// } // }
$outComment['postId'] = $comment->comment_post_ID; $outComment['postId'] = $comment->comment_post_ID;
$outComment['postName'] = $post->post_title; $outComment['postName'] = $post->post_title;
$outComment['comment_count'] = $post->comment_count; $outComment['comment_count'] = $post->comment_count;
@ -4739,7 +4733,7 @@ class MainWP_Child {
$theme_name = wp_get_theme()->get( 'Name' ); $theme_name = wp_get_theme()->get( 'Name' );
$themes = explode( '||', $theme ); $themes = explode( '||', $theme );
if (count($themes) == 1) { if ( count($themes) == 1 ) {
$themeToDelete = current($themes); $themeToDelete = current($themes);
if ( $themeToDelete == $theme_name ) { if ( $themeToDelete == $theme_name ) {
$information['error'] = 'IsActivatedTheme'; $information['error'] = 'IsActivatedTheme';
@ -4827,7 +4821,7 @@ class MainWP_Child {
$thePlugin = get_plugin_data( $plugin ); $thePlugin = get_plugin_data( $plugin );
if ( null !== $thePlugin && '' !== $thePlugin ) { if ( null !== $thePlugin && '' !== $thePlugin ) {
// to fix activate issue // to fix activate issue
if ('quotes-collection/quotes-collection.php' == $plugin) { if ( 'quotes-collection/quotes-collection.php' == $plugin ) {
activate_plugin( $plugin, '', false, true ); activate_plugin( $plugin, '', false, true );
// do_action( 'activate_plugin', $plugin, null ); // do_action( 'activate_plugin', $plugin, null );
} else { } else {
@ -4870,7 +4864,7 @@ class MainWP_Child {
foreach ( $plugins as $idx => $plugin ) { foreach ( $plugins as $idx => $plugin ) {
if ( $plugin !== $this->plugin_slug ) { if ( $plugin !== $this->plugin_slug ) {
if ( isset( $all_plugins[ $plugin ] ) ) { if ( isset( $all_plugins[ $plugin ] ) ) {
if (is_plugin_active($plugin)) { if ( is_plugin_active($plugin) ) {
$thePlugin = get_plugin_data( $plugin ); $thePlugin = get_plugin_data( $plugin );
if ( null !== $thePlugin && '' !== $thePlugin ) { if ( null !== $thePlugin && '' !== $thePlugin ) {
deactivate_plugins( $plugin ); deactivate_plugins( $plugin );
@ -4962,7 +4956,7 @@ class MainWP_Child {
return $rslt; return $rslt;
} }
function get_all_users( $return = false) { function get_all_users( $return = false ) {
$roles = explode( ',', $_POST['role'] ); $roles = explode( ',', $_POST['role'] );
$allusers = array(); $allusers = array();
if ( is_array( $roles ) ) { if ( is_array( $roles ) ) {
@ -4985,17 +4979,17 @@ class MainWP_Child {
} }
} }
} }
if ($return) { if ( $return ) {
return $allusers; return $allusers;
} }
MainWP_Helper::write( $allusers ); MainWP_Helper::write( $allusers );
} }
function get_all_users_int( $number = false) { function get_all_users_int( $number = false ) {
$allusers = array(); $allusers = array();
$params = array(); $params = array();
if ($number) { if ( $number ) {
$params['number'] = $number; $params['number'] = $number;
} }
@ -5027,10 +5021,10 @@ class MainWP_Child {
$search_user_role = array(); $search_user_role = array();
$check_users_role = false; $check_users_role = false;
if (isset($_POST['role']) && ! empty($_POST['role'])) { if ( isset($_POST['role']) && ! empty($_POST['role']) ) {
$check_users_role = true; $check_users_role = true;
$all_users_role = $this->get_all_users(true); $all_users_role = $this->get_all_users(true);
foreach ($all_users_role as $user) { foreach ( $all_users_role as $user ) {
$search_user_role[] = $user['id']; $search_user_role[] = $user['id'];
} }
unset($all_users_role); unset($all_users_role);
@ -5054,8 +5048,8 @@ class MainWP_Child {
) ); ) );
if ( ! empty( $user_query->results ) ) { if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $new_user ) { foreach ( $user_query->results as $new_user ) {
if ($check_users_role) { if ( $check_users_role ) {
if ( ! in_array($new_user->ID, $search_user_role )) { if ( ! in_array($new_user->ID, $search_user_role ) ) {
continue; continue;
} }
} }
@ -5110,7 +5104,7 @@ class MainWP_Child {
function activation() { function activation() {
$mu_plugin_enabled = apply_filters('mainwp_child_mu_plugin_enabled', false); $mu_plugin_enabled = apply_filters('mainwp_child_mu_plugin_enabled', false);
if ($mu_plugin_enabled) { if ( $mu_plugin_enabled ) {
return; return;
} }
@ -5135,10 +5129,10 @@ class MainWP_Child {
} }
} }
function deactivation( $deact = true) { function deactivation( $deact = true ) {
$mu_plugin_enabled = apply_filters('mainwp_child_mu_plugin_enabled', false); $mu_plugin_enabled = apply_filters('mainwp_child_mu_plugin_enabled', false);
if ($mu_plugin_enabled) { if ( $mu_plugin_enabled ) {
return; return;
} }
@ -5160,7 +5154,7 @@ class MainWP_Child {
} }
} }
if ($deact) { if ( $deact ) {
do_action( 'mainwp_child_deactivation' ); do_action( 'mainwp_child_deactivation' );
} }
} }
@ -5270,7 +5264,7 @@ class MainWP_Child {
// to fix for window host, performance not good? // to fix for window host, performance not good?
if ( class_exists( 'RecursiveIteratorIterator' ) ) { if ( class_exists( 'RecursiveIteratorIterator' ) ) {
$size = 0; $size = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) { foreach ( new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file ) {
$size += $file->getSize(); $size += $file->getSize();
} }
if ( $size && MainWP_Helper::ctype_digit( $size ) ) { if ( $size && MainWP_Helper::ctype_digit( $size ) ) {

View file

@ -339,65 +339,63 @@ class MainWP_Client_Report {
if ( ! is_array( $records ) ) { if ( ! is_array( $records ) ) {
$records = array(); $records = array();
} }
// to fix invalid data, or skip records // to fix invalid data, or skip records
$skip_records = array(); $skip_records = array();
// to fix for incorrect posts created logging // to fix for incorrect posts created logging
// query created posts from WP posts data to simulate records logging for created posts // query created posts from WP posts data to simulate records logging for created posts
if ( isset($_POST['direct_posts']) && !empty($_POST['direct_posts']) ) { if ( isset($_POST['direct_posts']) && ! empty($_POST['direct_posts']) ) {
$query_string = array( $query_string = array(
'post_type' => 'post', 'post_type' => 'post',
'date_query' => array( 'date_query' => array(
'column' => 'post_date', 'column' => 'post_date',
'after' => $args['date_from'], 'after' => $args['date_from'],
'before' => $args['date_to'] 'before' => $args['date_to'],
), ),
'post_status' => 'publish' 'post_status' => 'publish',
); );
$records_created_posts = query_posts( $query_string ); $records_created_posts = query_posts( $query_string );
if ($records_created_posts) { if ( $records_created_posts ) {
for( $i = 0; $i < count($records); $i++ ) { for ( $i = 0; $i < count($records); $i++ ) {
$record = $records[$i]; $record = $records[ $i ];
if ($record->connector == 'posts' && $record->context == 'post' && $record->action == 'created') { if ( $record->connector == 'posts' && $record->context == 'post' && $record->action == 'created' ) {
if (!in_array($record->ID, $skip_records)) { if ( ! in_array($record->ID, $skip_records) ) {
$skip_records[] = $record->ID; // so avoid this created logging, will use logging query from posts data $skip_records[] = $record->ID; // so avoid this created logging, will use logging query from posts data
} }
} }
} }
$post_authors = array(); $post_authors = array();
foreach( $records_created_posts as $_post){ foreach ( $records_created_posts as $_post ) {
$au_id = $_post->post_author; $au_id = $_post->post_author;
if ( !isset($post_authors[$au_id]) ) { if ( ! isset($post_authors[ $au_id ]) ) {
$au = get_user_by( 'id', $au_id ); $au = get_user_by( 'id', $au_id );
$post_authors[$au_id] = $au->display_name; $post_authors[ $au_id ] = $au->display_name;
} }
$au_name = $post_authors[$au_id]; $au_name = $post_authors[ $au_id ];
//simulate logging created posts record // simulate logging created posts record
$stdObj = new stdClass; $stdObj = new stdClass();
$stdObj->ID = 0; // simulate ID value $stdObj->ID = 0; // simulate ID value
$stdObj->connector = 'posts'; $stdObj->connector = 'posts';
$stdObj->context = 'post'; $stdObj->context = 'post';
$stdObj->action = 'created'; $stdObj->action = 'created';
$stdObj->created = $_post->post_date; $stdObj->created = $_post->post_date;
$stdObj->meta = array( $stdObj->meta = array(
'post_title' => array( $_post->post_title ), 'post_title' => array( $_post->post_title ),
'user_meta' => array( $au_name ) 'user_meta' => array( $au_name ),
); );
$records[] = $stdObj; $records[] = $stdObj;
} }
} }
} }
if ( isset( $other_tokens['header'] ) && is_array( $other_tokens['header'] ) ) { if ( isset( $other_tokens['header'] ) && is_array( $other_tokens['header'] ) ) {
$other_tokens_data['header'] = $this->get_other_tokens_data( $records, $other_tokens['header'], $skip_records); $other_tokens_data['header'] = $this->get_other_tokens_data( $records, $other_tokens['header'], $skip_records);
} }
@ -484,22 +482,23 @@ class MainWP_Client_Report {
case 'count': case 'count':
$count = 0; $count = 0;
foreach ( $records as $record ) { foreach ( $records as $record ) {
// check connector // check connector
if ( $record->connector == 'editor' ) { if ( $record->connector == 'editor' ) {
if ( !in_array( $context, array('plugins', 'themes') ) || $action !== 'updated' ) if ( ! in_array( $context, array( 'plugins', 'themes' ) ) || $action !== 'updated' ) {
continue; continue;
} else if ( $connector !== $record->connector ) { }
} elseif ( $connector !== $record->connector ) {
continue; continue;
} }
// check context // check context
if ( $context == 'comments' ) { // multi values if ( $context == 'comments' ) { // multi values
$comment_contexts = array( 'post', 'page' ); $comment_contexts = array( 'post', 'page' );
if ( ! in_array( $record->context, $comment_contexts ) ) { if ( ! in_array( $record->context, $comment_contexts ) ) {
continue; continue;
} }
} else if ( 'post' === $context && 'created' === $action ) { } elseif ( 'post' === $context && 'created' === $action ) {
if ( in_array($record->ID, $skip_records) ) { if ( in_array($record->ID, $skip_records) ) {
continue; continue;
} }
@ -562,8 +561,8 @@ class MainWP_Client_Report {
} }
continue; continue;
} }
} }
} }
} }
$count ++; $count ++;
} }
@ -882,8 +881,8 @@ class MainWP_Client_Report {
if ( isset( $meta[ $meta_key ] ) ) { if ( isset( $meta[ $meta_key ] ) ) {
$value = $meta[ $meta_key ]; $value = $meta[ $meta_key ];
$value = ( $meta_key == 'user_meta' && isset($value[1]) ) ? $value[1] : current( $value ); // display name $value = ( $meta_key == 'user_meta' && isset($value[1]) ) ? $value[1] : current( $value ); // display name
// to compatible with old meta data // to compatible with old meta data
if ( 'author_meta' === $meta_key ) { if ( 'author_meta' === $meta_key ) {
$value = maybe_unserialize( $value ); $value = maybe_unserialize( $value );

View file

@ -2,26 +2,26 @@
class MainWP_Helper { class MainWP_Helper {
static function write( $val ) { static function write( $val ) {
if (isset( $_REQUEST['json_result'] ) && $_REQUEST['json_result'] == true) : if ( isset( $_REQUEST['json_result'] ) && $_REQUEST['json_result'] == true ) :
$output = self::safe_json_encode( $val ); $output = self::safe_json_encode( $val );
else: else :
$output = serialize( $val ); $output = serialize( $val );
endif; endif;
die( '<mainwp>' . base64_encode( $output ) . '</mainwp>'); die( '<mainwp>' . base64_encode( $output ) . '</mainwp>');
} }
public static function json_valid_check( $data ) { public static function json_valid_check( $data ) {
if (is_array( $data )) { if ( is_array( $data ) ) {
$output = array(); $output = array();
foreach ( $data as $key => $value) { foreach ( $data as $key => $value ) {
if ( is_string( $key ) ) { if ( is_string( $key ) ) {
$id = self::json_convert_string( $key ); $id = self::json_convert_string( $key );
} else { } else {
$id = $key; $id = $key;
} }
if ( is_array( $value ) || is_object( $value ) ) { if ( is_array( $value ) || is_object( $value ) ) {
$output[ $id ] = self::json_valid_check( $value ); $output[ $id ] = self::json_valid_check( $value );
} elseif ( is_string( $value ) ) { } elseif ( is_string( $value ) ) {
@ -30,9 +30,9 @@ class MainWP_Helper {
$output[ $id ] = $value; $output[ $id ] = $value;
} }
} }
} }
elseif ( is_object( $data ) ) { elseif ( is_object( $data ) ) {
$output = new stdClass; $output = new stdClass();
foreach ( $data as $key => $value ) { foreach ( $data as $key => $value ) {
if ( is_string( $key ) ) { if ( is_string( $key ) ) {
$id = self::json_convert_string( $key ); $id = self::json_convert_string( $key );
@ -47,39 +47,39 @@ class MainWP_Helper {
$output->$id = $value; $output->$id = $value;
} }
} }
} }
elseif (is_string( $data )) { elseif ( is_string( $data ) ) {
return self::json_convert_string( $data ); return self::json_convert_string( $data );
} else { } else {
return $data; return $data;
} }
return $output; return $output;
} }
public function json_convert_string( $str ) {
if ( function_exists( 'mb_convert_encoding' )) {
$encoding = mb_detect_encoding( $str, mb_detect_order(), true );
if ( $encoding ) {
return mb_convert_encoding( $str, 'UTF-8', $encoding );
} else {
return mb_convert_encoding( $str, 'UTF-8', 'UTF-8' );
}
}
return $str;
}
public static function safe_json_encode( $value, $options = 0, $depth = 512) { public function json_convert_string( $str ) {
$encoded = @json_encode($value, $options, $depth); if ( function_exists( 'mb_convert_encoding' ) ) {
if ($encoded === false && !empty( $value ) && json_last_error() == JSON_ERROR_UTF8 ) { $encoding = mb_detect_encoding( $str, mb_detect_order(), true );
$encoded = @json_encode(self::json_valid_check($value), $options, $depth); if ( $encoding ) {
return mb_convert_encoding( $str, 'UTF-8', $encoding );
} else {
return mb_convert_encoding( $str, 'UTF-8', 'UTF-8' );
}
} }
return $encoded ; return $str;
}
public static function safe_json_encode( $value, $options = 0, $depth = 512 ) {
$encoded = @json_encode($value, $options, $depth);
if ( $encoded === false && ! empty( $value ) && json_last_error() == JSON_ERROR_UTF8 ) {
$encoded = @json_encode(self::json_valid_check($value), $options, $depth);
}
return $encoded;
} }
static function close_connection( $val = null ) { static function close_connection( $val = null ) {
if (isset( $_REQUEST['json_result'] ) && $_REQUEST['json_result'] == true) : if ( isset( $_REQUEST['json_result'] ) && $_REQUEST['json_result'] == true ) :
$output = self::safe_json_encode( $val ); $output = self::safe_json_encode( $val );
else : else :
$output = serialize( $val ); $output = serialize( $val );
@ -102,7 +102,7 @@ class MainWP_Helper {
static function error( $error, $code = null ) { static function error( $error, $code = null ) {
$information['error'] = $error; $information['error'] = $error;
if (null !== $code) { if ( null !== $code ) {
$information['error_code'] = $code; $information['error_code'] = $code;
} }
self::write( $information ); self::write( $information );
@ -114,7 +114,7 @@ class MainWP_Helper {
* CSSPARSER * CSSPARSER
* Copyright (C) 2009 Peter Kröner * Copyright (C) 2009 Peter Kröner
*/ */
public static function parse_css( $css) { public static function parse_css( $css ) {
// Remove CSS-Comments // Remove CSS-Comments
$css = preg_replace('/\/\*.*?\*\//ms', '', $css); $css = preg_replace('/\/\*.*?\*\//ms', '', $css);
@ -125,14 +125,14 @@ class MainWP_Helper {
// Append the rest to $blocks // Append the rest to $blocks
array_push($blocks[0], preg_replace('/@.+?\}[^\}]*?\}/ms', '', $css)); array_push($blocks[0], preg_replace('/@.+?\}[^\}]*?\}/ms', '', $css));
$ordered = array(); $ordered = array();
for ($i = 0;$i < count($blocks[0]);$i++) { for ( $i = 0;$i < count($blocks[0]);$i++ ) {
// If @media-block, strip declaration and parenthesis // If @media-block, strip declaration and parenthesis
if (substr($blocks[0][ $i ], 0, 6) === '@media') { if ( substr($blocks[0][ $i ], 0, 6) === '@media' ) {
$ordered_key = preg_replace('/^(@media[^\{]+)\{.*\}$/ms', '$1', $blocks[0][ $i ]); $ordered_key = preg_replace('/^(@media[^\{]+)\{.*\}$/ms', '$1', $blocks[0][ $i ]);
$ordered_value = preg_replace('/^@media[^\{]+\{(.*)\}$/ms', '$1', $blocks[0][ $i ]); $ordered_value = preg_replace('/^@media[^\{]+\{(.*)\}$/ms', '$1', $blocks[0][ $i ]);
} }
// Rule-blocks of the sort @import or @font-face // Rule-blocks of the sort @import or @font-face
elseif (substr($blocks[0][ $i ], 0, 1) === '@') { elseif ( substr($blocks[0][ $i ], 0, 1) === '@' ) {
$ordered_key = $blocks[0][ $i ]; $ordered_key = $blocks[0][ $i ];
$ordered_value = $blocks[0][ $i ]; $ordered_value = $blocks[0][ $i ];
} else { } else {
@ -144,27 +144,27 @@ class MainWP_Helper {
} }
// Beginning to rebuild new slim CSS-Array // Beginning to rebuild new slim CSS-Array
foreach ($ordered as $key => $val) { foreach ( $ordered as $key => $val ) {
$new = array(); $new = array();
for ($i = 0; $i < count($val); $i++) { for ( $i = 0; $i < count($val); $i++ ) {
// Split selectors and rules and split properties and values // Split selectors and rules and split properties and values
$selector = trim($val[ $i ], " \r\n\t"); $selector = trim($val[ $i ], " \r\n\t");
if ( ! empty($selector)) { if ( ! empty($selector) ) {
if ( ! isset($new[ $selector ])) { if ( ! isset($new[ $selector ]) ) {
$new[ $selector ] = array(); $new[ $selector ] = array();
} }
$rules = explode(';', $val[ ++$i ]); $rules = explode(';', $val[ ++$i ]);
foreach ($rules as $rule) { foreach ( $rules as $rule ) {
$rule = trim($rule, " \r\n\t"); $rule = trim($rule, " \r\n\t");
if ( ! empty($rule)) { if ( ! empty($rule) ) {
$rule = array_reverse(explode(':', $rule)); $rule = array_reverse(explode(':', $rule));
$property = trim(array_pop($rule), " \r\n\t"); $property = trim(array_pop($rule), " \r\n\t");
$value = implode(':', array_reverse($rule)); $value = implode(':', array_reverse($rule));
if ( ! isset($new[ $selector ][ $property ]) || ! preg_match('/!important/', $new[ $selector ][ $property ])) { if ( ! isset($new[ $selector ][ $property ]) || ! preg_match('/!important/', $new[ $selector ][ $property ]) ) {
$new[ $selector ][ $property ] = $value; $new[ $selector ][ $property ] = $value;
} elseif (preg_match('/!important/', $new[ $selector ][ $property ]) && preg_match('/!important/', $value)) { } elseif ( preg_match('/!important/', $new[ $selector ][ $property ]) && preg_match('/!important/', $value) ) {
$new[ $selector ][ $property ] = $value; $new[ $selector ][ $property ] = $value;
} }
} }
@ -176,23 +176,23 @@ class MainWP_Helper {
$parsed = $ordered; $parsed = $ordered;
$output = ''; $output = '';
foreach ($parsed as $media => $content) { foreach ( $parsed as $media => $content ) {
if (substr($media, 0, 6) === '@media') { if ( substr($media, 0, 6) === '@media' ) {
$output .= $media . " {\n"; $output .= $media . " {\n";
$prefix = "\t"; $prefix = "\t";
} else { } else {
$prefix = ''; $prefix = '';
} }
foreach ($content as $selector => $rules) { foreach ( $content as $selector => $rules ) {
$output .= $prefix . $selector . " {\n"; $output .= $prefix . $selector . " {\n";
foreach ($rules as $property => $value) { foreach ( $rules as $property => $value ) {
$output .= $prefix . "\t" . $property . ': ' . $value; $output .= $prefix . "\t" . $property . ': ' . $value;
$output .= ";\n"; $output .= ";\n";
} }
$output .= $prefix . "}\n\n"; $output .= $prefix . "}\n\n";
} }
if (substr($media, 0, 6) === '@media') { if ( substr($media, 0, 6) === '@media' ) {
$output .= "}\n\n"; $output .= "}\n\n";
} }
} }
@ -217,7 +217,7 @@ class MainWP_Helper {
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . $filename; // Local name $local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . $filename; // Local name
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path ); $local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
//$gen_unique_fn = true; // $gen_unique_fn = true;
// to fix issue re-create new attachment // to fix issue re-create new attachment
if ( $check_file_existed ) { if ( $check_file_existed ) {
@ -227,7 +227,7 @@ class MainWP_Helper {
$result = self::get_maybe_existed_attached_id( $local_img_url ); $result = self::get_maybe_existed_attached_id( $local_img_url );
if ( is_array($result) ) { // found attachment if ( is_array($result) ) { // found attachment
$attach = current($result); $attach = current($result);
if (is_object($attach)) { if ( is_object($attach) ) {
if ( file_exists( $temporary_file ) ) { if ( file_exists( $temporary_file ) ) {
unlink( $temporary_file ); unlink( $temporary_file );
} }
@ -238,13 +238,12 @@ class MainWP_Helper {
} }
} }
} }
} else { // find in other path
} else { // find in other path
$result = self::get_maybe_existed_attached_id( $filename, false ); $result = self::get_maybe_existed_attached_id( $filename, false );
if ( is_array( $result ) ) { // found attachment if ( is_array( $result ) ) { // found attachment
$attach = current($result); $attach = current($result);
if (is_object($attach)) { if ( is_object($attach) ) {
$basedir = $upload_dir['basedir']; $basedir = $upload_dir['basedir'];
$baseurl = $upload_dir['baseurl']; $baseurl = $upload_dir['baseurl'];
$local_img_path = str_replace( $baseurl, $basedir, $attach->guid ); $local_img_path = str_replace( $baseurl, $basedir, $attach->guid );
@ -259,13 +258,13 @@ class MainWP_Helper {
); );
} }
} }
} }
} }
} }
// file exists, do not overwrite, generate unique file name // file exists, do not overwrite, generate unique file name
// this may causing of issue incorrect source of image in post content // this may causing of issue incorrect source of image in post content
if ( file_exists( $local_img_path ) ) { if ( file_exists( $local_img_path ) ) {
$local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) ); $local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) );
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path ); $local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
} }
@ -470,12 +469,12 @@ class MainWP_Helper {
if ( isset( $post_custom['_mainwp_edit_post_id'] ) && $post_custom['_mainwp_edit_post_id'] ) { if ( isset( $post_custom['_mainwp_edit_post_id'] ) && $post_custom['_mainwp_edit_post_id'] ) {
$edit_post_id = current($post_custom['_mainwp_edit_post_id']); $edit_post_id = current($post_custom['_mainwp_edit_post_id']);
} elseif (isset( $new_post['ID'] ) && $new_post['ID']) { } elseif ( isset( $new_post['ID'] ) && $new_post['ID'] ) {
$edit_post_id = $new_post['ID']; $edit_post_id = $new_post['ID'];
} }
require_once ABSPATH . 'wp-admin/includes/post.php'; require_once ABSPATH . 'wp-admin/includes/post.php';
if ($edit_post_id) { if ( $edit_post_id ) {
if ( $user_id = wp_check_post_lock( $edit_post_id ) ) { if ( $user_id = wp_check_post_lock( $edit_post_id ) ) {
$user = get_userdata( $user_id ); $user = get_userdata( $user_id );
$error = sprintf( __( 'This content is currently locked. %s is currently editing.' ), $user->display_name ); $error = sprintf( __( 'This content is currently locked. %s is currently editing.' ), $user->display_name );
@ -544,9 +543,9 @@ class MainWP_Helper {
$replaceAttachedIds = array(); $replaceAttachedIds = array();
if ( isset( $_POST['post_gallery_images'] ) ) { if ( isset( $_POST['post_gallery_images'] ) ) {
$post_gallery_images = unserialize(base64_decode( $_POST['post_gallery_images'] )); $post_gallery_images = unserialize(base64_decode( $_POST['post_gallery_images'] ));
if (is_array($post_gallery_images)) { if ( is_array($post_gallery_images) ) {
foreach ($post_gallery_images as $gallery) { foreach ( $post_gallery_images as $gallery ) {
if (isset($gallery['src'])) { if ( isset($gallery['src']) ) {
try { try {
$upload = self::uploadImage( $gallery['src'], $gallery ); // Upload image to WP $upload = self::uploadImage( $gallery['src'], $gallery ); // Upload image to WP
if ( null !== $upload ) { if ( null !== $upload ) {
@ -559,18 +558,18 @@ class MainWP_Helper {
} }
} }
} }
if (count($replaceAttachedIds) > 0) { if ( count($replaceAttachedIds) > 0 ) {
foreach ( $matches as $match ) { foreach ( $matches as $match ) {
$idsToReplace = $match[1]; $idsToReplace = $match[1];
$idsToReplaceWith = ''; $idsToReplaceWith = '';
$originalIds = explode(',', $idsToReplace); $originalIds = explode(',', $idsToReplace);
foreach ($originalIds as $attached_id) { foreach ( $originalIds as $attached_id ) {
if ( ! empty($originalIds) && isset($replaceAttachedIds[ $attached_id ])) { if ( ! empty($originalIds) && isset($replaceAttachedIds[ $attached_id ]) ) {
$idsToReplaceWith .= $replaceAttachedIds[ $attached_id ] . ','; $idsToReplaceWith .= $replaceAttachedIds[ $attached_id ] . ',';
} }
} }
$idsToReplaceWith = rtrim($idsToReplaceWith, ','); $idsToReplaceWith = rtrim($idsToReplaceWith, ',');
if ( ! empty($idsToReplaceWith)) { if ( ! empty($idsToReplaceWith) ) {
$new_post['post_content'] = str_replace( '"' . $idsToReplace . '"', '"' . $idsToReplaceWith . '"', $new_post['post_content'] ); $new_post['post_content'] = str_replace( '"' . $idsToReplace . '"', '"' . $idsToReplaceWith . '"', $new_post['post_content'] );
} }
} }
@ -702,11 +701,11 @@ class MainWP_Helper {
$post_to_only_existing_categories = false; $post_to_only_existing_categories = false;
if (is_array($post_custom)) { if ( is_array($post_custom) ) {
foreach ( $post_custom as $meta_key => $meta_values ) { foreach ( $post_custom as $meta_key => $meta_values ) {
if ( ! in_array( $meta_key, $not_allowed ) ) { if ( ! in_array( $meta_key, $not_allowed ) ) {
foreach ( $meta_values as $meta_value ) { foreach ( $meta_values as $meta_value ) {
if (strpos($meta_key, '_mainwp_spinner_') === 0) { if ( strpos($meta_key, '_mainwp_spinner_') === 0 ) {
continue; // not save continue; // not save
} }
@ -753,7 +752,6 @@ class MainWP_Helper {
} catch ( Exception $e ) { } catch ( Exception $e ) {
} }
} }
} }
@ -786,7 +784,7 @@ class MainWP_Helper {
if ( null !== $upload ) { if ( null !== $upload ) {
update_post_meta( $new_post_id, '_thumbnail_id', $upload['id'] ); // Add the thumbnail to the post! update_post_meta( $new_post_id, '_thumbnail_id', $upload['id'] ); // Add the thumbnail to the post!
$featured_image_exist = true; $featured_image_exist = true;
if (isset($others['featured_image_data'])) { if ( isset($others['featured_image_data']) ) {
$_image_data = $others['featured_image_data']; $_image_data = $others['featured_image_data'];
update_post_meta( $upload['id'], '_wp_attachment_image_alt', $_image_data['alt'] ); update_post_meta( $upload['id'], '_wp_attachment_image_alt', $_image_data['alt'] );
wp_update_post( array( wp_update_post( array(
@ -870,7 +868,7 @@ class MainWP_Helper {
} }
// unlock if edit post // unlock if edit post
if ($edit_post_id) { if ( $edit_post_id ) {
update_post_meta( $edit_post_id, '_edit_lock', '' ); update_post_meta( $edit_post_id, '_edit_lock', '' );
} }
@ -1098,7 +1096,7 @@ class MainWP_Helper {
// $agent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'; // $agent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';
$agent = 'Mozilla/5.0 (compatible; MainWP-Child/' . MainWP_Child::$version . '; +http://mainwp.com)'; $agent = 'Mozilla/5.0 (compatible; MainWP-Child/' . MainWP_Child::$version . '; +http://mainwp.com)';
if ( ! is_array( $postdata )) { if ( ! is_array( $postdata ) ) {
$postdata = array(); $postdata = array();
} }
@ -1311,7 +1309,7 @@ class MainWP_Helper {
static function update_lasttime_backup( $by, $time ) { static function update_lasttime_backup( $by, $time ) {
$backup_by = array( 'backupbuddy', 'backupwordpress', 'backwpup', 'updraftplus', 'wptimecapsule' ); $backup_by = array( 'backupbuddy', 'backupwordpress', 'backwpup', 'updraftplus', 'wptimecapsule' );
if ( ! in_array($by, $backup_by)) { if ( ! in_array($by, $backup_by) ) {
return false; return false;
} }
@ -1324,17 +1322,17 @@ class MainWP_Helper {
} }
static function get_lasttime_backup( $by ) { static function get_lasttime_backup( $by ) {
if ($by == 'backupwp') { // to compatible if ( $by == 'backupwp' ) { // to compatible
$by = 'backupwordpress'; $by = 'backupwordpress';
} }
switch ($by) { switch ( $by ) {
case 'backupbuddy': case 'backupbuddy':
if ( ! is_plugin_active( 'backupbuddy/backupbuddy.php' ) && ! is_plugin_active( 'Backupbuddy/backupbuddy.php' )) { if ( ! is_plugin_active( 'backupbuddy/backupbuddy.php' ) && ! is_plugin_active( 'Backupbuddy/backupbuddy.php' ) ) {
return 0; return 0;
} }
break; break;
case 'backupwordpress': case 'backupwordpress':
if ( ! is_plugin_active( 'backupwordpress/backupwordpress.php' )) { if ( ! is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) {
return 0; return 0;
} }
break; break;
@ -1344,12 +1342,12 @@ class MainWP_Helper {
} }
break; break;
case 'updraftplus': case 'updraftplus':
if ( ! is_plugin_active( 'updraftplus/updraftplus.php' )) { if ( ! is_plugin_active( 'updraftplus/updraftplus.php' ) ) {
return 0; return 0;
} }
break; break;
case 'wptimecapsule': case 'wptimecapsule':
if ( ! is_plugin_active( 'wp-time-capsule/wp-time-capsule.php' )) { if ( ! is_plugin_active( 'wp-time-capsule/wp-time-capsule.php' ) ) {
return 0; return 0;
} }
break; break;
@ -1523,7 +1521,7 @@ class MainWP_Helper {
} }
public static function sanitize_filename( $filename ) { public static function sanitize_filename( $filename ) {
if ( ! function_exists('mb_ereg_replace')) { if ( ! function_exists('mb_ereg_replace') ) {
return sanitize_file_name($filename); return sanitize_file_name($filename);
} }
@ -1608,10 +1606,10 @@ class MainWP_Helper {
return false; return false;
} }
if (function_exists('get_current_screen')) { if ( function_exists('get_current_screen') ) {
$screen = get_current_screen(); $screen = get_current_screen();
if ( $screen ) { if ( $screen ) {
if ( $screen->base == 'update-core' && $screen->parent_file == 'index.php' ) { if ( $screen->base == 'update-core' && $screen->parent_file == 'index.php' ) {
return true; return true;
} }
} }
@ -1625,21 +1623,21 @@ class MainWP_Helper {
public static function check_files_exists( $files = array(), $return = false ) { public static function check_files_exists( $files = array(), $return = false ) {
$missing = array(); $missing = array();
if (is_array($files)) { if ( is_array($files) ) {
foreach ($files as $name) { foreach ( $files as $name ) {
if ( ! file_exists( $name )) { if ( ! file_exists( $name ) ) {
$missing[] = $name; $missing[] = $name;
} }
} }
} else { } else {
if ( ! file_exists( $files )) { if ( ! file_exists( $files ) ) {
$missing[] = $files; $missing[] = $files;
} }
} }
if ( ! empty($missing)) { if ( ! empty($missing) ) {
$message = 'Missing file(s): ' . implode(',', $missing); $message = 'Missing file(s): ' . implode(',', $missing);
if ($return) { if ( $return ) {
return $message; return $message;
} else { } else {
throw new Exception( $message ); throw new Exception( $message );
@ -1648,11 +1646,11 @@ class MainWP_Helper {
return true; return true;
} }
public static function check_classes_exists( $classes = array(), $return = false) { public static function check_classes_exists( $classes = array(), $return = false ) {
$missing = array(); $missing = array();
if (is_array($classes)) { if ( is_array($classes) ) {
foreach ($classes as $name) { foreach ( $classes as $name ) {
if ( ! class_exists( $name )) { if ( ! class_exists( $name ) ) {
$missing[] = $name; $missing[] = $name;
} }
} }
@ -1664,7 +1662,7 @@ class MainWP_Helper {
if ( ! empty($missing) ) { if ( ! empty($missing) ) {
$message = 'Missing classes: ' . implode(',', $missing); $message = 'Missing classes: ' . implode(',', $missing);
if ($return) { if ( $return ) {
return $message; return $message;
} else { } else {
throw new Exception( $message ); throw new Exception( $message );
@ -1673,25 +1671,24 @@ class MainWP_Helper {
return true; return true;
} }
public static function check_methods( $object, $methods = array(), $return = false) { public static function check_methods( $object, $methods = array(), $return = false ) {
$missing = array(); $missing = array();
if (is_array($methods)) { if ( is_array($methods) ) {
$missing = array(); $missing = array();
foreach ($methods as $name) { foreach ( $methods as $name ) {
if ( ! method_exists($object, $name) ) { if ( ! method_exists($object, $name) ) {
$missing[] = $name; $missing[] = $name;
} }
} }
} elseif ( ! empty($methods)) { } elseif ( ! empty($methods) ) {
if ( ! method_exists($object, $methods) ) { if ( ! method_exists($object, $methods) ) {
$missing[] = $methods; $missing[] = $methods;
} }
} }
if ( ! empty($missing) ) { if ( ! empty($missing) ) {
$message = 'Missing method: ' . implode(',', $missing); $message = 'Missing method: ' . implode(',', $missing);
if ($return) { if ( $return ) {
return $message; return $message;
} else { } else {
throw new Exception( $message ); throw new Exception( $message );
@ -1701,24 +1698,23 @@ class MainWP_Helper {
return true; return true;
} }
public static function check_properties( $object, $properties = array(), $return = false) { public static function check_properties( $object, $properties = array(), $return = false ) {
$missing = array(); $missing = array();
if (is_array($properties)) { if ( is_array($properties) ) {
foreach ($properties as $name) { foreach ( $properties as $name ) {
if ( ! property_exists($object, $name) ) { if ( ! property_exists($object, $name) ) {
$missing[] = $name; $missing[] = $name;
} }
} }
} elseif ( ! empty($properties)) { } elseif ( ! empty($properties) ) {
if ( ! property_exists($object, $properties) ) { if ( ! property_exists($object, $properties) ) {
$missing[] = $properties; $missing[] = $properties;
} }
} }
if ( ! empty($missing) ) { if ( ! empty($missing) ) {
$message = 'Missing properties: ' . implode(',', $missing); $message = 'Missing properties: ' . implode(',', $missing);
if ($return) { if ( $return ) {
return $message; return $message;
} else { } else {
throw new Exception( $message ); throw new Exception( $message );
@ -1728,24 +1724,23 @@ class MainWP_Helper {
return true; return true;
} }
public static function check_functions( $funcs = array(), $return = false) { public static function check_functions( $funcs = array(), $return = false ) {
$missing = array(); $missing = array();
if (is_array($funcs)) { if ( is_array($funcs) ) {
foreach ($funcs as $name) { foreach ( $funcs as $name ) {
if ( ! function_exists( $name) ) { if ( ! function_exists( $name) ) {
$missing[] = $name; $missing[] = $name;
} }
} }
} elseif ( ! empty($funcs)) { } elseif ( ! empty($funcs) ) {
if ( ! function_exists($funcs) ) { if ( ! function_exists($funcs) ) {
$missing[] = $funcs; $missing[] = $funcs;
} }
} }
if ( ! empty($missing) ) { if ( ! empty($missing) ) {
$message = 'Missing functions: ' . implode(',', $missing); $message = 'Missing functions: ' . implode(',', $missing);
if ($return) { if ( $return ) {
return $message; return $message;
} else { } else {
throw new Exception( $message ); throw new Exception( $message );
@ -1774,7 +1769,7 @@ class MainWP_Helper {
} }
} }
if (isset($_POST['function']) && isset($_POST['mainwpsignature']) && if ( isset($_POST['function']) && isset($_POST['mainwpsignature']) &&
( isset($_POST['mwp_action']) || 'wordpress_seo' == $_POST['function'] ) // wordpress_seo for WordPress SEO ( isset($_POST['mwp_action']) || 'wordpress_seo' == $_POST['function'] ) // wordpress_seo for WordPress SEO
) { ) {
register_shutdown_function( 'handle_shutdown' ); register_shutdown_function( 'handle_shutdown' );