mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-08-31 03:53:15 +08:00
Refactoring
This commit is contained in:
parent
9d8ed1259c
commit
facfa16de8
11 changed files with 613 additions and 580 deletions
|
@ -203,29 +203,7 @@ class MainWP_Backup {
|
|||
if ( $zipRes ) {
|
||||
$nodes = glob( ABSPATH . '*' );
|
||||
if ( ! $includeCoreFiles ) {
|
||||
$coreFiles = array(
|
||||
'favicon.ico',
|
||||
'index.php',
|
||||
'license.txt',
|
||||
'readme.html',
|
||||
'wp-activate.php',
|
||||
'wp-app.php',
|
||||
'wp-blog-header.php',
|
||||
'wp-comments-post.php',
|
||||
'wp-config.php',
|
||||
'wp-config-sample.php',
|
||||
'wp-cron.php',
|
||||
'wp-links-opml.php',
|
||||
'wp-load.php',
|
||||
'wp-login.php',
|
||||
'wp-mail.php',
|
||||
'wp-pass.php',
|
||||
'wp-register.php',
|
||||
'wp-settings.php',
|
||||
'wp-signup.php',
|
||||
'wp-trackback.php',
|
||||
'xmlrpc.php',
|
||||
);
|
||||
$coreFiles = $this->get_core_files();
|
||||
foreach ( $nodes as $key => $node ) {
|
||||
if ( MainWP_Helper::starts_with( $node, ABSPATH . WPINC ) ) {
|
||||
unset( $nodes[ $key ] );
|
||||
|
@ -282,6 +260,32 @@ class MainWP_Backup {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function get_core_files(){
|
||||
return array(
|
||||
'favicon.ico',
|
||||
'index.php',
|
||||
'license.txt',
|
||||
'readme.html',
|
||||
'wp-activate.php',
|
||||
'wp-app.php',
|
||||
'wp-blog-header.php',
|
||||
'wp-comments-post.php',
|
||||
'wp-config.php',
|
||||
'wp-config-sample.php',
|
||||
'wp-cron.php',
|
||||
'wp-links-opml.php',
|
||||
'wp-load.php',
|
||||
'wp-login.php',
|
||||
'wp-mail.php',
|
||||
'wp-pass.php',
|
||||
'wp-register.php',
|
||||
'wp-settings.php',
|
||||
'wp-signup.php',
|
||||
'wp-trackback.php',
|
||||
'xmlrpc.php',
|
||||
);
|
||||
}
|
||||
|
||||
public function add_config(){
|
||||
global $wpdb;
|
||||
$plugins = array();
|
||||
|
|
|
@ -75,7 +75,7 @@ class MainWP_Child_Back_Up_WordPress {
|
|||
return $value;
|
||||
}
|
||||
|
||||
public function action() {
|
||||
public function action() { // phpcs:ignore -- ignore complex method notice.
|
||||
$information = array();
|
||||
if ( ! self::is_activated() ) {
|
||||
$information['error'] = 'NO_BACKUPWORDPRESS';
|
||||
|
@ -578,7 +578,7 @@ class MainWP_Child_Back_Up_WordPress {
|
|||
if ( $files ) {
|
||||
$this->render_table_files( $files, $schedule, $directory, $root_dir, $new_version, $site_size, $is_size_calculated );
|
||||
}
|
||||
?>
|
||||
?>
|
||||
<p class="submit">
|
||||
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_edit_exclude_done()" class="button-primary"><?php esc_html_e( 'Done', 'mainwp-child' ); ?></a>
|
||||
</p>
|
||||
|
@ -631,24 +631,24 @@ class MainWP_Child_Back_Up_WordPress {
|
|||
}
|
||||
|
||||
private function render_table_files( $files, $schedule, $directory, $root_dir, $new_version, $site_size, $is_size_calculated ){
|
||||
?>
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<?php
|
||||
$this->render_table_header_files( $root_dir, $directory, $schedule, $new_version, $site_size, $is_size_calculated );
|
||||
?>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$this->render_table_body_files( $files, $schedule, $root_dir, $new_version, $site_size, $is_size_calculated );
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
?>
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<?php
|
||||
$this->render_table_header_files( $root_dir, $directory, $schedule, $new_version, $site_size, $is_size_calculated );
|
||||
?>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$this->render_table_body_files( $files, $schedule, $root_dir, $new_version, $site_size, $is_size_calculated );
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
|
||||
private function render_table_header_files( $root_dir, $directory, $schedule, $new_version, $site_size, $is_size_calculated ){
|
||||
?>
|
||||
?>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th scope="col"><?php esc_html_e( 'Name', 'mainwp-child' ); ?></th>
|
||||
|
@ -720,7 +720,7 @@ class MainWP_Child_Back_Up_WordPress {
|
|||
<?php
|
||||
}
|
||||
|
||||
private function render_table_body_files( $files, $schedule, $root_dir, $new_version, $site_size, $is_size_calculated ){
|
||||
private function render_table_body_files( $files, $schedule, $root_dir, $new_version, $site_size, $is_size_calculated ){ // phpcs:ignore -- ignore complex method notice.
|
||||
|
||||
foreach ( $files as $size => $file ) {
|
||||
$is_excluded = false;
|
||||
|
|
|
@ -158,7 +158,7 @@ class MainWP_Child_Pagespeed {
|
|||
return $information;
|
||||
}
|
||||
|
||||
public function save_settings() {
|
||||
public function save_settings() { // phpcs:ignore -- ignore complex method notice.
|
||||
$current_values = get_option( 'gpagespeedi_options' );
|
||||
$checkstatus = apply_filters( 'gpi_check_status', false );
|
||||
if ( $checkstatus ) {
|
||||
|
@ -403,7 +403,7 @@ class MainWP_Child_Pagespeed {
|
|||
);
|
||||
}
|
||||
|
||||
public static function get_filter_options( $restrict_type = 'all' ) {
|
||||
public static function get_filter_options( $restrict_type = 'all' ) { // phpcs:ignore -- ignore complex method notice, third party credit.
|
||||
|
||||
$types = array();
|
||||
$gpi_options = get_option( 'gpagespeedi_options' );
|
||||
|
|
|
@ -50,12 +50,13 @@ class MainWP_Child_Posts {
|
|||
}
|
||||
|
||||
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'];
|
||||
|
@ -68,26 +69,11 @@ class MainWP_Child_Posts {
|
|||
}
|
||||
}
|
||||
$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' ) ) {
|
||||
|
@ -96,83 +82,99 @@ class MainWP_Child_Posts {
|
|||
}
|
||||
|
||||
$posts = get_posts( $args );
|
||||
|
||||
if ( is_array( $posts ) ) {
|
||||
if ( $wp_seo_enabled ) {
|
||||
$post_ids = array();
|
||||
foreach ( $posts as $post ) {
|
||||
$post_ids[] = $post->ID;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* 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/
|
||||
*
|
||||
*/
|
||||
$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 = $this->get_out_post( $post, $extra, $tokens );
|
||||
if ( $wp_seo_enabled ) {
|
||||
$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 ),
|
||||
'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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function get_out_post( $post, $extra, $tokens ){
|
||||
$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' );
|
||||
}
|
||||
}
|
||||
return $outPost;
|
||||
}
|
||||
|
||||
public function get_all_posts() {
|
||||
$post_type = ( isset( $_POST['post_type'] ) ? $_POST['post_type'] : 'post' );
|
||||
|
@ -659,62 +661,20 @@ class MainWP_Child_Posts {
|
|||
|
||||
private function create_post( $new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags, $others = array() ) {
|
||||
|
||||
global $current_user;
|
||||
|
||||
/**
|
||||
* Hook: `mainwp_before_post_update`
|
||||
*
|
||||
* Runs before creating or updating a post via MainWP dashboard.
|
||||
*
|
||||
* @param array $new_post – Post data array.
|
||||
* @param array $post_custom – Post custom meta data.
|
||||
* @param string $post_category – Post categories.
|
||||
* @param string $post_tags – Post tags.
|
||||
* @param array $new_post – Post data array.
|
||||
* @param array $post_custom – Post custom meta data.
|
||||
* @param string $post_category – Post categories.
|
||||
* @param string $post_tags – Post tags.
|
||||
*/
|
||||
|
||||
do_action( 'mainwp_before_post_update', $new_post, $post_custom, $post_category, $post_tags );
|
||||
|
||||
$this->create_wp_rocket( $post_custom );
|
||||
|
||||
// current user may be connected admin or alternative admin.
|
||||
$current_uid = $current_user->ID;
|
||||
// Set up a new post (adding addition information).
|
||||
|
||||
$post_author = isset( $new_post['post_author'] ) ? $new_post['post_author'] : $current_uid;
|
||||
|
||||
if ( isset( $new_post['custom_post_author'] ) && ! empty( $new_post['custom_post_author'] ) ) {
|
||||
$_author = get_user_by( 'login', $new_post['custom_post_author'] );
|
||||
if ( ! empty( $_author ) ) {
|
||||
$new_post['post_author'] = $_author->ID;
|
||||
} else {
|
||||
$new_post['post_author'] = $current_uid;
|
||||
}
|
||||
unset( $new_post['custom_post_author'] );
|
||||
}
|
||||
|
||||
$post_author = ! empty( $post_author ) ? $post_author : $current_uid;
|
||||
$new_post['post_author'] = $post_author;
|
||||
|
||||
// post plus extension process.
|
||||
$is_post_plus = isset( $post_custom['_mainwp_post_plus'] ) ? true : false;
|
||||
|
||||
$wp_error = null;
|
||||
|
||||
if ( $is_post_plus ) {
|
||||
if ( isset( $new_post['post_date_gmt'] ) && ! empty( $new_post['post_date_gmt'] ) && '0000-00-00 00:00:00' != $new_post['post_date_gmt'] ) {
|
||||
$post_date_timestamp = strtotime( $new_post['post_date_gmt'] ) + get_option( 'gmt_offset' ) * 60 * 60;
|
||||
$new_post['post_date'] = date( 'Y-m-d H:i:s', $post_date_timestamp ); // phpcs:ignore -- local time.
|
||||
}
|
||||
}
|
||||
|
||||
do_action( 'mainwp_before_post_update', $new_post, $post_custom, $post_category, $post_tags );
|
||||
$edit_post_id = 0;
|
||||
|
||||
if ( isset( $post_custom['_mainwp_edit_post_id'] ) && $post_custom['_mainwp_edit_post_id'] ) {
|
||||
$edit_post_id = current( $post_custom['_mainwp_edit_post_id'] );
|
||||
} elseif ( isset( $new_post['ID'] ) && $new_post['ID'] ) {
|
||||
$edit_post_id = $new_post['ID'];
|
||||
}
|
||||
|
||||
$is_post_plus = false;
|
||||
$this->set_post_custom_data( $new_post, $post_custom, $post_tags, $edit_post_id, $is_post_plus );
|
||||
require_once ABSPATH . 'wp-admin/includes/post.php';
|
||||
if ( $edit_post_id ) {
|
||||
$user_id = wp_check_post_lock( $edit_post_id );
|
||||
|
@ -724,28 +684,16 @@ class MainWP_Child_Posts {
|
|||
return array( 'error' => $error );
|
||||
}
|
||||
}
|
||||
|
||||
$check_image_existed = false;
|
||||
if ( $edit_post_id ) {
|
||||
$check_image_existed = true; // if editing post then will check if image existed.
|
||||
}
|
||||
|
||||
$check_image_existed = $edit_post_id ? true : false; // if editing post then will check if image existed.
|
||||
$this->create_found_images( $new_post, $upload_dir, $check_image_existed );
|
||||
$this->create_has_shortcode_gallery( $new_post );
|
||||
|
||||
if ( $is_post_plus ) {
|
||||
$this->create_post_plus( $new_post, $post_custom );
|
||||
}
|
||||
|
||||
if ( isset( $post_tags ) && '' !== $post_tags ) {
|
||||
$new_post['tags_input'] = $post_tags;
|
||||
}
|
||||
|
||||
// Save the post to the WP.
|
||||
remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); // to fix brake scripts or html.
|
||||
$post_status = $new_post['post_status'];
|
||||
$new_post['post_status'] = 'auto-draft'; // child reports: to logging as created post.
|
||||
|
||||
$post_status = $new_post['post_status']; // save post_status.
|
||||
$new_post['post_status'] = 'auto-draft'; // to fix reports: to logging as created post.
|
||||
// update post.
|
||||
if ( $edit_post_id ) {
|
||||
// check if post existed.
|
||||
|
@ -754,10 +702,9 @@ class MainWP_Child_Posts {
|
|||
$new_post['ID'] = $edit_post_id;
|
||||
}
|
||||
$new_post['post_status'] = $post_status; // child reports: to logging as update post.
|
||||
}
|
||||
|
||||
}
|
||||
$wp_error = null;
|
||||
$new_post_id = wp_insert_post( $new_post, $wp_error );
|
||||
|
||||
// Show errors if something went wrong.
|
||||
if ( is_wp_error( $wp_error ) ) {
|
||||
return $wp_error->get_error_message();
|
||||
|
@ -765,7 +712,6 @@ class MainWP_Child_Posts {
|
|||
if ( empty( $new_post_id ) ) {
|
||||
return array( 'error' => 'Empty post id' );
|
||||
}
|
||||
|
||||
if ( ! $edit_post_id ) {
|
||||
wp_update_post(
|
||||
array(
|
||||
|
@ -774,14 +720,11 @@ class MainWP_Child_Posts {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->update_post_data( $new_post_id, $post_custom, $post_category, $post_featured_image, $check_image_existed, $is_post_plus );
|
||||
|
||||
// unlock if edit post.
|
||||
if ( $edit_post_id ) {
|
||||
update_post_meta( $edit_post_id, '_edit_lock', '' );
|
||||
}
|
||||
|
||||
$permalink = get_permalink( $new_post_id );
|
||||
$ret['success'] = true;
|
||||
$ret['link'] = $permalink;
|
||||
|
@ -789,6 +732,48 @@ class MainWP_Child_Posts {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
private function set_post_custom_data( &$new_post, $post_custom, $post_tags, &$edit_post_id, &$is_post_plus ){
|
||||
|
||||
global $current_user;
|
||||
|
||||
$this->create_wp_rocket( $post_custom );
|
||||
|
||||
// current user may be connected admin or alternative admin.
|
||||
$current_uid = $current_user->ID;
|
||||
|
||||
// Set up a new post (adding addition information).
|
||||
|
||||
$new_post['post_author'] = isset( $new_post['post_author'] ) && ! empty( $new_post['post_author'] )? $new_post['post_author'] : $current_uid;
|
||||
|
||||
if ( isset( $new_post['custom_post_author'] ) && ! empty( $new_post['custom_post_author'] ) ) {
|
||||
$_author = get_user_by( 'login', $new_post['custom_post_author'] );
|
||||
if ( ! empty( $_author ) ) {
|
||||
$new_post['post_author'] = $_author->ID;
|
||||
}
|
||||
unset( $new_post['custom_post_author'] );
|
||||
}
|
||||
|
||||
// post plus extension process.
|
||||
$is_post_plus = isset( $post_custom['_mainwp_post_plus'] ) ? true : false;
|
||||
|
||||
if ( $is_post_plus ) {
|
||||
if ( isset( $new_post['post_date_gmt'] ) && ! empty( $new_post['post_date_gmt'] ) && '0000-00-00 00:00:00' != $new_post['post_date_gmt'] ) {
|
||||
$post_date_timestamp = strtotime( $new_post['post_date_gmt'] ) + get_option( 'gmt_offset' ) * 60 * 60;
|
||||
$new_post['post_date'] = date( 'Y-m-d H:i:s', $post_date_timestamp ); // phpcs:ignore -- local time.
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $post_tags ) && '' !== $post_tags ) {
|
||||
$new_post['tags_input'] = $post_tags;
|
||||
}
|
||||
|
||||
if ( isset( $post_custom['_mainwp_edit_post_id'] ) && $post_custom['_mainwp_edit_post_id'] ) {
|
||||
$edit_post_id = current( $post_custom['_mainwp_edit_post_id'] );
|
||||
} elseif ( isset( $new_post['ID'] ) && $new_post['ID'] ) {
|
||||
$edit_post_id = $new_post['ID'];
|
||||
}
|
||||
}
|
||||
|
||||
private function update_post_data( $new_post_id, $post_custom, $post_category, $post_featured_image, $check_image_existed, $is_post_plus ){
|
||||
|
||||
$seo_ext_activated = false;
|
||||
|
|
|
@ -74,7 +74,7 @@ class MainWP_Child_Staging {
|
|||
return $this->get_overview();
|
||||
}
|
||||
|
||||
public function action() {
|
||||
public function action() { // phpcs:ignore -- ignore complex method notice.
|
||||
if ( ! $this->is_plugin_installed ) {
|
||||
mainwp_child_helper()->write( array( 'error' => __( 'Please install WP Staging plugin on child website', 'mainwp-child' ) ) );
|
||||
}
|
||||
|
|
|
@ -94,49 +94,12 @@ class MainWP_Child_Stats {
|
|||
add_filter( 'default_option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
||||
add_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
||||
|
||||
$premiumPlugins = array();
|
||||
$premiumThemes = array();
|
||||
|
||||
// First check for new premium updates.
|
||||
$this->check_premium_updates();
|
||||
|
||||
$informationPremiumUpdates = apply_filters( 'mwp_premium_update_notification', array() );
|
||||
$premiumPlugins = array();
|
||||
$premiumThemes = array();
|
||||
if ( is_array( $informationPremiumUpdates ) ) {
|
||||
$premiumUpdates = 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'] );
|
||||
|
||||
if ( ! isset( $information['premium_updates'] ) ) {
|
||||
$information['premium_updates'] = array();
|
||||
}
|
||||
|
||||
$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 );
|
||||
}
|
||||
|
||||
$this->check_premium_updates( $information, $premiumPlugins, $premiumThemes );
|
||||
|
||||
remove_filter( 'default_option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
||||
remove_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
||||
|
||||
|
@ -381,7 +344,7 @@ class MainWP_Child_Stats {
|
|||
}
|
||||
}
|
||||
|
||||
private function check_premium_updates() {
|
||||
private function check_premium_updates( &$information, &$premiumPlugins, &$premiumThemes ) {
|
||||
// First check for new premium updates.
|
||||
$update_check = apply_filters( 'mwp_premium_update_check', array() );
|
||||
if ( ! empty( $update_check ) ) {
|
||||
|
@ -393,8 +356,48 @@ class MainWP_Child_Stats {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$informationPremiumUpdates = apply_filters( 'mwp_premium_update_notification', array() );
|
||||
$premiumPlugins = array();
|
||||
$premiumThemes = array();
|
||||
if ( is_array( $informationPremiumUpdates ) ) {
|
||||
$premiumUpdates = 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'] );
|
||||
|
||||
if ( ! isset( $information['premium_updates'] ) ) {
|
||||
$information['premium_updates'] = array();
|
||||
}
|
||||
|
||||
$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 );
|
||||
}
|
||||
}
|
||||
|
||||
private function stats_plugin_update( $premiumPlugins ) {
|
||||
|
||||
$results = array();
|
||||
|
|
|
@ -58,7 +58,7 @@ class MainWP_Child_Timecapsule {
|
|||
}
|
||||
|
||||
|
||||
public function action() {
|
||||
public function action() { // phpcs:ignore -- ignore complex method notice.
|
||||
if ( ! $this->is_plugin_installed ) {
|
||||
mainwp_child_helper()->write( array( 'error' => 'Please install WP Time Capsule plugin on child website' ) );
|
||||
}
|
||||
|
|
|
@ -44,9 +44,34 @@ class MainWP_Child_Updates {
|
|||
if ( ! defined( 'DOING_CRON' ) ) {
|
||||
define( 'DOING_CRON', true );
|
||||
}
|
||||
|
||||
|
||||
MainWP_Helper::get_wp_filesystem();
|
||||
|
||||
$this->include_updates();
|
||||
|
||||
$information = array();
|
||||
$information['upgrades'] = array();
|
||||
$mwp_premium_updates_todo = array();
|
||||
$mwp_premium_updates_todo_slugs = array();
|
||||
$premiumUpgrader = false;
|
||||
|
||||
if ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ) {
|
||||
$this->upgrade_plugin( $information, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs, $premiumUpgrader );
|
||||
} elseif ( isset( $_POST['type'] ) && 'theme' === $_POST['type'] ) {
|
||||
$this->upgrade_theme( $information, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs, $premiumUpgrader );
|
||||
} else {
|
||||
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
if ( count( $mwp_premium_updates_todo ) > 0 ) {
|
||||
$this->update_premiums_todo( $information, $premiumUpgrader, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs );
|
||||
}
|
||||
|
||||
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
||||
mainwp_child_helper()->write( $information );
|
||||
}
|
||||
|
||||
private function include_updates(){
|
||||
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
||||
|
||||
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
||||
|
@ -61,86 +86,289 @@ class MainWP_Child_Updates {
|
|||
include_once ABSPATH . '/wp-admin/includes/file.php';
|
||||
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
||||
include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
|
||||
|
||||
$information = array();
|
||||
$information['upgrades'] = array();
|
||||
$mwp_premium_updates_todo = array();
|
||||
$mwp_premium_updates_todo_slugs = array();
|
||||
|
||||
if ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ) {
|
||||
$this->upgrade_plugin( $information, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs );
|
||||
} elseif ( isset( $_POST['type'] ) && 'theme' === $_POST['type'] ) {
|
||||
$this->upgrade_theme( $information, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs );
|
||||
} else {
|
||||
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
if ( count( $mwp_premium_updates_todo ) > 0 ) {
|
||||
// Upgrade via WP.
|
||||
// @see wp-admin/update.php.
|
||||
$result = $premiumUpgrader->bulk_upgrade( $mwp_premium_updates_todo_slugs );
|
||||
if ( ! empty( $result ) ) {
|
||||
foreach ( $result as $plugin => $info ) {
|
||||
if ( ! empty( $info ) ) {
|
||||
$information['upgrades'][ $plugin ] = true;
|
||||
|
||||
foreach ( $mwp_premium_updates_todo as $key => $update ) {
|
||||
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Upgrade via callback.
|
||||
foreach ( $mwp_premium_updates_todo as $update ) {
|
||||
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
||||
|
||||
if ( isset( $update['url'] ) ) {
|
||||
$installer = new \WP_Upgrader();
|
||||
$result = $installer->run(
|
||||
array(
|
||||
'package' => $update['url'],
|
||||
'destination' => ( 'plugin' === $update['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
|
||||
'clear_destination' => true,
|
||||
'clear_working' => true,
|
||||
'hook_extra' => array(),
|
||||
)
|
||||
);
|
||||
$information['upgrades'][ $slug ] = ( ! is_wp_error( $result ) && ! empty( $result ) );
|
||||
} elseif ( isset( $update['callback'] ) ) {
|
||||
if ( is_array( $update['callback'] ) && isset( $update['callback'][0] ) && isset( $update['callback'][1] ) ) {
|
||||
$update_result = call_user_func(
|
||||
array(
|
||||
$update['callback'][0],
|
||||
$update['callback'][1],
|
||||
)
|
||||
);
|
||||
$information['upgrades'][ $slug ] = $update_result && true;
|
||||
} elseif ( is_string( $update['callback'] ) ) {
|
||||
$update_result = call_user_func( $update['callback'] );
|
||||
$information['upgrades'][ $slug ] = $update_result && true;
|
||||
} else {
|
||||
$information['upgrades'][ $slug ] = false;
|
||||
}
|
||||
} else {
|
||||
$information['upgrades'][ $slug ] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
||||
mainwp_child_helper()->write( $information );
|
||||
}
|
||||
|
||||
private function upgrade_plugin( &$information, &$mwp_premium_updates_todo, &$mwp_premium_updates_todo_slugs ) {
|
||||
private function upgrade_plugin( &$information, &$mwp_premium_updates_todo, &$mwp_premium_updates_todo_slugs, &$premiumUpgrader ) {
|
||||
|
||||
include_once ABSPATH . '/wp-admin/includes/update.php';
|
||||
include_once ABSPATH . '/wp-admin/includes/update.php';
|
||||
if ( null !== $this->filterFunction ) {
|
||||
add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
||||
}
|
||||
|
||||
$plugins = explode( ',', urldecode( $_POST['list'] ) );
|
||||
$plugins = explode( ',', urldecode( $_POST['list'] ) );
|
||||
|
||||
$this->to_support_some_premiums_updates( $plugins );
|
||||
|
||||
global $wp_current_filter;
|
||||
$wp_current_filter[] = 'load-plugins.php'; // phpcs:ignore -- to custom plugin installation.
|
||||
wp_update_plugins();
|
||||
|
||||
// trick to prevent some premium plugins re-create update info.
|
||||
remove_all_filters( 'pre_set_site_transient_update_plugins' );
|
||||
|
||||
// support cached premium plugins update info, hooking in the bulk_upgrade().
|
||||
add_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ) );
|
||||
|
||||
$information['plugin_updates'] = get_plugin_updates();
|
||||
|
||||
$plugins = explode( ',', urldecode( $_POST['list'] ) );
|
||||
$premiumPlugins = array();
|
||||
$premiumUpdates = get_option( 'mainwp_premium_updates' );
|
||||
if ( is_array( $premiumUpdates ) ) {
|
||||
$newPlugins = array();
|
||||
foreach ( $plugins as $plugin ) {
|
||||
if ( in_array( $plugin, $premiumUpdates ) ) {
|
||||
$premiumPlugins[] = $plugin;
|
||||
} else {
|
||||
$newPlugins[] = $plugin;
|
||||
}
|
||||
}
|
||||
$plugins = $newPlugins;
|
||||
}
|
||||
|
||||
if ( count( $plugins ) > 0 ) {
|
||||
$this->to_update_plugins( $information, $plugins );
|
||||
}
|
||||
|
||||
remove_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ), 10 );
|
||||
delete_site_transient( 'mainwp_update_plugins_cached' ); // fix cached update info.
|
||||
|
||||
if ( count( $premiumPlugins ) > 0 ) {
|
||||
$mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() );
|
||||
if ( is_array( $mwp_premium_updates ) && is_array( $premiumPlugins ) ) {
|
||||
foreach ( $premiumPlugins as $premiumPlugin ) {
|
||||
foreach ( $mwp_premium_updates as $key => $update ) {
|
||||
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
||||
if ( 0 === strcmp( $slug, $premiumPlugin ) ) {
|
||||
$mwp_premium_updates_todo[ $key ] = $update;
|
||||
$mwp_premium_updates_todo_slugs[] = $premiumPlugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unset( $mwp_premium_updates );
|
||||
// to fix update of Yithemes premiums plugins that hooked to upgrader_pre_download.
|
||||
$url = 'update.php?action=update-selected&plugins=' . rawurlencode( implode( ',', $plugins ) );
|
||||
$nonce = 'bulk-update-plugins';
|
||||
$premiumUpgrader = new \Plugin_Upgrader( new \Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
||||
}
|
||||
|
||||
if ( count( $plugins ) <= 0 && count( $premiumPlugins ) <= 0 ) {
|
||||
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
if ( null !== $this->filterFunction ) {
|
||||
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
||||
}
|
||||
}
|
||||
|
||||
private function to_update_plugins( &$information, $plugins ){
|
||||
$failed = true;
|
||||
// to fix update of Yithemes premiums plugins that hooked to upgrader_pre_download.
|
||||
$url = 'update.php?action=update-selected&plugins=' . rawurlencode( implode( ',', $plugins ) );
|
||||
$nonce = 'bulk-update-plugins';
|
||||
|
||||
$upgrader = new \Plugin_Upgrader( new \Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
||||
$result = $upgrader->bulk_upgrade( $plugins );
|
||||
|
||||
if ( ! empty( $result ) ) {
|
||||
foreach ( $result as $plugin => $info ) {
|
||||
if ( empty( $info ) ) {
|
||||
|
||||
$information['upgrades'][ $plugin ] = false;
|
||||
// try to fix if that is premiums update.
|
||||
$api = apply_filters( 'plugins_api', false, 'plugin_information', array( 'slug' => $plugin ) );
|
||||
|
||||
if ( ! is_wp_error( $api ) && ! empty( $api ) ) {
|
||||
if ( isset( $api->download_link ) ) {
|
||||
$res = $upgrader->install( $api->download_link );
|
||||
if ( ! is_wp_error( $res ) && ! ( is_null( $res ) ) ) {
|
||||
$information['upgrades'][ $plugin ] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$information['upgrades'][ $plugin ] = true;
|
||||
}
|
||||
}
|
||||
$failed = false;
|
||||
}
|
||||
|
||||
if ( $failed ) {
|
||||
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
||||
}
|
||||
}
|
||||
|
||||
private function upgrade_theme( &$information, &$mwp_premium_updates_todo, &$mwp_premium_updates_todo_slugs, &$premiumUpgrader ) {
|
||||
|
||||
$last_update = get_site_transient( 'update_themes' );
|
||||
|
||||
include_once ABSPATH . '/wp-admin/includes/update.php';
|
||||
if ( null !== $this->filterFunction ) {
|
||||
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
||||
}
|
||||
|
||||
wp_update_themes();
|
||||
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
||||
|
||||
// to support cached premium themes update info, hooking in the bulk_upgrade().
|
||||
add_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ) );
|
||||
|
||||
$information['theme_updates'] = $this->upgrade_get_theme_updates();
|
||||
$themes = explode( ',', $_POST['list'] );
|
||||
$premiumThemes = array();
|
||||
$premiumUpdates = get_option( 'mainwp_premium_updates' );
|
||||
if ( is_array( $premiumUpdates ) ) {
|
||||
$newThemes = array();
|
||||
foreach ( $themes as $theme ) {
|
||||
if ( in_array( $theme, $premiumUpdates ) ) {
|
||||
$premiumThemes[] = $theme;
|
||||
} else {
|
||||
$newThemes[] = $theme;
|
||||
}
|
||||
}
|
||||
$themes = $newThemes;
|
||||
}
|
||||
|
||||
if ( count( $themes ) > 0 ) {
|
||||
$this->to_upgrade_themes( $information, $themes, $last_update );
|
||||
}
|
||||
|
||||
remove_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ), 10 );
|
||||
delete_site_transient( 'mainwp_update_themes_cached' ); // fix cached update info.
|
||||
|
||||
if ( count( $premiumThemes ) > 0 ) {
|
||||
$mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() );
|
||||
$mwp_premium_updates_todo = array();
|
||||
$mwp_premium_updates_todo_slugs = array();
|
||||
if ( is_array( $premiumThemes ) && is_array( $mwp_premium_updates ) ) {
|
||||
foreach ( $premiumThemes as $premiumTheme ) {
|
||||
foreach ( $mwp_premium_updates as $key => $update ) {
|
||||
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
||||
if ( 0 === strcmp( $slug, $premiumTheme ) ) {
|
||||
$mwp_premium_updates_todo[ $key ] = $update;
|
||||
$mwp_premium_updates_todo_slugs[] = $slug;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unset( $mwp_premium_updates );
|
||||
$premiumUpgrader = new \Theme_Upgrader( new \Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
||||
}
|
||||
if ( count( $themes ) <= 0 && count( $premiumThemes ) <= 0 ) {
|
||||
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
if ( null !== $this->filterFunction ) {
|
||||
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
||||
}
|
||||
}
|
||||
|
||||
private function to_upgrade_themes( &$information, $themes, $last_update ){
|
||||
$addFilterToFixUpdate_optimizePressTheme = false;
|
||||
if ( in_array( 'optimizePressTheme', $themes ) ) {
|
||||
$addFilterToFixUpdate_optimizePressTheme = true;
|
||||
add_filter( 'site_transient_update_themes', array( $this, 'hook_fix_optimize_press_theme_update' ), 99 );
|
||||
}
|
||||
|
||||
if ( null !== $this->filterFunction ) {
|
||||
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
||||
}
|
||||
|
||||
$last_update2 = get_site_transient( 'update_themes' );
|
||||
set_site_transient( 'update_themes', $last_update );
|
||||
|
||||
$failed = true;
|
||||
$upgrader = new \Theme_Upgrader( new \Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
||||
$result = $upgrader->bulk_upgrade( $themes );
|
||||
if ( ! empty( $result ) ) {
|
||||
foreach ( $result as $theme => $info ) {
|
||||
if ( empty( $info ) ) {
|
||||
$information['upgrades'][ $theme ] = false;
|
||||
} else {
|
||||
$information['upgrades'][ $theme ] = true;
|
||||
}
|
||||
}
|
||||
$failed = false;
|
||||
}
|
||||
|
||||
if ( $failed ) {
|
||||
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
if ( null !== $this->filterFunction ) {
|
||||
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
||||
}
|
||||
|
||||
set_site_transient( 'update_themes', $last_update2 );
|
||||
|
||||
if ( $addFilterToFixUpdate_optimizePressTheme ) {
|
||||
remove_filter(
|
||||
'site_transient_update_themes',
|
||||
array(
|
||||
$this,
|
||||
'hook_fix_optimize_press_theme_update',
|
||||
),
|
||||
99
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function update_premiums_todo( &$information, $premiumUpgrader, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs ){
|
||||
// Upgrade via WP.
|
||||
// @see wp-admin/update.php.
|
||||
$result = $premiumUpgrader->bulk_upgrade( $mwp_premium_updates_todo_slugs );
|
||||
if ( ! empty( $result ) ) {
|
||||
foreach ( $result as $plugin => $info ) {
|
||||
if ( ! empty( $info ) ) {
|
||||
$information['upgrades'][ $plugin ] = true;
|
||||
|
||||
foreach ( $mwp_premium_updates_todo as $key => $update ) {
|
||||
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Upgrade via callback.
|
||||
foreach ( $mwp_premium_updates_todo as $update ) {
|
||||
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
||||
|
||||
if ( isset( $update['url'] ) ) {
|
||||
$installer = new \WP_Upgrader();
|
||||
$result = $installer->run(
|
||||
array(
|
||||
'package' => $update['url'],
|
||||
'destination' => ( 'plugin' === $update['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
|
||||
'clear_destination' => true,
|
||||
'clear_working' => true,
|
||||
'hook_extra' => array(),
|
||||
)
|
||||
);
|
||||
$information['upgrades'][ $slug ] = ( ! is_wp_error( $result ) && ! empty( $result ) );
|
||||
} elseif ( isset( $update['callback'] ) ) {
|
||||
if ( is_array( $update['callback'] ) && isset( $update['callback'][0] ) && isset( $update['callback'][1] ) ) {
|
||||
$update_result = call_user_func(
|
||||
array(
|
||||
$update['callback'][0],
|
||||
$update['callback'][1],
|
||||
)
|
||||
);
|
||||
$information['upgrades'][ $slug ] = $update_result && true;
|
||||
} elseif ( is_string( $update['callback'] ) ) {
|
||||
$update_result = call_user_func( $update['callback'] );
|
||||
$information['upgrades'][ $slug ] = $update_result && true;
|
||||
} else {
|
||||
$information['upgrades'][ $slug ] = false;
|
||||
}
|
||||
} else {
|
||||
$information['upgrades'][ $slug ] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function to_support_some_premiums_updates( $plugins ){
|
||||
|
||||
if ( in_array( 'backupbuddy/backupbuddy.php', $plugins ) ) {
|
||||
if ( isset( $GLOBALS['ithemes_updater_path'] ) ) {
|
||||
if ( ! class_exists( 'Ithemes_Updater_Settings' ) ) {
|
||||
|
@ -160,212 +388,9 @@ class MainWP_Child_Updates {
|
|||
include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php';
|
||||
}
|
||||
}
|
||||
|
||||
global $wp_current_filter;
|
||||
$wp_current_filter[] = 'load-plugins.php'; // phpcs:ignore -- to custom plugin installation.
|
||||
wp_update_plugins();
|
||||
|
||||
// trick to prevent some premium plugins re-create update info.
|
||||
remove_all_filters( 'pre_set_site_transient_update_plugins' );
|
||||
|
||||
// support cached premium plugins update info, hooking in the bulk_upgrade().
|
||||
add_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ) );
|
||||
|
||||
$information['plugin_updates'] = get_plugin_updates();
|
||||
|
||||
$plugins = explode( ',', urldecode( $_POST['list'] ) );
|
||||
$premiumPlugins = array();
|
||||
$premiumUpdates = get_option( 'mainwp_premium_updates' );
|
||||
if ( is_array( $premiumUpdates ) ) {
|
||||
$newPlugins = array();
|
||||
foreach ( $plugins as $plugin ) {
|
||||
if ( in_array( $plugin, $premiumUpdates ) ) {
|
||||
$premiumPlugins[] = $plugin;
|
||||
} else {
|
||||
$newPlugins[] = $plugin;
|
||||
}
|
||||
}
|
||||
$plugins = $newPlugins;
|
||||
}
|
||||
|
||||
if ( count( $plugins ) > 0 ) {
|
||||
$failed = true;
|
||||
// to fix update of Yithemes premiums plugins that hooked to upgrader_pre_download.
|
||||
$url = 'update.php?action=update-selected&plugins=' . rawurlencode( implode( ',', $plugins ) );
|
||||
$nonce = 'bulk-update-plugins';
|
||||
|
||||
$upgrader = new \Plugin_Upgrader( new \Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
||||
$result = $upgrader->bulk_upgrade( $plugins );
|
||||
|
||||
if ( ! empty( $result ) ) {
|
||||
foreach ( $result as $plugin => $info ) {
|
||||
if ( empty( $info ) ) {
|
||||
|
||||
$information['upgrades'][ $plugin ] = false;
|
||||
// try to fix if that is premiums update.
|
||||
$api = apply_filters( 'plugins_api', false, 'plugin_information', array( 'slug' => $plugin ) );
|
||||
|
||||
if ( ! is_wp_error( $api ) && ! empty( $api ) ) {
|
||||
if ( isset( $api->download_link ) ) {
|
||||
$res = $upgrader->install( $api->download_link );
|
||||
if ( ! is_wp_error( $res ) && ! ( is_null( $res ) ) ) {
|
||||
$information['upgrades'][ $plugin ] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$information['upgrades'][ $plugin ] = true;
|
||||
}
|
||||
}
|
||||
$failed = false;
|
||||
}
|
||||
|
||||
if ( $failed ) {
|
||||
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
||||
}
|
||||
}
|
||||
|
||||
remove_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ), 10 );
|
||||
delete_site_transient( 'mainwp_update_plugins_cached' ); // fix cached update info.
|
||||
|
||||
if ( count( $premiumPlugins ) > 0 ) {
|
||||
$mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() );
|
||||
if ( is_array( $mwp_premium_updates ) && is_array( $premiumPlugins ) ) {
|
||||
foreach ( $premiumPlugins as $premiumPlugin ) {
|
||||
foreach ( $mwp_premium_updates as $key => $update ) {
|
||||
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
||||
if ( 0 === strcmp( $slug, $premiumPlugin ) ) {
|
||||
$mwp_premium_updates_todo[ $key ] = $update;
|
||||
$mwp_premium_updates_todo_slugs[] = $premiumPlugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unset( $mwp_premium_updates );
|
||||
$premiumUpgrader = new \Plugin_Upgrader( new \Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
||||
}
|
||||
|
||||
if ( count( $plugins ) <= 0 && count( $premiumPlugins ) <= 0 ) {
|
||||
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
if ( null !== $this->filterFunction ) {
|
||||
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function upgrade_theme( &$information, &$mwp_premium_updates_todo, &$mwp_premium_updates_todo_slugs ) {
|
||||
|
||||
$last_update = get_site_transient( 'update_themes' );
|
||||
|
||||
include_once ABSPATH . '/wp-admin/includes/update.php';
|
||||
if ( null !== $this->filterFunction ) {
|
||||
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
||||
}
|
||||
|
||||
wp_update_themes();
|
||||
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
||||
|
||||
// to support cached premium themes update info, hooking in the bulk_upgrade().
|
||||
add_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ) );
|
||||
|
||||
$information['theme_updates'] = $this->upgrade_get_theme_updates();
|
||||
$themes = explode( ',', $_POST['list'] );
|
||||
$premiumThemes = array();
|
||||
$premiumUpdates = get_option( 'mainwp_premium_updates' );
|
||||
if ( is_array( $premiumUpdates ) ) {
|
||||
$newThemes = array();
|
||||
foreach ( $themes as $theme ) {
|
||||
if ( in_array( $theme, $premiumUpdates ) ) {
|
||||
$premiumThemes[] = $theme;
|
||||
} else {
|
||||
$newThemes[] = $theme;
|
||||
}
|
||||
}
|
||||
$themes = $newThemes;
|
||||
}
|
||||
|
||||
if ( count( $themes ) > 0 ) {
|
||||
$addFilterToFixUpdate_optimizePressTheme = false;
|
||||
if ( in_array( 'optimizePressTheme', $themes ) ) {
|
||||
$addFilterToFixUpdate_optimizePressTheme = true;
|
||||
add_filter( 'site_transient_update_themes', array( $this, 'hook_fix_optimize_press_theme_update' ), 99 );
|
||||
}
|
||||
|
||||
if ( null !== $this->filterFunction ) {
|
||||
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
||||
}
|
||||
|
||||
$last_update2 = get_site_transient( 'update_themes' );
|
||||
set_site_transient( 'update_themes', $last_update );
|
||||
|
||||
$failed = true;
|
||||
$upgrader = new \Theme_Upgrader( new \Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
||||
$result = $upgrader->bulk_upgrade( $themes );
|
||||
if ( ! empty( $result ) ) {
|
||||
foreach ( $result as $theme => $info ) {
|
||||
if ( empty( $info ) ) {
|
||||
$information['upgrades'][ $theme ] = false;
|
||||
} else {
|
||||
$information['upgrades'][ $theme ] = true;
|
||||
}
|
||||
}
|
||||
$failed = false;
|
||||
}
|
||||
|
||||
if ( $failed ) {
|
||||
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
if ( null !== $this->filterFunction ) {
|
||||
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
||||
}
|
||||
|
||||
set_site_transient( 'update_themes', $last_update2 );
|
||||
|
||||
if ( $addFilterToFixUpdate_optimizePressTheme ) {
|
||||
remove_filter(
|
||||
'site_transient_update_themes',
|
||||
array(
|
||||
$this,
|
||||
'hook_fix_optimize_press_theme_update',
|
||||
),
|
||||
99
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
remove_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ), 10 );
|
||||
delete_site_transient( 'mainwp_update_themes_cached' ); // fix cached update info.
|
||||
|
||||
if ( count( $premiumThemes ) > 0 ) {
|
||||
$mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() );
|
||||
$mwp_premium_updates_todo = array();
|
||||
$mwp_premium_updates_todo_slugs = array();
|
||||
if ( is_array( $premiumThemes ) && is_array( $mwp_premium_updates ) ) {
|
||||
foreach ( $premiumThemes as $premiumTheme ) {
|
||||
foreach ( $mwp_premium_updates as $key => $update ) {
|
||||
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
||||
if ( 0 === strcmp( $slug, $premiumTheme ) ) {
|
||||
$mwp_premium_updates_todo[ $key ] = $update;
|
||||
$mwp_premium_updates_todo_slugs[] = $slug;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unset( $mwp_premium_updates );
|
||||
|
||||
$premiumUpgrader = new \Theme_Upgrader( new \Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
||||
}
|
||||
if ( count( $themes ) <= 0 && count( $premiumThemes ) <= 0 ) {
|
||||
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
if ( null !== $this->filterFunction ) {
|
||||
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function upgrade_get_theme_updates() {
|
||||
$themeUpdates = get_theme_updates();
|
||||
$newThemeUpdates = array();
|
||||
|
|
|
@ -458,7 +458,7 @@ class MainWP_Client_Report {
|
|||
return $token_values;
|
||||
}
|
||||
|
||||
private function get_other_tokens_count( $records, $connector, $context, $action, &$skip_records, &$backups_created_time_to_fix ){
|
||||
private function get_other_tokens_count( $records, $connector, $context, $action, &$skip_records, &$backups_created_time_to_fix ){ // phpcs:ignore -- ignore complex method notice.
|
||||
$count = 0;
|
||||
|
||||
foreach ( $records as $record ) {
|
||||
|
@ -585,7 +585,7 @@ class MainWP_Client_Report {
|
|||
return $this->get_section_loop_records( $records, $tokens, $connector, $context, $action, $skip_records );
|
||||
}
|
||||
|
||||
public function get_section_loop_records( $records, $tokens, $connector, $context, $action, $skip_records ) {
|
||||
public function get_section_loop_records( $records, $tokens, $connector, $context, $action, $skip_records ) { // phpcs:ignore -- ignore complex method notice.
|
||||
|
||||
$loops = array();
|
||||
$loop_count = 0;
|
||||
|
@ -687,7 +687,7 @@ class MainWP_Client_Report {
|
|||
$data = 'roles';
|
||||
}
|
||||
|
||||
$tok_value = $this->get_section_loop_token_value( $record, $data, $context, $token );
|
||||
$tok_value = $this->get_section_token_value( $record, $data, $context, $token );
|
||||
|
||||
$token_values[ $token ] = $tok_value;
|
||||
|
||||
|
@ -699,7 +699,7 @@ class MainWP_Client_Report {
|
|||
return $token_values;
|
||||
}
|
||||
|
||||
public function get_section_loop_token_value( $record, $data, $context, $token ) {
|
||||
public function get_section_token_value( $record, $data, $context, $token ) { // phpcs:ignore -- ignore complex method notice.
|
||||
$tok_value = '';
|
||||
switch ( $data ) {
|
||||
case 'ID':
|
||||
|
|
|
@ -216,64 +216,24 @@ class MainWP_Custom_Post_Type {
|
|||
|
||||
// Insert post meta.
|
||||
if ( ! empty( $data['postmeta'] ) && is_array( $data['postmeta'] ) ) {
|
||||
foreach ( $data['postmeta'] as $key ) {
|
||||
if ( isset( $key['meta_key'] ) && isset( $key['meta_value'] ) ) {
|
||||
if ( $is_woocomerce ) {
|
||||
if ( '_sku' == $key['meta_key'] ) {
|
||||
if ( ! wc_product_has_unique_sku( $post_id, $key['meta_value'] ) ) {
|
||||
return array( 'error' => __( 'Product SKU must be unique', $this->plugin_translate ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( '_product_image_gallery' == $key['meta_key'] ) {
|
||||
$product_image_gallery = array();
|
||||
if ( isset( $data['extras']['woocommerce']['product_images'] ) ) {
|
||||
foreach ( $data['extras']['woocommerce']['product_images'] as $product_image ) {
|
||||
try {
|
||||
$upload_featured_image = MainWP_Utility::upload_image( $product_image, array(), $check_image_existed );
|
||||
|
||||
if ( null !== $upload_featured_image ) {
|
||||
$product_image_gallery[] = $upload_featured_image['id'];
|
||||
} else {
|
||||
return array( 'error' => __( 'Cannot add product image', $this->plugin_translate ) );
|
||||
}
|
||||
} catch ( \Exception $e ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$key['meta_value'] = implode( $product_image_gallery, ',' );
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( '_thumbnail_id' == $key['meta_key'] ) {
|
||||
if ( isset( $data['extras']['featured_image'] ) ) {
|
||||
try {
|
||||
$upload_featured_image = MainWP_Utility::upload_image( $data['extras']['featured_image'], array(), $check_image_existed );
|
||||
|
||||
if ( null !== $upload_featured_image ) {
|
||||
$key['meta_value'] = $upload_featured_image['id'];
|
||||
} else {
|
||||
return array( 'error' => __( 'Cannot add featured image', $this->plugin_translate ) );
|
||||
}
|
||||
} catch ( \Exception $e ) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$meta_value = maybe_unserialize( $key['meta_value'] );
|
||||
if ( add_post_meta( $post_id, $key['meta_key'], $meta_value ) === false ) {
|
||||
return array( 'error' => __( 'Error when adding post meta', $this->plugin_translate ) . ' `' . esc_html( $key['meta_key'] ) . '`' );
|
||||
}
|
||||
}
|
||||
}
|
||||
$ret = $this->insert_postmeta( $post_id, $data, $check_image_existed, $is_woocomerce );
|
||||
if ( true !== $ret )
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$ret = $this->insert_custom_data( $post_id, $data );
|
||||
|
||||
if ( true !== $ret )
|
||||
return $ret;
|
||||
|
||||
return array(
|
||||
'success' => 1,
|
||||
'post_id' => $post_id,
|
||||
);
|
||||
}
|
||||
|
||||
private function insert_custom_data( $post_id, $data ){
|
||||
|
||||
// MainWP Categories.
|
||||
if ( ! empty( $data['categories'] ) && is_array( $data['categories'] ) ) {
|
||||
// Contains wp_create_categories.
|
||||
|
@ -331,10 +291,66 @@ class MainWP_Custom_Post_Type {
|
|||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function insert_postmeta( $post_id, $data, $check_image_existed, $is_woocomerce ){
|
||||
foreach ( $data['postmeta'] as $key ) {
|
||||
if ( isset( $key['meta_key'] ) && isset( $key['meta_value'] ) ) {
|
||||
if ( $is_woocomerce ) {
|
||||
if ( '_sku' == $key['meta_key'] ) {
|
||||
if ( ! wc_product_has_unique_sku( $post_id, $key['meta_value'] ) ) {
|
||||
return array( 'error' => __( 'Product SKU must be unique', $this->plugin_translate ) );
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => 1,
|
||||
'post_id' => $post_id,
|
||||
);
|
||||
if ( '_product_image_gallery' == $key['meta_key'] ) {
|
||||
$product_image_gallery = array();
|
||||
if ( isset( $data['extras']['woocommerce']['product_images'] ) ) {
|
||||
foreach ( $data['extras']['woocommerce']['product_images'] as $product_image ) {
|
||||
try {
|
||||
$upload_featured_image = MainWP_Utility::upload_image( $product_image, array(), $check_image_existed );
|
||||
|
||||
if ( null !== $upload_featured_image ) {
|
||||
$product_image_gallery[] = $upload_featured_image['id'];
|
||||
} else {
|
||||
return array( 'error' => __( 'Cannot add product image', $this->plugin_translate ) );
|
||||
}
|
||||
} catch ( \Exception $e ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$key['meta_value'] = implode( $product_image_gallery, ',' );
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( '_thumbnail_id' == $key['meta_key'] ) {
|
||||
if ( isset( $data['extras']['featured_image'] ) ) {
|
||||
try {
|
||||
$upload_featured_image = MainWP_Utility::upload_image( $data['extras']['featured_image'], array(), $check_image_existed );
|
||||
|
||||
if ( null !== $upload_featured_image ) {
|
||||
$key['meta_value'] = $upload_featured_image['id'];
|
||||
} else {
|
||||
return array( 'error' => __( 'Cannot add featured image', $this->plugin_translate ) );
|
||||
}
|
||||
} catch ( \Exception $e ) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$meta_value = maybe_unserialize( $key['meta_value'] );
|
||||
if ( add_post_meta( $post_id, $key['meta_key'], $meta_value ) === false ) {
|
||||
return array( 'error' => __( 'Error when adding post meta', $this->plugin_translate ) . ' `' . esc_html( $key['meta_key'] ) . '`' );
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -469,7 +469,7 @@ class Tar_Archiver {
|
|||
protected $gcCnt = 0;
|
||||
protected $cnt = 0;
|
||||
|
||||
private function add_file( $path, $entryName ) {
|
||||
private function add_file( $path, $entryName ) { // phpcs:ignore -- ignore complex method notice.
|
||||
if ( ( '.' == basename( $path ) ) || ( '..' == basename( $path ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1140,7 +1140,7 @@ class Tar_Archiver {
|
|||
return false;
|
||||
}
|
||||
|
||||
public function extract_to( $to ) {
|
||||
public function extract_to( $to ) { // phpcs:ignore -- ignore complex method notice.
|
||||
/** @var $wp_filesystem WP_Filesystem_Base */
|
||||
global $wp_filesystem;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue