Merge pull request #149 from mainwp/bogdan01-cf-autofix

Apply fixes from CodeFactor
This commit is contained in:
Thang Hoang Van 2020-05-19 20:30:21 +07:00 committed by GitHub
commit 137e2d1f18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 107 additions and 105 deletions

View file

@ -260,33 +260,33 @@ class MainWP_Backup {
return false;
}
private function get_core_files(){
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',
);
'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(){
public function add_config() {
global $wpdb;
$plugins = array();
$dir = WP_CONTENT_DIR . '/plugins/';

View file

@ -576,8 +576,8 @@ class MainWP_Child_Back_Up_WordPress {
$exclude_string = $schedule->backup->exclude_string( 'regex' );
}
if ( $files ) {
$this->render_table_files( $files, $schedule, $directory, $root_dir, $new_version, $site_size, $is_size_calculated );
}
$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>
@ -629,14 +629,15 @@ class MainWP_Child_Back_Up_WordPress {
</table>
<?php
}
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
@ -644,11 +645,11 @@ class MainWP_Child_Back_Up_WordPress {
?>
</tbody>
</table>
<?php
<?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>
@ -719,9 +720,9 @@ class MainWP_Child_Back_Up_WordPress {
</tr>
<?php
}
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;
$is_unreadable = false;

View file

@ -50,13 +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'];
@ -69,7 +69,7 @@ class MainWP_Child_Posts {
}
}
$tokens = array_flip( $tokens );
if ( 0 !== $pCount ) {
$args['numberposts'] = $pCount;
}
@ -82,14 +82,14 @@ 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
@ -109,7 +109,7 @@ class MainWP_Child_Posts {
}
foreach ( $posts as $post ) {
$outPost = $this->get_out_post( $post, $extra, $tokens );
if ( $wp_seo_enabled ) {
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' ),
@ -121,8 +121,8 @@ class MainWP_Child_Posts {
}
}
}
private function get_out_post( $post, $extra, $tokens ){
private function get_out_post( $post, $extra, $tokens ) {
$outPost = array();
$outPost['id'] = $post->ID;
$outPost['post_type'] = $post->post_type;
@ -173,7 +173,7 @@ class MainWP_Child_Posts {
$outPost['[post.website.name]'] = get_bloginfo( 'name' );
}
}
return $outPost;
return $outPost;
}
public function get_all_posts() {
@ -671,10 +671,10 @@ class MainWP_Child_Posts {
* @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 );
do_action( 'mainwp_before_post_update', $new_post, $post_custom, $post_category, $post_tags );
$edit_post_id = 0;
$is_post_plus = false;
$this->set_post_custom_data( $new_post, $post_custom, $post_tags, $edit_post_id, $is_post_plus );
$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 );
@ -684,7 +684,7 @@ class MainWP_Child_Posts {
return array( 'error' => $error );
}
}
$check_image_existed = $edit_post_id ? true : false; // 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 ) {
@ -702,8 +702,8 @@ 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;
}
$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 ) ) {
@ -725,34 +725,34 @@ class MainWP_Child_Posts {
if ( $edit_post_id ) {
update_post_meta( $edit_post_id, '_edit_lock', '' );
}
$permalink = get_permalink( $new_post_id );
$permalink = get_permalink( $new_post_id );
$ret['success'] = true;
$ret['link'] = $permalink;
$ret['added_id'] = $new_post_id;
return $ret;
}
private function set_post_custom_data( &$new_post, $post_custom, $post_tags, &$edit_post_id, &$is_post_plus ){
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;
$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;
@ -762,20 +762,20 @@ class MainWP_Child_Posts {
$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 ){
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;
if ( class_exists( 'WPSEO_Meta' ) && class_exists( 'WPSEO_Admin' ) ) {
$seo_ext_activated = true;

View file

@ -95,11 +95,11 @@ class MainWP_Child_Stats {
add_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
$premiumPlugins = array();
$premiumThemes = array();
$premiumThemes = array();
// First check for new premium updates.
$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' ) );
@ -356,7 +356,7 @@ class MainWP_Child_Stats {
}
}
}
$informationPremiumUpdates = apply_filters( 'mwp_premium_update_notification', array() );
$premiumPlugins = array();
$premiumThemes = array();
@ -397,7 +397,7 @@ class MainWP_Child_Stats {
MainWP_Helper::update_option( 'mainwp_premium_updates', $premiumUpdates );
}
}
private function stats_plugin_update( $premiumPlugins ) {
$results = array();

View file

@ -44,17 +44,17 @@ 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;
$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'] ) {
@ -62,16 +62,16 @@ class MainWP_Child_Updates {
} 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 );
$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(){
private function include_updates() {
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
@ -98,7 +98,7 @@ class MainWP_Child_Updates {
$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();
@ -127,7 +127,7 @@ class MainWP_Child_Updates {
}
if ( count( $plugins ) > 0 ) {
$this->to_update_plugins( $information, $plugins );
$this->to_update_plugins( $information, $plugins );
}
remove_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ), 10 );
@ -148,8 +148,8 @@ class MainWP_Child_Updates {
}
unset( $mwp_premium_updates );
// to fix update of Yithemes premiums plugins that hooked to upgrader_pre_download.
$url = 'update.php?action=update-selected&amp;plugins=' . rawurlencode( implode( ',', $plugins ) );
$nonce = 'bulk-update-plugins';
$url = 'update.php?action=update-selected&amp;plugins=' . rawurlencode( implode( ',', $plugins ) );
$nonce = 'bulk-update-plugins';
$premiumUpgrader = new \Plugin_Upgrader( new \Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
}
@ -161,8 +161,8 @@ class MainWP_Child_Updates {
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
}
}
private function to_update_plugins( &$information, $plugins ){
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&amp;plugins=' . rawurlencode( implode( ',', $plugins ) );
@ -252,7 +252,7 @@ class MainWP_Child_Updates {
}
}
}
unset( $mwp_premium_updates );
unset( $mwp_premium_updates );
$premiumUpgrader = new \Theme_Upgrader( new \Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
}
if ( count( $themes ) <= 0 && count( $premiumThemes ) <= 0 ) {
@ -264,7 +264,7 @@ class MainWP_Child_Updates {
}
}
private function to_upgrade_themes( &$information, $themes, $last_update ){
private function to_upgrade_themes( &$information, $themes, $last_update ) {
$addFilterToFixUpdate_optimizePressTheme = false;
if ( in_array( 'optimizePressTheme', $themes ) ) {
$addFilterToFixUpdate_optimizePressTheme = true;
@ -313,8 +313,8 @@ class MainWP_Child_Updates {
);
}
}
private function update_premiums_todo( &$information, $premiumUpgrader, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs ){
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 );
@ -366,9 +366,9 @@ class MainWP_Child_Updates {
}
}
}
private function to_support_some_premiums_updates( $plugins ){
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' ) ) {
@ -388,9 +388,8 @@ class MainWP_Child_Updates {
include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php';
}
}
}
public function upgrade_get_theme_updates() {
$themeUpdates = get_theme_updates();
$newThemeUpdates = array();

View file

@ -700,7 +700,7 @@ class MainWP_Client_Report {
}
return $token_values;
}
public function get_section_token_value( $record, $data, $context, $token ) { // phpcs:ignore -- ignore complex method notice.
$tok_value = '';
switch ( $data ) {

View file

@ -217,23 +217,25 @@ class MainWP_Custom_Post_Type {
// Insert post meta.
if ( ! empty( $data['postmeta'] ) && is_array( $data['postmeta'] ) ) {
$ret = $this->insert_postmeta( $post_id, $data, $check_image_existed, $is_woocomerce );
if ( true !== $ret )
return $ret;
if ( true !== $ret ) {
return $ret;
}
}
$ret = $this->insert_custom_data( $post_id, $data );
if ( true !== $ret )
if ( true !== $ret ) {
return $ret;
}
return array(
'success' => 1,
'post_id' => $post_id,
);
}
private function insert_custom_data( $post_id, $data ){
private function insert_custom_data( $post_id, $data ) {
// MainWP Categories.
if ( ! empty( $data['categories'] ) && is_array( $data['categories'] ) ) {
// Contains wp_create_categories.
@ -293,8 +295,8 @@ class MainWP_Custom_Post_Type {
}
return true;
}
private function insert_postmeta( $post_id, $data, $check_image_existed, $is_woocomerce ){
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 ) {