Refactoring

This commit is contained in:
thanghv 2020-05-12 20:19:58 +07:00
parent 3936785bd5
commit e31db72607
10 changed files with 3412 additions and 3143 deletions

File diff suppressed because it is too large Load diff

View file

@ -28,6 +28,154 @@ class MainWP_Child_Install {
return self::$instance;
}
public function plugin_action() {
global $mainWPChild;
$action = $_POST['action'];
$plugins = explode( '||', $_POST['plugin'] );
if ( 'activate' === $action ) {
include_once ABSPATH . '/wp-admin/includes/plugin.php';
foreach ( $plugins as $idx => $plugin ) {
if ( $plugin !== $mainWPChild->plugin_slug ) {
$thePlugin = get_plugin_data( $plugin );
if ( null !== $thePlugin && '' !== $thePlugin ) {
if ( 'quotes-collection/quotes-collection.php' == $plugin ) {
activate_plugin( $plugin, '', false, true );
} else {
activate_plugin( $plugin );
}
}
}
}
} elseif ( 'deactivate' === $action ) {
include_once ABSPATH . '/wp-admin/includes/plugin.php';
foreach ( $plugins as $idx => $plugin ) {
if ( $plugin !== $mainWPChild->plugin_slug ) {
$thePlugin = get_plugin_data( $plugin );
if ( null !== $thePlugin && '' !== $thePlugin ) {
deactivate_plugins( $plugin );
}
}
}
} elseif ( 'delete' === $action ) {
include_once ABSPATH . '/wp-admin/includes/plugin.php';
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
include_once ABSPATH . '/wp-admin/includes/screen.php';
}
include_once ABSPATH . '/wp-admin/includes/file.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/class-wp-filesystem-base.php';
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
MainWP_Helper::check_wp_filesystem();
$pluginUpgrader = new Plugin_Upgrader();
$all_plugins = get_plugins();
foreach ( $plugins as $idx => $plugin ) {
if ( $plugin !== $mainWPChild->plugin_slug ) {
if ( isset( $all_plugins[ $plugin ] ) ) {
if ( is_plugin_active( $plugin ) ) {
$thePlugin = get_plugin_data( $plugin );
if ( null !== $thePlugin && '' !== $thePlugin ) {
deactivate_plugins( $plugin );
}
}
$tmp['plugin'] = $plugin;
if ( true === $pluginUpgrader->delete_old_plugin( null, null, null, $tmp ) ) {
$args = array(
'action' => 'delete',
'Name' => $all_plugins[ $plugin ]['Name'],
);
do_action( 'mainwp_child_plugin_action', $args );
}
}
}
}
} else {
$information['status'] = 'FAIL';
}
if ( ! isset( $information['status'] ) ) {
$information['status'] = 'SUCCESS';
}
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
mainwp_child_helper()->write( $information );
}
public function theme_action() {
$action = $_POST['action'];
$theme = $_POST['theme'];
if ( 'activate' === $action ) {
include_once ABSPATH . '/wp-admin/includes/theme.php';
$theTheme = wp_get_theme( $theme );
if ( null !== $theTheme && '' !== $theTheme ) {
switch_theme( $theTheme['Template'], $theTheme['Stylesheet'] );
}
} elseif ( 'delete' === $action ) {
include_once ABSPATH . '/wp-admin/includes/theme.php';
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
include_once ABSPATH . '/wp-admin/includes/screen.php';
}
include_once ABSPATH . '/wp-admin/includes/file.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/class-wp-filesystem-base.php';
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
MainWP_Helper::check_wp_filesystem();
$themeUpgrader = new Theme_Upgrader();
$theme_name = wp_get_theme()->get( 'Name' );
$themes = explode( '||', $theme );
if ( count( $themes ) == 1 ) {
$themeToDelete = current( $themes );
if ( $themeToDelete == $theme_name ) {
$information['error'] = 'IsActivatedTheme';
mainwp_child_helper()->write( $information );
return;
}
}
foreach ( $themes as $idx => $themeToDelete ) {
if ( $themeToDelete !== $theme_name ) {
$theTheme = wp_get_theme( $themeToDelete );
if ( null !== $theTheme && '' !== $theTheme ) {
$tmp['theme'] = $theTheme['Template'];
if ( true === $themeUpgrader->delete_old_theme( null, null, null, $tmp ) ) {
$args = array(
'action' => 'delete',
'Name' => $theTheme['Name'],
);
do_action( 'mainwp_child_theme_action', $args );
}
}
}
}
} else {
$information['status'] = 'FAIL';
}
if ( ! isset( $information['status'] ) ) {
$information['status'] = 'SUCCESS';
}
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
mainwp_child_helper()->write( $information );
}
/**
* Functions to support core functionality
@ -155,6 +303,6 @@ class MainWP_Child_Install {
$information['installation'] = 'SUCCESS';
$information['destination_name'] = $result['destination_name'];
mainwp_child_helper()->write( $information );
}
}
}

View file

@ -0,0 +1,662 @@
<?php
namespace MainWP\Child;
class MainWP_Child_Posts {
protected static $instance = null;
private $comments_and_clauses;
private $posts_where_suffix;
/**
* Method get_class_name()
*
* Get Class Name.
*
* @return object
*/
public static function get_class_name() {
return __CLASS__;
}
public function __construct() {
$this->comments_and_clauses = '';
$this->posts_where_suffix = '';
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function get_recent_posts( $pAllowedStatuses, $pCount, $type = 'post', $extra = null ) {
$allPosts = array();
if ( null !== $pAllowedStatuses ) {
foreach ( $pAllowedStatuses as $status ) {
$this->get_recent_posts_int( $status, $pCount, $type, $allPosts, $extra );
}
} else {
$this->get_recent_posts_int( 'any', $pCount, $type, $allPosts, $extra );
}
return $allPosts;
}
public function get_recent_posts_int( $status, $pCount, $type = 'post', &$allPosts, $extra = null ) {
$args = array(
'post_status' => $status,
'suppress_filters' => false,
'post_type' => $type,
);
$tokens = array();
if ( is_array( $extra ) && isset( $extra['tokens'] ) ) {
$tokens = $extra['tokens'];
if ( 1 == $extra['extract_post_type'] ) {
$args['post_type'] = 'post';
} elseif ( 2 == $extra['extract_post_type'] ) {
$args['post_type'] = 'page';
} elseif ( 3 == $extra['extract_post_type'] ) {
$args['post_type'] = array( 'post', 'page' );
}
}
$tokens = array_flip( $tokens );
if ( 0 !== $pCount ) {
$args['numberposts'] = $pCount;
}
/*
*
* Credits
*
* Plugin-Name: Yoast SEO
* Plugin URI: https://yoast.com/wordpress/plugins/seo/#utm_source=wpadmin&utm_medium=plugin&utm_campaign=wpseoplugin
* Author: Team Yoast
* Author URI: https://yoast.com/
* Licence: GPL v3
*
* The code is used for the MainWP WordPress SEO Extension
* Extension URL: https://mainwp.com/extension/wordpress-seo/
*
*/
$wp_seo_enabled = false;
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' ) ) {
$wp_seo_enabled = true;
}
}
$posts = get_posts( $args );
if ( is_array( $posts ) ) {
if ( $wp_seo_enabled ) {
$post_ids = array();
foreach ( $posts as $post ) {
$post_ids[] = $post->ID;
}
$link_count = new WPSEO_Link_Column_Count();
$link_count->set( $post_ids );
}
foreach ( $posts as $post ) {
$outPost = array();
$outPost['id'] = $post->ID;
$outPost['post_type'] = $post->post_type;
$outPost['status'] = $post->post_status;
$outPost['title'] = $post->post_title;
$outPost['comment_count'] = $post->comment_count;
if ( isset( $extra['where_post_date'] ) && ! empty( $extra['where_post_date'] ) ) {
$outPost['dts'] = strtotime( $post->post_date_gmt );
} else {
$outPost['dts'] = strtotime( $post->post_modified_gmt );
}
if ( 'future' == $post->post_status ) {
$outPost['dts'] = strtotime( $post->post_date_gmt );
}
$usr = get_user_by( 'id', $post->post_author );
$outPost['author'] = ! empty( $usr ) ? $usr->user_nicename : 'removed';
$categoryObjects = get_the_category( $post->ID );
$categories = '';
foreach ( $categoryObjects as $cat ) {
if ( '' !== $categories ) {
$categories .= ', ';
}
$categories .= $cat->name;
}
$outPost['categories'] = $categories;
$tagObjects = get_the_tags( $post->ID );
$tags = '';
if ( is_array( $tagObjects ) ) {
foreach ( $tagObjects as $tag ) {
if ( '' !== $tags ) {
$tags .= ', ';
}
$tags .= $tag->name;
}
}
$outPost['tags'] = $tags;
if ( is_array( $tokens ) ) {
if ( isset( $tokens['[post.url]'] ) ) {
$outPost['[post.url]'] = get_permalink( $post->ID );
}
if ( isset( $tokens['[post.website.url]'] ) ) {
$outPost['[post.website.url]'] = get_site_url();
}
if ( isset( $tokens['[post.website.name]'] ) ) {
$outPost['[post.website.name]'] = get_bloginfo( 'name' );
}
}
if ( $wp_seo_enabled ) {
$post_id = $post->ID;
$outPost['seo_data'] = array(
'count_seo_links' => $link_count->get( $post_id, 'internal_link_count' ),
'count_seo_linked' => $link_count->get( $post_id, 'incoming_link_count' ),
'seo_score' => \MainWP_WordPress_SEO::instance()->parse_column_score( $post_id ),
'readability_score' => \MainWP_WordPress_SEO::instance()->parse_column_score_readability( $post_id ),
);
}
$allPosts[] = $outPost;
}
}
}
public function get_all_posts() {
$post_type = ( isset( $_POST['post_type'] ) ? $_POST['post_type'] : 'post' );
$this->get_all_posts_by_type( $post_type );
}
public function get_all_pages() {
$this->get_all_posts_by_type( 'page' );
}
public function posts_where( $where ) {
if ( $this->posts_where_suffix ) {
$where .= ' ' . $this->posts_where_suffix;
}
return $where;
}
public function get_all_posts_by_type( $type ) {
global $wpdb;
add_filter( 'posts_where', array( &$this, 'posts_where' ) );
$where_post_date = isset( $_POST['where_post_date'] ) && ! empty( $_POST['where_post_date'] ) ? true : false;
if ( isset( $_POST['postId'] ) ) {
$this->posts_where_suffix .= " AND $wpdb->posts.ID = " . $_POST['postId'];
} elseif ( isset( $_POST['userId'] ) ) {
$this->posts_where_suffix .= " AND $wpdb->posts.post_author = " . $_POST['userId'];
} else {
if ( isset( $_POST['keyword'] ) ) {
$search_on = isset( $_POST['search_on'] ) ? $_POST['search_on'] : '';
if ( 'title' == $search_on ) {
$this->posts_where_suffix .= " AND ( $wpdb->posts.post_title LIKE '%" . $_POST['keyword'] . "%' )";
} elseif ( 'content' == $search_on ) {
$this->posts_where_suffix .= " AND ($wpdb->posts.post_content LIKE '%" . $_POST['keyword'] . "%' )";
} else {
$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 ( $where_post_date ) {
$this->posts_where_suffix .= " AND $wpdb->posts.post_date > '" . $_POST['dtsstart'] . "'";
} else {
$this->posts_where_suffix .= " AND $wpdb->posts.post_modified > '" . $_POST['dtsstart'] . "'";
}
}
if ( isset( $_POST['dtsstop'] ) && '' !== $_POST['dtsstop'] ) {
if ( $where_post_date ) {
$this->posts_where_suffix .= " AND $wpdb->posts.post_date < '" . $_POST['dtsstop'] . "'";
} else {
$this->posts_where_suffix .= " AND $wpdb->posts.post_modified < '" . $_POST['dtsstop'] . "'";
}
}
if ( isset( $_POST['exclude_page_type'] ) && $_POST['exclude_page_type'] ) {
$this->posts_where_suffix .= " AND $wpdb->posts.post_type NOT IN ('page')";
}
}
$maxPages = 50;
if ( defined( 'MAINWP_CHILD_NR_OF_PAGES' ) ) {
$maxPages = MAINWP_CHILD_NR_OF_PAGES;
}
if ( isset( $_POST['maxRecords'] ) ) {
$maxPages = $_POST['maxRecords'];
}
if ( 0 === $maxPages ) {
$maxPages = 99999;
}
$extra = array();
if ( isset( $_POST['extract_tokens'] ) ) {
$extra['tokens'] = maybe_unserialize( base64_decode( $_POST['extract_tokens'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
$extra['extract_post_type'] = $_POST['extract_post_type'];
}
$extra['where_post_date'] = $where_post_date;
$rslt = $this->get_recent_posts( explode( ',', $_POST['status'] ), $maxPages, $type, $extra );
$this->posts_where_suffix = '';
mainwp_child_helper()->write( $rslt );
}
public function new_post() {
$new_post = maybe_unserialize( base64_decode( $_POST['new_post'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
$post_custom = maybe_unserialize( base64_decode( $_POST['post_custom'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
$post_category = rawurldecode( isset( $_POST['post_category'] ) ? base64_decode( $_POST['post_category'] ) : null ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
$post_tags = rawurldecode( isset( $new_post['post_tags'] ) ? $new_post['post_tags'] : null );
$post_featured_image = base64_decode( $_POST['post_featured_image'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
$upload_dir = maybe_unserialize( base64_decode( $_POST['mainwp_upload_dir'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
if ( isset( $_POST['_ezin_post_category'] ) ) {
$new_post['_ezin_post_category'] = maybe_unserialize( base64_decode( $_POST['_ezin_post_category'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
}
$others = array();
if ( isset( $_POST['featured_image_data'] ) && ! empty( $_POST['featured_image_data'] ) ) {
$others['featured_image_data'] = unserialize( base64_decode( $_POST['featured_image_data'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
}
$res = MainWP_Helper::create_post( $new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags, $others );
if ( is_array( $res ) && isset( $res['error'] ) ) {
MainWP_Helper::error( $res['error'] );
}
$created = $res['success'];
if ( true !== $created ) {
MainWP_Helper::error( 'Undefined error' );
}
$information['added'] = true;
$information['added_id'] = $res['added_id'];
$information['link'] = $res['link'];
do_action( 'mainwp_child_after_newpost', $res );
mainwp_child_helper()->write( $information );
}
public function post_action() {
$action = $_POST['action'];
$postId = $_POST['id'];
$my_post = array();
if ( 'publish' === $action ) {
$post_current = get_post( $postId );
if ( empty( $post_current ) ) {
$information['status'] = 'FAIL';
} else {
if ( 'future' == $post_current->post_status ) {
wp_publish_post( $postId );
wp_update_post(
array(
'ID' => $postId,
'post_date' => current_time( 'mysql', false ),
'post_date_gmt' => current_time( 'mysql', true ),
)
);
} else {
wp_update_post(
array(
'ID' => $postId,
'post_status' => 'publish',
)
);
}
}
} elseif ( 'update' === $action ) {
$postData = $_POST['post_data'];
$my_post = is_array( $postData ) ? $postData : array();
wp_update_post( $my_post );
} elseif ( 'unpublish' === $action ) {
$my_post['ID'] = $postId;
$my_post['post_status'] = 'draft';
wp_update_post( $my_post );
} elseif ( 'trash' === $action ) {
add_action( 'trash_post', array( '\MainWP_Child_Links_Checker', 'hook_post_deleted' ) );
wp_trash_post( $postId );
} elseif ( 'delete' === $action ) {
add_action( 'delete_post', array( '\MainWP_Child_Links_Checker', 'hook_post_deleted' ) );
wp_delete_post( $postId, true );
} elseif ( 'restore' === $action ) {
wp_untrash_post( $postId );
} elseif ( 'update_meta' === $action ) {
$values = maybe_unserialize( base64_decode( $_POST['values'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
$meta_key = $values['meta_key'];
$meta_value = $values['meta_value'];
$check_prev = $values['check_prev'];
foreach ( $meta_key as $i => $key ) {
if ( 1 === intval( $check_prev[ $i ] ) ) {
update_post_meta( $postId, $key, get_post_meta( $postId, $key, true ) ? get_post_meta( $postId, $key, true ) : $meta_value[ $i ] );
} else {
update_post_meta( $postId, $key, $meta_value[ $i ] );
}
}
} elseif ( 'get_edit' === $action ) {
$postId = $_POST['id'];
$post_type = $_POST['post_type'];
if ( 'post' == $post_type ) {
$my_post = $this->get_post_edit( $postId );
} else {
$my_post = $this->get_page_edit( $postId );
}
} else {
$information['status'] = 'FAIL';
}
if ( ! isset( $information['status'] ) ) {
$information['status'] = 'SUCCESS';
}
$information['my_post'] = $my_post;
mainwp_child_helper()->write( $information );
}
public function get_post_edit( $id ) {
$post = get_post( $id );
if ( $post ) {
$categoryObjects = get_the_category( $post->ID );
$categories = '';
foreach ( $categoryObjects as $cat ) {
if ( '' !== $categories ) {
$categories .= ', ';
}
$categories .= $cat->name;
}
$post_category = $categories;
$tagObjects = get_the_tags( $post->ID );
$tags = '';
if ( is_array( $tagObjects ) ) {
foreach ( $tagObjects as $tag ) {
if ( '' !== $tags ) {
$tags .= ', ';
}
$tags .= $tag->name;
}
}
$post_tags = $tags;
$post_custom = get_post_custom( $id );
$galleries = get_post_gallery( $id, false );
$post_gallery_images = array();
if ( is_array( $galleries ) && isset( $galleries['ids'] ) ) {
$attached_images = explode( ',', $galleries['ids'] );
foreach ( $attached_images as $attachment_id ) {
$attachment = get_post( $attachment_id );
if ( $attachment ) {
$post_gallery_images[] = array(
'id' => $attachment_id,
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'caption' => $attachment->post_excerpt,
'description' => $attachment->post_content,
'src' => $attachment->guid,
'title' => $attachment->post_title,
);
}
}
}
include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php';
$post_featured_image = get_post_thumbnail_id( $id );
$child_upload_dir = wp_upload_dir();
$new_post = array(
'edit_id' => $id,
'is_sticky' => is_sticky( $id ) ? 1 : 0,
'post_title' => $post->post_title,
'post_content' => $post->post_content,
'post_status' => $post->post_status,
'post_date' => $post->post_date,
'post_date_gmt' => $post->post_date_gmt,
'post_tags' => $post_tags,
'post_name' => $post->post_name,
'post_excerpt' => $post->post_excerpt,
'comment_status' => $post->comment_status,
'ping_status' => $post->ping_status,
);
if ( null != $post_featured_image ) { // Featured image is set, retrieve URL.
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
$post_featured_image = $img[0];
}
require_once ABSPATH . 'wp-admin/includes/post.php';
wp_set_post_lock( $id );
$post_data = array(
'new_post' => base64_encode( serialize( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
'post_custom' => base64_encode( serialize( $post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
'post_category' => base64_encode( $post_category ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
'post_featured_image' => base64_encode( $post_featured_image ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
);
return $post_data;
}
return false;
}
public function get_page_edit( $id ) {
$post = get_post( $id );
if ( $post ) {
$post_custom = get_post_custom( $id );
include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php';
$post_featured_image = get_post_thumbnail_id( $id );
$child_upload_dir = wp_upload_dir();
$new_post = array(
'edit_id' => $id,
'post_title' => $post->post_title,
'post_content' => $post->post_content,
'post_status' => $post->post_status,
'post_date' => $post->post_date,
'post_date_gmt' => $post->post_date_gmt,
'post_type' => 'page',
'post_name' => $post->post_name,
'post_excerpt' => $post->post_excerpt,
'comment_status' => $post->comment_status,
'ping_status' => $post->ping_status,
);
if ( null != $post_featured_image ) {
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
$post_featured_image = $img[0];
}
$galleries = get_post_gallery( $id, false );
$post_gallery_images = array();
if ( is_array( $galleries ) && isset( $galleries['ids'] ) ) {
$attached_images = explode( ',', $galleries['ids'] );
foreach ( $attached_images as $attachment_id ) {
$attachment = get_post( $attachment_id );
if ( $attachment ) {
$post_gallery_images[] = array(
'id' => $attachment_id,
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'caption' => $attachment->post_excerpt,
'description' => $attachment->post_content,
'src' => $attachment->guid,
'title' => $attachment->post_title,
);
}
}
}
require_once ABSPATH . 'wp-admin/includes/post.php';
wp_set_post_lock( $id );
$post_data = array(
'new_post' => base64_encode( serialize( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
'post_custom' => base64_encode( serialize( $post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
'post_featured_image' => base64_encode( $post_featured_image ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
);
return $post_data;
}
return false;
}
public function comment_action() {
$action = $_POST['action'];
$commentId = $_POST['id'];
if ( 'approve' === $action ) {
wp_set_comment_status( $commentId, 'approve' );
} elseif ( 'unapprove' === $action ) {
wp_set_comment_status( $commentId, 'hold' );
} elseif ( 'spam' === $action ) {
wp_spam_comment( $commentId );
} elseif ( 'unspam' === $action ) {
wp_unspam_comment( $commentId );
} elseif ( 'trash' === $action ) {
add_action( 'trashed_comment', array( '\MainWP_Child_Links_Checker', 'hook_trashed_comment' ), 10, 1 );
wp_trash_comment( $commentId );
} elseif ( 'restore' === $action ) {
wp_untrash_comment( $commentId );
} elseif ( 'delete' === $action ) {
wp_delete_comment( $commentId, true );
} else {
$information['status'] = 'FAIL';
}
if ( ! isset( $information['status'] ) ) {
$information['status'] = 'SUCCESS';
}
mainwp_child_helper()->write( $information );
}
public function comment_bulk_action() {
$action = $_POST['action'];
$commentIds = explode( ',', $_POST['ids'] );
$information['success'] = 0;
foreach ( $commentIds as $commentId ) {
if ( $commentId ) {
$information['success'] ++;
if ( 'approve' === $action ) {
wp_set_comment_status( $commentId, 'approve' );
} elseif ( 'unapprove' === $action ) {
wp_set_comment_status( $commentId, 'hold' );
} elseif ( 'spam' === $action ) {
wp_spam_comment( $commentId );
} elseif ( 'unspam' === $action ) {
wp_unspam_comment( $commentId );
} elseif ( 'trash' === $action ) {
wp_trash_comment( $commentId );
} elseif ( 'restore' === $action ) {
wp_untrash_comment( $commentId );
} elseif ( 'delete' === $action ) {
wp_delete_comment( $commentId, true );
} else {
$information['success']--;
}
}
}
mainwp_child_helper()->write( $information );
}
public function comments_clauses( $clauses ) {
if ( $this->comments_and_clauses ) {
$clauses['where'] .= ' ' . $this->comments_and_clauses;
}
return $clauses;
}
public function get_all_comments() {
global $wpdb;
add_filter( 'comments_clauses', array( &$this, 'comments_clauses' ) );
if ( isset( $_POST['postId'] ) ) {
$this->comments_and_clauses .= " AND $wpdb->comments.comment_post_ID = " . $_POST['postId'];
} else {
if ( isset( $_POST['keyword'] ) ) {
$this->comments_and_clauses .= " AND $wpdb->comments.comment_content LIKE '%" . $_POST['keyword'] . "%'";
}
if ( isset( $_POST['dtsstart'] ) && '' !== $_POST['dtsstart'] ) {
$this->comments_and_clauses .= " AND $wpdb->comments.comment_date > '" . $_POST['dtsstart'] . "'";
}
if ( isset( $_POST['dtsstop'] ) && '' !== $_POST['dtsstop'] ) {
$this->comments_and_clauses .= " AND $wpdb->comments.comment_date < '" . $_POST['dtsstop'] . "'";
}
}
$maxComments = 50;
if ( defined( 'MAINWP_CHILD_NR_OF_COMMENTS' ) ) {
$maxComments = MAINWP_CHILD_NR_OF_COMMENTS; // to compatible.
}
if ( isset( $_POST['maxRecords'] ) ) {
$maxComments = $_POST['maxRecords'];
}
if ( 0 === $maxComments ) {
$maxComments = 99999;
}
$rslt = $this->get_recent_comments( explode( ',', $_POST['status'] ), $maxComments );
$this->comments_and_clauses = '';
mainwp_child_helper()->write( $rslt );
}
public function get_recent_comments( $pAllowedStatuses, $pCount ) {
if ( ! function_exists( 'get_comment_author_url' ) ) {
include_once WPINC . '/comment-template.php';
}
$allComments = array();
foreach ( $pAllowedStatuses as $status ) {
$params = array( 'status' => $status );
if ( 0 !== $pCount ) {
$params['number'] = $pCount;
}
$comments = get_comments( $params );
if ( is_array( $comments ) ) {
foreach ( $comments as $comment ) {
$post = get_post( $comment->comment_post_ID );
$email = apply_filters( 'comment_email', $comment->comment_author_email );
$outComment = array();
$outComment['id'] = $comment->comment_ID;
$outComment['status'] = wp_get_comment_status( $comment->comment_ID );
$outComment['author'] = $comment->comment_author;
$outComment['author_url'] = get_comment_author_url( $comment->comment_ID );
$outComment['author_ip'] = get_comment_author_IP( $comment->comment_ID );
$outComment['author_email'] = apply_filters( 'comment_email', $comment->comment_author_email );
$outComment['postId'] = $comment->comment_post_ID;
$outComment['postName'] = $post->post_title;
$outComment['comment_count'] = $post->comment_count;
$outComment['content'] = $comment->comment_content;
$outComment['dts'] = strtotime( $comment->comment_date_gmt );
$allComments[] = $outComment;
}
}
}
return $allComments;
}
}

View file

@ -0,0 +1,701 @@
<?php
namespace MainWP\Child;
class MainWP_Child_Stats {
protected static $instance = null;
private $filterFunction = null;
/**
* Method get_class_name()
*
* Get Class Name.
*
* @return object
*/
public static function get_class_name() {
return __CLASS__;
}
public function __construct() {
$this->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;
}
// Show stats without login - only allowed while no account is added yet.
public function get_site_stats_no_auth( $information = array() ) {
if ( get_option( 'mainwp_child_pubkey' ) ) {
$hint = '<br/>' . __( 'Hint: Go to the child site, deactivate and reactivate the MainWP Child plugin and try again.', 'mainwp-child' );
MainWP_Helper::error( __( 'This site already contains a link. Please deactivate and reactivate the MainWP plugin.', 'mainwp-child' ) . $hint );
}
global $wp_version;
$information['version'] = MainWP_Child::$version;
$information['wpversion'] = $wp_version;
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
mainwp_child_helper()->write( $information );
}
public function default_option_active_plugins( $default ) {
if ( ! is_array( $default ) ) {
$default = array();
}
if ( ! in_array( 'managewp/init.php', $default ) ) {
$default[] = 'managewp/init.php';
}
return $default;
}
// Show stats.
public function get_site_stats( $information = array(), $exit = true ) {
global $wp_version;
if ( $exit ) {
$this->update_external_settings();
}
MainWP_Child_Branding::instance()->save_branding_options( 'branding_disconnected', '' );
if ( isset( $_POST['server'] ) ) {
MainWP_Helper::update_option( 'mainwp_child_server', $_POST['server'] );
}
MainWP_Child_Plugins_Check::may_outdate_number_change();
$information['version'] = MainWP_Child::$version;
$information['wpversion'] = $wp_version;
$information['siteurl'] = get_option( 'siteurl' );
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
$theme_name = wp_get_theme()->get( 'Name' );
$information['site_info'] = array(
'wpversion' => $wp_version,
'debug_mode' => ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) ? true : false,
'phpversion' => phpversion(),
'child_version' => MainWP_Child::$version,
'memory_limit' => MainWP_Child_Server_Information::get_php_memory_limit(),
'mysql_version' => MainWP_Child_Server_Information::get_my_sql_version(),
'themeactivated' => $theme_name,
'ip' => $_SERVER['SERVER_ADDR'],
);
// Try to switch to SSL if SSL is enabled in between!
$pubkey = get_option( 'mainwp_child_pubkey' );
$nossl = get_option( 'mainwp_child_nossl' );
if ( 1 == $nossl ) {
if ( isset( $pubkey ) && MainWP_Helper::is_ssl_enabled() ) {
MainWP_Helper::update_option( 'mainwp_child_nossl', 0, 'yes' );
$nossl = 0;
}
}
$information['nossl'] = ( 1 == $nossl ? 1 : 0 );
include_once ABSPATH . '/wp-admin/includes/update.php';
$timeout = 3 * 60 * 60;
set_time_limit( $timeout );
ini_set( 'max_execution_time', $timeout ); //phpcs:ignore -- to custom
// Check for new versions.
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 );
}
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 ) {
break;
}
if ( 'upgrade' === $core_update->response && version_compare( $wp_version, $core_update->current, '<=' ) ) {
$information['wp_updates'] = $core_update->current;
}
}
}
if ( ! isset( $information['wp_updates'] ) ) {
$information['wp_updates'] = null;
}
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 );
}
add_filter( 'default_option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
add_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
// First check for new premium updates.
$update_check = apply_filters( 'mwp_premium_update_check', array() );
if ( ! empty( $update_check ) ) {
foreach ( $update_check as $updateFeedback ) {
if ( is_array( $updateFeedback['callback'] ) && isset( $updateFeedback['callback'][0] ) && isset( $updateFeedback['callback'][1] ) ) {
call_user_func( array( $updateFeedback['callback'][0], $updateFeedback['callback'][1] ) );
} elseif ( is_string( $updateFeedback['callback'] ) ) {
call_user_func( $updateFeedback['callback'] );
}
}
}
$informationPremiumUpdates = apply_filters( 'mwp_premium_update_notification', array() );
$premiumPlugins = array();
$premiumThemes = array();
if ( is_array( $informationPremiumUpdates ) ) {
$premiumUpdates = array();
$information['premium_updates'] = array();
$informationPremiumUpdatesLength = count( $informationPremiumUpdates );
for ( $i = 0; $i < $informationPremiumUpdatesLength; $i ++ ) {
if ( ! isset( $informationPremiumUpdates[ $i ]['new_version'] ) ) {
continue;
}
$slug = ( isset( $informationPremiumUpdates[ $i ]['slug'] ) ? $informationPremiumUpdates[ $i ]['slug'] : $informationPremiumUpdates[ $i ]['Name'] );
if ( 'plugin' === $informationPremiumUpdates[ $i ]['type'] ) {
$premiumPlugins[] = $slug;
} elseif ( 'theme' === $informationPremiumUpdates[ $i ]['type'] ) {
$premiumThemes[] = $slug;
}
$new_version = $informationPremiumUpdates[ $i ]['new_version'];
unset( $informationPremiumUpdates[ $i ]['old_version'] );
unset( $informationPremiumUpdates[ $i ]['new_version'] );
$information['premium_updates'][ $slug ] = $informationPremiumUpdates[ $i ];
$information['premium_updates'][ $slug ]['update'] = (object) array(
'new_version' => $new_version,
'premium' => true,
'slug' => $slug,
);
if ( ! in_array( $slug, $premiumUpdates ) ) {
$premiumUpdates[] = $slug;
}
}
MainWP_Helper::update_option( 'mainwp_premium_updates', $premiumUpdates );
}
remove_filter( 'default_option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
remove_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
if ( null !== $this->filterFunction ) {
add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
}
global $wp_current_filter;
$wp_current_filter[] = 'load-plugins.php'; // phpcs:ignore -- to custom plugin installation.
wp_update_plugins();
include_once ABSPATH . '/wp-admin/includes/plugin.php';
$plugin_updates = get_plugin_updates();
if ( is_array( $plugin_updates ) ) {
$information['plugin_updates'] = array();
foreach ( $plugin_updates as $slug => $plugin_update ) {
if ( in_array( $plugin_update->Name, $premiumPlugins ) ) {
continue;
}
// to fix incorrect info.
if ( ! property_exists( $plugin_update, 'update' ) || ! property_exists( $plugin_update->update, 'new_version' ) || empty( $plugin_update->update->new_version ) ) {
continue;
}
$information['plugin_updates'][ $slug ] = $plugin_update;
}
}
if ( null !== $this->filterFunction ) {
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
}
// to fix premium plugs update.
$cached_plugins_update = get_site_transient( 'mainwp_update_plugins_cached' );
if ( is_array( $cached_plugins_update ) && ( count( $cached_plugins_update ) > 0 ) ) {
if ( ! isset( $information['plugin_updates'] ) ) {
$information['plugin_updates'] = array();
}
foreach ( $cached_plugins_update as $slug => $plugin_update ) {
// to fix incorrect info.
if ( ! property_exists( $plugin_update, 'new_version' ) || empty( $plugin_update->new_version ) ) { // may do not need to check this?
// to fix for some premiums update info.
if ( property_exists( $plugin_update, 'update' ) ) {
if ( ! property_exists( $plugin_update->update, 'new_version' ) || empty( $plugin_update->update->new_version ) ) {
continue;
}
} else {
continue;
}
}
if ( ! isset( $information['plugin_updates'][ $slug ] ) ) {
$information['plugin_updates'][ $slug ] = $plugin_update;
}
}
}
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';
$theme_updates = MainWP_Child_Updates::get_instance()->upgrade_get_theme_updates();
if ( is_array( $theme_updates ) ) {
$information['theme_updates'] = array();
foreach ( $theme_updates as $slug => $theme_update ) {
$name = ( is_array( $theme_update ) ? $theme_update['Name'] : $theme_update->Name );
if ( in_array( $name, $premiumThemes ) ) {
continue;
}
$information['theme_updates'][ $slug ] = $theme_update;
}
}
if ( null !== $this->filterFunction ) {
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
}
// to fix premium themes update.
$cached_themes_update = get_site_transient( 'mainwp_update_themes_cached' );
if ( is_array( $cached_themes_update ) && ( count( $cached_themes_update ) > 0 ) ) {
if ( ! isset( $information['theme_updates'] ) ) {
$information['theme_updates'] = array();
}
foreach ( $cached_themes_update as $slug => $theme_update ) {
$name = ( is_array( $theme_update ) ? $theme_update['Name'] : $theme_update->Name );
if ( in_array( $name, $premiumThemes ) ) {
continue;
}
if ( isset( $information['theme_updates'][ $slug ] ) ) {
continue;
}
$information['theme_updates'][ $slug ] = $theme_update;
}
}
$translation_updates = wp_get_translation_updates();
if ( ! empty( $translation_updates ) ) {
$information['translation_updates'] = array();
foreach ( $translation_updates as $translation_update ) {
$new_translation_update = array(
'type' => $translation_update->type,
'slug' => $translation_update->slug,
'language' => $translation_update->language,
'version' => $translation_update->version,
);
if ( 'plugin' === $translation_update->type ) {
$all_plugins = get_plugins();
foreach ( $all_plugins as $file => $plugin ) {
$path = dirname( $file );
if ( $path == $translation_update->slug ) {
$new_translation_update['name'] = $plugin['Name'];
break;
}
}
} elseif ( 'theme' === $translation_update->type ) {
$theme = wp_get_theme( $translation_update->slug );
$new_translation_update['name'] = $theme->name;
} elseif ( ( 'core' === $translation_update->type ) && ( 'default' === $translation_update->slug ) ) {
$new_translation_update['name'] = 'WordPress core';
}
$information['translation_updates'][] = $new_translation_update;
}
}
$information['recent_comments'] = MainWP_Child_Posts::get_instance()->get_recent_comments( array( 'approve', 'hold' ), 5 );
$recent_number = 5;
if ( isset( $_POST ) && isset( $_POST['recent_number'] ) ) {
$recent_number = $_POST['recent_number'];
if ( get_option( 'mainwp_child_recent_number', 5 ) != $recent_number ) {
update_option( 'mainwp_child_recent_number', $recent_number );
}
} else {
$recent_number = get_option( 'mainwp_child_recent_number', 5 );
}
if ( $recent_number <= 0 || $recent_number > 30 ) {
$recent_number = 5;
}
$information['recent_posts'] = MainWP_Child_Posts::get_instance()->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number );
$information['recent_pages'] = MainWP_Child_Posts::get_instance()->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number, 'page' );
$information['securityIssues'] = MainWP_Security::get_stats_security();
// Directory listings!
$information['directories'] = $this->scan_dir( ABSPATH, 3 );
$cats = get_categories(
array(
'hide_empty' => 0,
'hierarchical' => true,
'number' => 300,
)
);
$categories = array();
foreach ( $cats as $cat ) {
$categories[] = $cat->name;
}
$information['categories'] = $categories;
$get_file_size = apply_filters_deprecated( 'mainwp-child-get-total-size', array( true ), '4.0.7.1', 'mainwp_child_get_total_size' );
$get_file_size = apply_filters( 'mainwp_child_get_total_size', $get_file_size );
if ( $get_file_size && isset( $_POST['cloneSites'] ) && ( '0' !== $_POST['cloneSites'] ) ) {
$max_exe = ini_get( 'max_execution_time' );
if ( $max_exe > 20 ) {
$information['totalsize'] = $this->get_total_file_size();
}
}
$information['dbsize'] = MainWP_Child_DB::get_size();
global $mainWPChild;
$max_his = $mainWPChild->get_max_history();
$auths = get_option( 'mainwp_child_auth' );
$information['extauth'] = ( $auths && isset( $auths[ $max_his ] ) ? $auths[ $max_his ] : null );
$plugins = $this->get_all_plugins_int( false );
$themes = $this->get_all_themes_int( false );
$information['plugins'] = $plugins;
$information['themes'] = $themes;
if ( isset( $_POST['optimize'] ) && ( '1' === $_POST['optimize'] ) ) {
$information['users'] = MainWP_Child_Users::get_instance()->get_all_users_int( 500 );
}
if ( isset( $_POST['primaryBackup'] ) && ! empty( $_POST['primaryBackup'] ) ) {
$primary_bk = $_POST['primaryBackup'];
$information['primaryLasttimeBackup'] = MainWP_Helper::get_lasttime_backup( $primary_bk );
}
$last_post = wp_get_recent_posts( array( 'numberposts' => absint( '1' ) ) );
if ( isset( $last_post[0] ) ) {
$last_post = $last_post[0];
}
if ( isset( $last_post ) && isset( $last_post['post_modified_gmt'] ) ) {
$information['last_post_gmt'] = strtotime( $last_post['post_modified_gmt'] );
}
$information['mainwpdir'] = ( MainWP_Helper::validate_mainwp_dir() ? 1 : - 1 );
$information['uniqueId'] = get_option( 'mainwp_child_uniqueId', '' );
$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();
if ( isset( $_POST['user'] ) ) {
$user = get_user_by( 'login', $_POST['user'] );
if ( $user && property_exists( $user, 'ID' ) && $user->ID ) {
$information['admin_nicename'] = $user->data->user_nicename;
$information['admin_useremail'] = $user->data->user_email;
}
}
try {
do_action( 'mainwp_child_site_stats' );
} catch ( \Exception $e ) {
MainWP_Helper::log_debug( $e->getMessage() );
}
if ( isset( $_POST['othersData'] ) ) {
$othersData = json_decode( stripslashes( $_POST['othersData'] ), true );
if ( ! is_array( $othersData ) ) {
$othersData = array();
}
if ( isset( $othersData['wpvulndbToken'] ) ) {
$wpvulndb_token = get_option( 'mainwp_child_wpvulndb_token', '' );
if ( $wpvulndb_token != $othersData['wpvulndbToken'] ) {
MainWP_Helper::update_option( 'mainwp_child_wpvulndb_token', $othersData['wpvulndbToken'] );
}
}
try {
$information = apply_filters_deprecated( 'mainwp-site-sync-others-data', array( $information, $othersData ), '4.0.7.1', 'mainwp_site_sync_others_data' );
$information = apply_filters( 'mainwp_site_sync_others_data', $information, $othersData );
} catch ( \Exception $e ) {
MainWP_Helper::log_debug( $e->getMessage() );
}
}
if ( $exit ) {
mainwp_child_helper()->write( $information );
}
return $information;
}
public function update_external_settings() {
$update_htaccess = false;
if ( isset( $_POST['cloneSites'] ) ) {
if ( '0' !== $_POST['cloneSites'] ) {
$arr = json_decode( urldecode( $_POST['cloneSites'] ), 1 );
MainWP_Helper::update_option( 'mainwp_child_clone_sites', ( ! is_array( $arr ) ? array() : $arr ) );
} else {
MainWP_Helper::update_option( 'mainwp_child_clone_sites', '0' );
}
}
if ( isset( $_POST['siteId'] ) ) {
MainWP_Helper::update_option( 'mainwp_child_siteid', intval( $_POST['siteId'] ) );
}
if ( isset( $_POST['pluginDir'] ) ) {
if ( get_option( 'mainwp_child_pluginDir' ) !== $_POST['pluginDir'] ) {
MainWP_Helper::update_option( 'mainwp_child_pluginDir', $_POST['pluginDir'], 'yes' );
$update_htaccess = true;
}
} elseif ( false !== get_option( 'mainwp_child_pluginDir' ) ) {
MainWP_Helper::update_option( 'mainwp_child_pluginDir', false, 'yes' );
$update_htaccess = true;
}
if ( $update_htaccess ) {
global $mainWPChild;
$mainWPChild->update_htaccess( true );
}
}
public function get_total_file_size( $directory = WP_CONTENT_DIR ) {
try {
if ( MainWP_Helper::function_exists( 'popen' ) ) {
$uploadDir = MainWP_Helper::get_mainwp_dir();
$uploadDir = $uploadDir[0];
$popenHandle = popen( 'du -s ' . $directory . ' --exclude "' . str_replace( ABSPATH, '', $uploadDir ) . '"', 'r' ); // phpcs:ignore -- run if enabled.
if ( 'resource' === gettype( $popenHandle ) ) {
$size = fread( $popenHandle, 1024 );
pclose( $popenHandle );
$size = substr( $size, 0, strpos( $size, "\t" ) );
if ( $size && MainWP_Helper::ctype_digit( $size ) ) {
return $size / 1024;
}
}
}
if ( MainWP_Helper::function_exists( 'shell_exec' ) ) {
$uploadDir = MainWP_Helper::get_mainwp_dir();
$uploadDir = $uploadDir[0];
$size = shell_exec( 'du -s ' . $directory . ' --exclude "' . str_replace( ABSPATH, '', $uploadDir ) . '"' ); // phpcs:ignore -- run if enabled.
if ( null !== $size ) {
$size = substr( $size, 0, strpos( $size, "\t" ) );
if ( $size && MainWP_Helper::ctype_digit( $size ) ) {
return $size / 1024;
}
}
}
if ( class_exists( 'COM' ) ) {
$obj = new COM( 'scripting.filesystemobject' );
if ( is_object( $obj ) ) {
$ref = $obj->getfolder( $directory );
$size = $ref->size;
$obj = null;
if ( MainWP_Helper::ctype_digit( $size ) ) {
return $size / 1024;
}
}
}
// to fix for window host, performance not good?
if ( class_exists( 'RecursiveIteratorIterator' ) ) {
$size = 0;
foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $directory ) ) as $file ) {
$size += $file->getSize();
}
if ( $size && MainWP_Helper::ctype_digit( $size ) ) {
return $size / 1024 / 1024;
}
}
return 0;
} catch ( \Exception $e ) {
return 0;
}
}
public function scan_dir( $pDir, $pLvl ) {
$output = array();
if ( file_exists( $pDir ) && is_dir( $pDir ) ) {
if ( 'logs' === basename( $pDir ) ) {
return empty( $output ) ? null : $output;
}
if ( 0 === $pLvl ) {
return empty( $output ) ? null : $output;
}
$files = $this->int_scan_dir( $pDir );
if ( $files ) {
foreach ( $files as $file ) {
if ( ( '.' === $file ) || ( '..' === $file ) ) {
continue;
}
$newDir = $pDir . $file . DIRECTORY_SEPARATOR;
if ( is_dir( $newDir ) ) {
$output[ $file ] = $this->scan_dir( $newDir, $pLvl - 1, false );
}
}
unset( $files );
$files = null;
}
}
return empty( $output ) ? null : $output;
}
public function int_scan_dir( $dir ) {
$dh = opendir( $dir );
if ( is_dir( $dir ) && $dh ) {
$cnt = 0;
$out = array();
$file = readdir( $dh );
while ( false !== $file ) {
$newDir = $dir . $file . DIRECTORY_SEPARATOR;
if ( ! is_dir( $newDir ) ) {
continue;
}
$out[] = $file;
if ( $cnt ++ > 10 ) {
return $out;
}
}
closedir( $dh );
return $out;
}
return false;
}
public function get_all_themes() {
$keyword = $_POST['keyword'];
$status = $_POST['status'];
$filter = isset( $_POST['filter'] ) ? $_POST['filter'] : true;
$rslt = $this->get_all_themes_int( $filter, $keyword, $status );
mainwp_child_helper()->write( $rslt );
}
public function get_all_themes_int( $filter, $keyword = '', $status = '' ) {
$rslt = array();
$themes = wp_get_themes();
if ( is_array( $themes ) ) {
$theme_name = wp_get_theme()->get( 'Name' );
/** @var $theme WP_Theme */
foreach ( $themes as $theme ) {
$out = array();
$out['name'] = $theme->get( 'Name' );
$out['title'] = $theme->display( 'Name', true, false );
$out['description'] = $theme->display( 'Description', true, false );
$out['version'] = $theme->display( 'Version', true, false );
$out['active'] = ( $theme->get( 'Name' ) === $theme_name ) ? 1 : 0;
$out['slug'] = $theme->get_stylesheet();
if ( ! $filter ) {
if ( '' == $keyword || stristr( $out['title'], $keyword ) ) {
$rslt[] = $out;
}
} elseif ( ( ( 'active' === $status ) ? 1 : 0 ) === $out['active'] ) {
if ( '' == $keyword || stristr( $out['title'], $keyword ) ) {
$rslt[] = $out;
}
}
}
}
return $rslt;
}
public function get_all_plugins() {
$keyword = $_POST['keyword'];
$status = $_POST['status'];
$filter = isset( $_POST['filter'] ) ? $_POST['filter'] : true;
$rslt = $this->get_all_plugins_int( $filter, $keyword, $status );
mainwp_child_helper()->write( $rslt );
}
public function get_all_plugins_int( $filter, $keyword = '', $status = '' ) {
if ( ! function_exists( 'get_plugins' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
global $mainWPChild;
$rslt = array();
$plugins = get_plugins();
if ( is_array( $plugins ) ) {
$active_plugins = get_option( 'active_plugins' );
foreach ( $plugins as $pluginslug => $plugin ) {
$out = array();
$out['mainwp'] = ( $pluginslug == $mainWPChild->plugin_slug ? 'T' : 'F' );
$out['name'] = $plugin['Name'];
$out['slug'] = $pluginslug;
$out['description'] = $plugin['Description'];
$out['version'] = $plugin['Version'];
$out['active'] = is_plugin_active( $pluginslug ) ? 1 : 0;
if ( ! $filter ) {
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
$rslt[] = $out;
}
} elseif ( ( ( 'active' == $status ) ? 1 : 0 ) == $out['active'] ) {
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
$rslt[] = $out;
}
}
}
}
$muplugins = get_mu_plugins();
if ( is_array( $muplugins ) ) {
foreach ( $muplugins as $pluginslug => $plugin ) {
$out = array();
$out['mainwp'] = ( $pluginslug == $mainWPChild->plugin_slug ? 'T' : 'F' );
$out['name'] = $plugin['Name'];
$out['slug'] = $pluginslug;
$out['description'] = $plugin['Description'];
$out['version'] = $plugin['Version'];
$out['active'] = 1;
$out['mu'] = 1;
if ( ! $filter ) {
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
$rslt[] = $out;
}
} elseif ( ( ( 'active' == $status ) ? 1 : 0 ) == $out['active'] ) {
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
$rslt[] = $out;
}
}
}
}
return $rslt;
}
}

View file

@ -350,12 +350,27 @@ class MainWP_Child_Updates {
$information['upgrades'][ $slug ] = false;
}
}
}
$information['sync'] = $this->get_site_stats( array(), false );
}
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
mainwp_child_helper()->write( $information );
}
public function upgrade_get_theme_updates() {
$themeUpdates = get_theme_updates();
$newThemeUpdates = array();
if ( is_array( $themeUpdates ) ) {
foreach ( $themeUpdates as $slug => $themeUpdate ) {
$newThemeUpdate = array();
$newThemeUpdate['update'] = $themeUpdate->update;
$newThemeUpdate['Name'] = MainWP_Helper::search( $themeUpdate, 'Name' );
$newThemeUpdate['Version'] = MainWP_Helper::search( $themeUpdate, 'Version' );
$newThemeUpdates[ $slug ] = $newThemeUpdate;
}
}
return $newThemeUpdates;
}
public function hook_fix_optimize_press_theme_update( $transient ) {
if ( ! defined( 'OP_FUNC' ) ) {
return $transient;
@ -464,18 +479,15 @@ class MainWP_Child_Updates {
if ( 'plugin' == $type || 'theme' == $type ) {
$list = isset( $_GET['list'] ) ? $_GET['list'] : '';
if ( ! empty( $list ) ) {
// to call function upgrade_plugin_theme().
if ( ! empty( $list ) ) {
$_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 ] ) );
}
$function = 'upgradeplugintheme'; // to call function upgrade_plugin_theme().
if ( MainWP_Child_Callable::get_instance()->is_callable_function( $function ) ) {
MainWP_Child_Callable::get_instance()->call_function( $function );
}
}
}
}
@ -745,9 +757,9 @@ class MainWP_Child_Updates {
}
} else {
$information['upgrades'] = array(); // to fix error message when translations updated.
}
$information['sync'] = $this->get_site_stats( array(), false );
}
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
mainwp_child_helper()->write( $information );
}
}
}

View file

@ -0,0 +1,470 @@
<?php
namespace MainWP\Child;
class MainWP_Child_Users {
protected static $instance = null;
/**
* Method get_class_name()
*
* Get Class Name.
*
* @return object
*/
public static function get_class_name() {
return __CLASS__;
}
public function __construct() {
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function user_action() {
$action = $_POST['action'];
$extra = $_POST['extra'];
$userId = $_POST['id'];
$user_pass = $_POST['user_pass'];
$failed = false;
global $current_user;
$reassign = ( isset( $current_user ) && isset( $current_user->ID ) ) ? $current_user->ID : 0;
include_once ABSPATH . '/wp-admin/includes/user.php';
if ( 'delete' === $action ) {
wp_delete_user( $userId, $reassign );
} elseif ( 'changeRole' === $action ) {
$my_user = array();
$my_user['ID'] = $userId;
$my_user['role'] = $extra;
wp_update_user( $my_user );
} elseif ( 'update_password' === $action ) {
$my_user = array();
$my_user['ID'] = $userId;
$my_user['user_pass'] = $user_pass;
wp_update_user( $my_user );
} elseif ( 'edit' === $action ) {
$user_data = $this->get_user_to_edit( $userId );
if ( ! empty( $user_data ) ) {
$information['user_data'] = $user_data;
} else {
$failed = true;
}
} elseif ( 'update_user' === $action ) {
$my_user = $_POST['extra'];
if ( is_array( $my_user ) ) {
foreach ( $my_user as $idx => $val ) {
if ( 'donotupdate' === $val || ( empty( $val ) && 'role' !== $idx ) ) {
unset( $my_user[ $idx ] );
}
}
$result = $this->edit_user( $userId, $my_user );
if ( is_array( $result ) && isset( $result['error'] ) ) {
$information['error'] = $result['error'];
}
} else {
$failed = true;
}
} else {
$failed = true;
}
if ( $failed ) {
$information['status'] = 'FAIL';
}
if ( ! isset( $information['status'] ) && ! isset( $information['error'] ) ) {
$information['status'] = 'SUCCESS';
if ( 'update_user' === $action && isset( $_POST['optimize'] ) && ! empty( $_POST['optimize'] ) ) {
$information['users'] = $this->get_all_users_int( 500 );
}
}
mainwp_child_helper()->write( $information );
}
public function get_all_users_int( $number = false ) {
$allusers = array();
$params = array();
if ( $number ) {
$params['number'] = $number;
}
$new_users = get_users( $params );
if ( is_array( $new_users ) ) {
foreach ( $new_users as $new_user ) {
$usr = array();
$usr['id'] = $new_user->ID;
$usr['login'] = $new_user->user_login;
$usr['nicename'] = $new_user->user_nicename;
$usr['email'] = $new_user->user_email;
$usr['registered'] = $new_user->user_registered;
$usr['status'] = $new_user->user_status;
$usr['display_name'] = $new_user->display_name;
$userdata = get_userdata( $new_user->ID );
$user_roles = $userdata->roles;
$user_role = array_shift( $user_roles );
$usr['role'] = $user_role;
$usr['post_count'] = count_user_posts( $new_user->ID );
$allusers[] = $usr;
}
}
return $allusers;
}
public function get_all_users( $return = false ) {
$roles = explode( ',', $_POST['role'] );
$allusers = array();
if ( is_array( $roles ) ) {
foreach ( $roles as $role ) {
$new_users = get_users( 'role=' . $role );
foreach ( $new_users as $new_user ) {
$usr = array();
$usr['id'] = $new_user->ID;
$usr['login'] = $new_user->user_login;
$usr['nicename'] = $new_user->user_nicename;
$usr['email'] = $new_user->user_email;
$usr['registered'] = $new_user->user_registered;
$usr['status'] = $new_user->user_status;
$usr['display_name'] = $new_user->display_name;
$usr['role'] = $role;
$usr['post_count'] = count_user_posts( $new_user->ID );
$usr['avatar'] = get_avatar( $new_user->ID, 32 );
$allusers[] = $usr;
}
}
}
if ( $return ) {
return $allusers;
}
mainwp_child_helper()->write( $allusers );
}
public function search_users() {
$search_user_role = array();
$check_users_role = false;
if ( isset( $_POST['role'] ) && ! empty( $_POST['role'] ) ) {
$check_users_role = true;
$all_users_role = $this->get_all_users( true );
foreach ( $all_users_role as $user ) {
$search_user_role[] = $user['id'];
}
unset( $all_users_role );
}
$columns = explode( ',', $_POST['search_columns'] );
$allusers = array();
$exclude = array();
foreach ( $columns as $col ) {
if ( empty( $col ) ) {
continue;
}
$user_query = new WP_User_Query(
array(
'search' => $_POST['search'],
'fields' => 'all_with_meta',
'search_columns' => array( $col ),
'query_orderby' => array( $col ),
'exclude' => $exclude,
)
);
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $new_user ) {
if ( $check_users_role ) {
if ( ! in_array( $new_user->ID, $search_user_role ) ) {
continue;
}
}
$exclude[] = $new_user->ID;
$usr = array();
$usr['id'] = $new_user->ID;
$usr['login'] = $new_user->user_login;
$usr['nicename'] = $new_user->user_nicename;
$usr['email'] = $new_user->user_email;
$usr['registered'] = $new_user->user_registered;
$usr['status'] = $new_user->user_status;
$usr['display_name'] = $new_user->display_name;
$userdata = get_userdata( $new_user->ID );
$user_roles = $userdata->roles;
$user_role = array_shift( $user_roles );
$usr['role'] = $user_role;
$usr['post_count'] = count_user_posts( $new_user->ID );
$usr['avatar'] = get_avatar( $new_user->ID, 32 );
$allusers[] = $usr;
}
}
}
mainwp_child_helper()->write( $allusers );
}
public function edit_user( $user_id, $data ) {
$wp_roles = wp_roles();
$user = new stdClass();
$update = true;
if ( $user_id ) {
$user->ID = (int) $user_id;
$userdata = get_userdata( $user_id );
$user->user_login = wp_slash( $userdata->user_login );
} else {
return array( 'error' => 'ERROR: Empty user id.' );
}
$pass1 = '';
$pass2 = '';
if ( isset( $data['pass1'] ) ) {
$pass1 = $data['pass1'];
}
if ( isset( $data['pass2'] ) ) {
$pass2 = $data['pass2'];
}
if ( isset( $data['role'] ) && current_user_can( 'edit_users' ) ) {
$new_role = sanitize_text_field( $data['role'] );
$potential_role = isset( $wp_roles->role_objects[ $new_role ] ) ? $wp_roles->role_objects[ $new_role ] : false;
// Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
// Multisite super admins can freely edit their blog roles -- they possess all caps.
if ( ( is_multisite() && current_user_can( 'manage_sites' ) ) || get_current_user_id() != $user_id || ( $potential_role && $potential_role->has_cap( 'edit_users' ) ) ) {
$user->role = $new_role;
}
// If the new role isn't editable by the logged-in user die with error.
$editable_roles = get_editable_roles();
if ( ! empty( $new_role ) && empty( $editable_roles[ $new_role ] ) ) {
return array( 'error' => 'You can&#8217;t give users that role.' );
}
}
$email = '';
if ( isset( $data['email'] ) ) {
$email = trim( $data['email'] );
}
if ( ! empty( $email ) ) {
$user->user_email = sanitize_text_field( wp_unslash( $email ) );
} else {
$user->user_email = $userdata->user_email;
}
if ( isset( $data['url'] ) ) {
if ( empty( $data['url'] ) || 'http://' == $data['url'] ) {
$user->user_url = '';
} else {
$user->user_url = esc_url_raw( $data['url'] );
$protocols = implode( '|', array_map( 'preg_quote', wp_allowed_protocols() ) );
$user->user_url = preg_match( '/^(' . $protocols . '):/is', $user->user_url ) ? $user->user_url : 'http://' . $user->user_url;
}
}
if ( isset( $data['first_name'] ) ) {
$user->first_name = sanitize_text_field( $data['first_name'] );
}
if ( isset( $data['last_name'] ) ) {
$user->last_name = sanitize_text_field( $data['last_name'] );
}
if ( isset( $data['nickname'] ) && ! empty( $data['nickname'] ) ) {
$user->nickname = sanitize_text_field( $data['nickname'] );
}
if ( isset( $data['display_name'] ) ) {
$user->display_name = sanitize_text_field( $data['display_name'] );
}
if ( isset( $data['description'] ) ) {
$user->description = trim( $data['description'] );
}
$errors = new \WP_Error();
// checking that username has been typed.
if ( '' == $user->user_login ) {
$errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' ) );
}
do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) );
if ( ! empty( $pass1 ) || ! empty( $pass2 ) ) {
// Check for blank password when adding a user.
if ( ! $update && empty( $pass1 ) ) {
$errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter a password.' ), array( 'form-field' => 'pass1' ) );
}
// Check for "\" in password.
if ( false !== strpos( wp_unslash( $pass1 ), '\\' ) ) {
$errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) );
}
// Checking the password has been typed twice the same.
if ( ( $update || ! empty( $pass1 ) ) && $pass1 != $pass2 ) {
$errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) );
}
if ( ! empty( $pass1 ) ) {
$user->user_pass = $pass1;
}
} else {
$user->user_pass = $userdata->user_pass;
}
$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
if ( in_array( strtolower( $user->user_login ), array_map( 'strtolower', $illegal_logins ) ) ) {
$errors->add( 'invalid_username', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) );
}
$owner_id = email_exists( $user->user_email );
if ( empty( $user->user_email ) ) {
$errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an email address.' ), array( 'form-field' => 'email' ) );
} elseif ( ! is_email( $user->user_email ) ) {
$errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn&#8217;t correct.' ), array( 'form-field' => 'email' ) );
} elseif ( ( $owner_id ) && ( ! $update || ( $owner_id != $user->ID ) ) ) {
$errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ), array( 'form-field' => 'email' ) );
}
do_action_ref_array( 'user_profile_update_errors', array( &$errors, $update, &$user ) );
if ( $errors->get_error_codes() ) {
$error_str = '';
foreach ( $errors->get_error_messages() as $message ) {
if ( is_string( $message ) ) {
$error_str .= ' ' . esc_html( wp_strip_all_tags( $message ) );
}
}
return array( 'error' => $error_str );
}
$user_id = wp_update_user( $user );
return $user_id;
}
public function get_user_to_edit( $user_id ) {
require_once ABSPATH . 'wp-admin/includes/user.php';
$profileuser = get_user_to_edit( $user_id );
$edit_data = array();
if ( is_object( $profileuser ) ) {
$user_roles = array_intersect( array_values( $profileuser->roles ), array_keys( get_editable_roles() ) );
$user_role = reset( $user_roles );
$edit_data['role'] = $user_role;
$edit_data['first_name'] = $profileuser->first_name;
$edit_data['last_name'] = $profileuser->last_name;
$edit_data['nickname'] = $profileuser->nickname;
$public_display = array();
$public_display['display_nickname'] = $profileuser->nickname;
$public_display['display_username'] = $profileuser->user_login;
if ( ! empty( $profileuser->first_name ) ) {
$public_display['display_firstname'] = $profileuser->first_name;
}
if ( ! empty( $profileuser->last_name ) ) {
$public_display['display_lastname'] = $profileuser->last_name;
}
if ( ! empty( $profileuser->first_name ) && ! empty( $profileuser->last_name ) ) {
$public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
$public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
}
if ( ! in_array( $profileuser->display_name, $public_display ) ) { // Only add this if it isn't duplicated elsewhere!
$public_display = array( 'display_displayname' => $profileuser->display_name ) + $public_display;
}
$public_display = array_map( 'trim', $public_display );
$public_display = array_unique( $public_display );
$edit_data['public_display'] = $public_display;
$edit_data['display_name'] = $profileuser->display_name;
$edit_data['user_email'] = $profileuser->user_email;
$edit_data['user_url'] = $profileuser->user_url;
foreach ( wp_get_user_contact_methods( $profileuser ) as $name => $desc ) {
$edit_data['contact_methods'][ $name ] = $profileuser->$name;
}
$edit_data['description'] = $profileuser->description;
}
return $edit_data;
}
public function new_admin_password() {
$new_password = maybe_unserialize( base64_decode( $_POST['new_password'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
$user = get_user_by( 'login', $_POST['user'] );
require_once ABSPATH . WPINC . '/registration.php';
$id = wp_update_user(
array(
'ID' => $user->ID,
'user_pass' => $new_password['user_pass'],
)
);
if ( $id !== $user->ID ) {
if ( is_wp_error( $id ) ) {
MainWP_Helper::error( $id->get_error_message() );
} else {
MainWP_Helper::error( __( 'Administrator password could not be changed.', 'mainwp-child' ) );
}
}
$information['added'] = true;
mainwp_child_helper()->write( $information );
}
public function new_user() {
$new_user = maybe_unserialize( base64_decode( $_POST['new_user'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
$send_password = $_POST['send_password'];
if ( isset( $new_user['role'] ) ) {
if ( ! get_role( $new_user['role'] ) ) {
$new_user['role'] = 'subscriber';
}
}
$new_user_id = wp_insert_user( $new_user );
if ( is_wp_error( $new_user_id ) ) {
MainWP_Helper::error( $new_user_id->get_error_message() );
}
if ( 0 === $new_user_id ) {
MainWP_Helper::error( __( 'Undefined error!', 'mainwp-child' ) );
}
if ( $send_password ) {
$user = new WP_User( $new_user_id );
$user_login = stripslashes( $user->user_login );
$user_email = stripslashes( $user->user_email );
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
// we want to reverse this for the plain text arena of emails.
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
$message = sprintf( __( 'Username: %s' ), $user_login ) . "\r\n";
$message .= sprintf( __( 'Password: %s' ), $new_user['user_pass'] ) . "\r\n";
$message .= wp_login_url() . "\r\n";
wp_mail( $user_email, sprintf( __( '[%s] Your username and password' ), $blogname ), $message, '' );
}
$information['added'] = true;
mainwp_child_helper()->write( $information );
}
}

File diff suppressed because it is too large Load diff

View file

@ -4,9 +4,9 @@ namespace MainWP\Child;
class MainWP_Debug {
/**
* @param $mainwpChild MainWP_Child
* @param $mainWPChild MainWP_Child
*/
public static function process( &$mainwpChild ) {
public static function process( &$mainWPChild ) {
if ( ! isset( $_GET['mainwpdebug'] ) || ! defined( 'MAINWP_DEBUG' ) || ( MAINWP_DEBUG !== true ) ) {
return;
}
@ -21,11 +21,11 @@ class MainWP_Debug {
$_POST['excludezip'] = '1';
$_POST['excludenonwp'] = '1';
$_POST['ext'] = 'tar.gz';
print_r( $mainwpChild->backup( false ) ); // phpcs:ignore -- debug feature.
print_r( $mainWPChild->backup( false ) ); // phpcs:ignore -- debug feature.
} elseif ( 'test' == $_GET['mainwpdebug'] ) {
print_r( get_included_files() ); // phpcs:ignore -- debug feature.
} else {
print_r( $mainwpChild->get_site_stats( array(), false ) ); // phpcs:ignore -- debug feature.
print_r( MainWP_Child_Stats::get_instance()->get_site_stats( array(), false ) ); // phpcs:ignore -- debug feature.
}
$stop = microtime( true );

View file

@ -125,7 +125,7 @@ class MainWP_Helper {
if ( null !== $code ) {
$information['error_code'] = $code;
}
self::write( $information );
self::instance()->write( $information );
}
/**
@ -519,7 +519,7 @@ class MainWP_Helper {
$new_post['post_content'] = str_replace( $lnkToReplace, $linkToReplaceWith, $new_post['post_content'] );
}
} catch ( \Exception $e ) {
error_log( $e->getMessage() ); // phpcs:ignore -- debug mode only.
MainWP_Helper::log_debug( $e->getMessage() );
}
}
}
@ -1004,19 +1004,21 @@ class MainWP_Helper {
public static function check_wp_filesystem() {
$FTP_ERROR = 'Failed! Please, add FTP details for automatic updates.';
self::get_wp_filesystem();
global $wp_filesystem;
if ( empty( $wp_filesystem ) ) {
self::error( $this->FTP_ERROR );
self::error( $FTP_ERROR );
} elseif ( is_wp_error( $wp_filesystem->errors ) ) {
$errorCodes = $wp_filesystem->errors->get_error_codes();
if ( ! empty( $errorCodes ) ) {
self::error( __( 'WordPress Filesystem error: ', 'mainwp-child' ) . $wp_filesystem->errors->get_error_message() );
}
}
return $wp_filesystem;
}
@ -1751,7 +1753,7 @@ class MainWP_Helper {
// handle fatal errors and compile errors.
$error = error_get_last();
if ( isset( $error['type'] ) && isset( $error['message'] ) && ( E_ERROR === $error['type'] || E_COMPILE_ERROR === $error['type'] ) ) {
self::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
self::instance()->write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
}
}
@ -1786,4 +1788,9 @@ class MainWP_Helper {
return $return;
}
public static function log_debug( $msg ) {
if ( defined( 'MAINWP_DEBUG' ) && MAINWP_DEBUG ) {
error_log( $msg ); // phpcs:ignore -- debug mode only.
}
}
}

View file

@ -10,7 +10,7 @@
*/
require_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php'; // Version information from WordPress.
define( 'MAINWP_DEBUG', false );
define( 'MAINWP_DEBUG', true );
if ( ! defined( 'MAINWP_CHILD_FILE' ) ) {
define( 'MAINWP_CHILD_FILE', __FILE__ );