[CodeFactor] Apply fixes

[ci skip] [skip ci]
This commit is contained in:
codefactor-io 2020-05-22 04:40:40 +00:00
parent e758ee489e
commit 635f617694
5 changed files with 330 additions and 324 deletions

View file

@ -8,53 +8,54 @@ namespace MainWP\Child;
/**
* Class MainWP_Child_Comments
*
* @package MainWP\Child
*/
class MainWP_Child_Comments {
/**
* @static
* @var null Holds the Public static instance of MainWP_Child_Comments.
*/
protected static $instance = null;
/**
* @static
* @var null Holds the Public static instance of MainWP_Child_Comments.
*/
protected static $instance = null;
/**
* @var string
*/
private $comments_and_clauses;
/**
* @var string
*/
private $comments_and_clauses;
/**
* Get Class Name.
*
* @return string
*/
/**
* Get Class Name.
*
* @return string
*/
public static function get_class_name() {
return __CLASS__;
}
/**
* MainWP_Child_Comments constructor.
*/
public function __construct() {
/**
* MainWP_Child_Comments constructor.
*/
public function __construct() {
$this->comments_and_clauses = '';
}
/**
* Create a public static instance of ainWP_Child_Comments.
*
* @return MainWP_Child_Comments|null
*/
public static function get_instance() {
/**
* Create a public static instance of ainWP_Child_Comments.
*
* @return MainWP_Child_Comments|null
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* MainWP Child Comment actions: approve, unapprove, spam, unspam, trash, restore, delete.
*/
public function comment_action() {
/**
* MainWP Child Comment actions: approve, unapprove, spam, unspam, trash, restore, delete.
*/
public function comment_action() {
$action = $_POST['action'];
$commentId = $_POST['id'];
@ -83,10 +84,10 @@ class MainWP_Child_Comments {
MainWP_Helper::write( $information );
}
/**
* MainWP Child Bulk Comment actions: approve, unapprove, spam, unspam, trash, restore, delete.
*/
public function comment_bulk_action() {
/**
* MainWP Child Bulk Comment actions: approve, unapprove, spam, unspam, trash, restore, delete.
*/
public function comment_bulk_action() {
$action = $_POST['action'];
$commentIds = explode( ',', $_POST['ids'] );
$information['success'] = 0;
@ -116,13 +117,13 @@ class MainWP_Child_Comments {
}
/**
* Comment WHERE Clauses.
*
* @param $clauses MySQL WHERE Clause.
* @return array $clauses, Array of MySQL WHERE Clauses.
*/
public function comments_clauses($clauses ) {
/**
* Comment WHERE Clauses.
*
* @param $clauses MySQL WHERE Clause.
* @return array $clauses, Array of MySQL WHERE Clauses.
*/
public function comments_clauses( $clauses ) {
if ( $this->comments_and_clauses ) {
$clauses['where'] .= ' ' . $this->comments_and_clauses;
}
@ -130,14 +131,14 @@ class MainWP_Child_Comments {
return $clauses;
}
/**
* Get all comments.
*
* @return array $rslt Array of comments.
*/
public function get_all_comments() {
/**
* Get all comments.
*
* @return array $rslt Array of comments.
*/
public function get_all_comments() {
/** @var global $wbdb wpdb. */
/** @var global $wbdb wpdb. */
global $wpdb;
add_filter( 'comments_clauses', array( &$this, 'comments_clauses' ) );
@ -175,14 +176,14 @@ class MainWP_Child_Comments {
MainWP_Helper::write( $rslt );
}
/**
* Get recent comments.
*
* @param $pAllowedStatuses Allowed comment statuses.
* @param $pCount Comment count.
* @return array $allComments Array of all comments found.
*/
public function get_recent_comments($pAllowedStatuses, $pCount ) {
/**
* Get recent comments.
*
* @param $pAllowedStatuses Allowed comment statuses.
* @param $pCount Comment count.
* @return array $allComments Array of all comments found.
*/
public function get_recent_comments( $pAllowedStatuses, $pCount ) {
if ( ! function_exists( 'get_comment_author_url' ) ) {
include_once WPINC . '/comment-template.php';
}

View file

@ -279,10 +279,10 @@ class MainWP_Child_Install {
/**
* Hook to set ssl verify.
*
* @param array $r
* @param string $url
* @return array $r
*
* @param array $r
* @param string $url
* @return array $r
*/
public static function no_ssl_filter_function( $r, $url ) {
$r['sslverify'] = false;

View file

@ -13,47 +13,48 @@ namespace MainWP\Child;
/**
* Class MainWP_Child_Plugins_Check
*
* @package MainWP\Child
*/
class MainWP_Child_Plugins_Check {
/**
* @var string
*/
private $cron_name_watcher = 'mainwp_child_cron_plugin_health_check_watcher';
/**
* @var string
*/
private $cron_name_daily = 'mainwp_child_cron_plugin_health_check_daily';
/**
* @var string
*/
private $cron_name_batching = 'mainwp_child_cron_plugin_health_check_batching';
/**
* @var string
*/
private $tran_name_plugin_timestamps = 'mainwp_child_tran_name_plugin_timestamps';
/**
* @var string
*/
private $tran_name_plugins_to_batch = 'mainwp_child_tran_name_plugins_to_batch';
/**
* @var string
*/
private $option_name_last_daily_run = 'mainwp_child_plugin_last_daily_run';
/**
* @var string
*/
private $cron_name_watcher = 'mainwp_child_cron_plugin_health_check_watcher';
/**
* @var string
*/
private $cron_name_daily = 'mainwp_child_cron_plugin_health_check_daily';
/**
* @var string
*/
private $cron_name_batching = 'mainwp_child_cron_plugin_health_check_batching';
/**
* @var string
*/
private $tran_name_plugin_timestamps = 'mainwp_child_tran_name_plugin_timestamps';
/**
* @var string
*/
private $tran_name_plugins_to_batch = 'mainwp_child_tran_name_plugins_to_batch';
/**
* @var string
*/
private $option_name_last_daily_run = 'mainwp_child_plugin_last_daily_run';
/**
* @static
* @var null Holds the Public static instance of MainWP_Child_Plugins_Check.
*/
public static $instance = null;
/**
* @static
* @var null Holds the Public static instance of MainWP_Child_Plugins_Check.
*/
public static $instance = null;
/**
* Create a public static instance of MainWP_Child_Plugins_Check.
*
* @return MainWP_Child_Plugins_Check|null
*/
public static function instance() {
/**
* Create a public static instance of MainWP_Child_Plugins_Check.
*
* @return MainWP_Child_Plugins_Check|null
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
@ -61,10 +62,10 @@ class MainWP_Child_Plugins_Check {
return self::$instance;
}
/**
* MainWP_Child_Plugins_Check constructor.
*/
public function __construct() {
/**
* MainWP_Child_Plugins_Check constructor.
*/
public function __construct() {
if ( get_option( 'mainwp_child_plugintheme_days_outdate' ) ) {
$this->schedule_watchdog();
@ -76,29 +77,29 @@ class MainWP_Child_Plugins_Check {
}
}
/**
* Un-schedules all events attached to the hook with the specified arguments.
*
* @return int|false|bool On success an integer indicating number of events un-scheduled
* (0 indicates no events were registered with the hook and arguments combination),
* false if un-scheduling one or more events fail.
*/
private function cleanup_basic() {
/**
* Un-schedules all events attached to the hook with the specified arguments.
*
* @return int|false|bool On success an integer indicating number of events un-scheduled
* (0 indicates no events were registered with the hook and arguments combination),
* false if un-scheduling one or more events fail.
*/
private function cleanup_basic() {
wp_clear_scheduled_hook( $this->cron_name_daily );
wp_clear_scheduled_hook( $this->cron_name_batching );
delete_transient( $this->tran_name_plugins_to_batch );
}
/**
* Un-schedules all events attached to the hook with the specified arguments.
*
* @param bool $del Whether or not to delete the transient data. Default: true.
* @return int|false|bool On success an integer indicating number of events un-scheduled
* (0 indicates no events were registered with the hook and arguments combination),
* false if un-scheduling one or more events fail.
*/
public function cleanup_deactivation($del = true ) {
/**
* Un-schedules all events attached to the hook with the specified arguments.
*
* @param bool $del Whether or not to delete the transient data. Default: true.
* @return int|false|bool On success an integer indicating number of events un-scheduled
* (0 indicates no events were registered with the hook and arguments combination),
* false if un-scheduling one or more events fail.
*/
public function cleanup_deactivation( $del = true ) {
$this->cleanup_basic();
wp_clear_scheduled_hook( $this->cron_name_watcher );
delete_option( $this->option_name_last_daily_run );
@ -107,14 +108,14 @@ class MainWP_Child_Plugins_Check {
}
}
/**
* Modify plugin API Search Query.
*
* @param object $args Query arguments.
* @param string $action Action to perform: query_plugins.
* @return \stdClass $args Modified Search Query.
*/
public function modify_plugin_api_search_query($args, $action ) {
/**
* Modify plugin API Search Query.
*
* @param object $args Query arguments.
* @param string $action Action to perform: query_plugins.
* @return \stdClass $args Modified Search Query.
*/
public function modify_plugin_api_search_query( $args, $action ) {
if ( isset( $action ) && 'query_plugins' === $action ) {
if ( ! is_object( $args ) ) {
@ -131,12 +132,12 @@ class MainWP_Child_Plugins_Check {
return $args;
}
/**
* Schedule watchdog crons.
*
* @throws \Exception Error message on failure.
*/
public function perform_watchdog() {
/**
* Schedule watchdog crons.
*
* @throws \Exception Error message on failure.
*/
public function perform_watchdog() {
if ( false === wp_next_scheduled( $this->cron_name_daily ) && false === wp_next_scheduled( $this->cron_name_batching ) ) {
$last_run = get_option( $this->option_name_last_daily_run );
@ -159,21 +160,21 @@ class MainWP_Child_Plugins_Check {
}
}
/**
* Schedule a global watchdog cron just in case both other crons get killed.
*/
public function schedule_watchdog() {
/**
* Schedule a global watchdog cron just in case both other crons get killed.
*/
public function schedule_watchdog() {
if ( ! wp_next_scheduled( $this->cron_name_watcher ) ) {
wp_schedule_event( time(), 'hourly', $this->cron_name_watcher );
}
}
/**
* Get plugins outdated info.
*
* @return array $plugins_outdate Array of outdated plugin info.
*/
public function get_plugins_outdate_info() {
/**
* Get plugins outdated info.
*
* @return array $plugins_outdate Array of outdated plugin info.
*/
public function get_plugins_outdate_info() {
$plugins_outdate = get_transient( $this->tran_name_plugin_timestamps );
if ( ! is_array( $plugins_outdate ) ) {
$plugins_outdate = array();
@ -196,10 +197,10 @@ class MainWP_Child_Plugins_Check {
return $plugins_outdate;
}
/**
* Update Days out of date option.
*/
public static function may_outdate_number_change() {
/**
* Update Days out of date option.
*/
public static function may_outdate_number_change() {
if ( isset( $_POST['numberdaysOutdatePluginTheme'] ) ) {
$days_outdate = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
if ( $days_outdate != $_POST['numberdaysOutdatePluginTheme'] ) {
@ -211,12 +212,12 @@ class MainWP_Child_Plugins_Check {
}
}
/**
* Run plugin update check.
*
* @throws \Exception Error message on failure.
*/
public function run_check() {
/**
* Run plugin update check.
*
* @throws \Exception Error message on failure.
*/
public function run_check() {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
@ -306,14 +307,14 @@ class MainWP_Child_Plugins_Check {
}
}
/**
* Try to get response body.
*
* @param $plugin
* @param $second_pass
* @return bool|string true|false The body of the response. Empty string if no body or incorrect parameter given.
*/
private function try_get_response_body($plugin, $second_pass ) {
/**
* Try to get response body.
*
* @param $plugin
* @param $second_pass
* @return bool|string true|false The body of the response. Empty string if no body or incorrect parameter given.
*/
private function try_get_response_body( $plugin, $second_pass ) {
// Get the WordPress current version to be polite in the API call.
include ABSPATH . WPINC . '/version.php';

View file

@ -26,36 +26,38 @@ require_once ABSPATH . '/wp-admin/includes/plugin.php';
/**
* Class MainWP_Child
*
* @package MainWP\Child
*/
class MainWP_Child {
/**
* @static
* @var string MainWP Child Plugin Version.
*/
public static $version = '4.0.7.1';
/**
* @static
* @var string MainWP Child Plugin Version.
*/
public static $version = '4.0.7.1';
/**
* @var string Update Version.
*/
private $update_version = '1.5';
/**
* @var string Update Version.
*/
private $update_version = '1.5';
/**
* @var string MainWP Child Plugin slug.
*/
public $plugin_slug;
/**
* @var string MainWP Child Plugin slug.
*/
public $plugin_slug;
/**
* @var string MainWP Child Plugin directory.
*/
private $plugin_dir;
/**
* @var string MainWP Child Plugin directory.
*/
private $plugin_dir;
/**
* MainWP_Child constructor.
* @param $plugin_file MainWP Child Plugin file.
*/
public function __construct($plugin_file ) {
/**
* MainWP_Child constructor.
*
* @param $plugin_file MainWP Child Plugin file.
*/
public function __construct( $plugin_file ) {
$this->update();
$this->load_all_options();
@ -97,14 +99,14 @@ class MainWP_Child {
}
}
/**
* Load all MainWP Child Plugin options.
*
* @return array|bool Return array of options $alloptions[] or FALSE on failure.
*/
public function load_all_options() {
/**
* Load all MainWP Child Plugin options.
*
* @return array|bool Return array of options $alloptions[] or FALSE on failure.
*/
public function load_all_options() {
/** @var global $wbdb wpdb. */
/** @var global $wbdb wpdb. */
global $wpdb;
if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
@ -178,12 +180,12 @@ class MainWP_Child {
}
/**
* Update MainWP Child Plugin.
*
* @return string Update verison.
*/
public function update() {
/**
* Update MainWP Child Plugin.
*
* @return string Update verison.
*/
public function update() {
$update_version = get_option( 'mainwp_child_update_version' );
if ( $update_version === $this->update_version ) {
@ -193,24 +195,24 @@ class MainWP_Child {
MainWP_Helper::update_option( 'mainwp_child_update_version', $this->update_version, 'yes' );
}
/**
* Load MainWP Child Plugin textdomains.
*/
public function localization() {
/**
* Load MainWP Child Plugin textdomains.
*/
public function localization() {
load_plugin_textdomain( 'mainwp-child', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
}
/**
* Template redirect.
*/
public function template_redirect() {
/**
* Template redirect.
*/
public function template_redirect() {
MainWP_Utility::instance()->maintenance_alert();
}
/**
*
*/
public function parse_init() {
/**
*
*/
public function parse_init() {
if ( isset( $_REQUEST['cloneFunc'] ) ) {
@ -222,7 +224,7 @@ class MainWP_Child {
}
}
/** @var global $wp_rewrite Core class used to implement a rewrite component API. */
/** @var global $wp_rewrite Core class used to implement a rewrite component API. */
global $wp_rewrite;
$snPluginDir = basename( $this->plugin_dir );
@ -284,26 +286,26 @@ class MainWP_Child {
MainWP_Keyword_Links::instance()->parse_init_keyword_links();
}
/**
* Check login.
*/
public function init_check_login() {
/**
* Check login.
*/
public function init_check_login() {
MainWP_Connect::instance()->check_login();
}
/**
* If user is administrator initiate the admin ajax.
*/
public function admin_init() {
/**
* If user is administrator initiate the admin ajax.
*/
public function admin_init() {
if ( MainWP_Helper::is_admin() && is_admin() ) {
MainWP_Clone::get()->init_ajax();
}
}
/**
* Parse MainWP Extension initiations.
*/
private function parse_init_extensions() {
/**
* Parse MainWP Extension initiations.
*/
private function parse_init_extensions() {
// Handle fatal errors for those init if needed.
MainWP_Child_Branding::instance()->branding_init();
MainWP_Client_Report::instance()->creport_init();
@ -321,11 +323,12 @@ class MainWP_Child {
\MainWP_Child_WPvivid_BackupRestore::instance()->init();
}
/**
* Hook to deactivate MainWP Child Plugin.
* @param bool $deact Whether or not to deactivate pugin. Default: true.
*/
public function deactivation($deact = true ) {
/**
* Hook to deactivate MainWP Child Plugin.
*
* @param bool $deact Whether or not to deactivate pugin. Default: true.
*/
public function deactivation( $deact = true ) {
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );
if ( $mu_plugin_enabled ) {
@ -355,10 +358,10 @@ class MainWP_Child {
}
}
/**
* Hook to deactivate Child Plugin.
*/
public function activation() {
/**
* Hook to deactivate Child Plugin.
*/
public function activation() {
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );
if ( $mu_plugin_enabled ) {
return;

View file

@ -10,15 +10,16 @@ namespace MainWP\Child;
/**
* Class MainWP_Clone_Install
*
* @package MainWP\Child
*/
class MainWP_Clone_Install {
/** @var string The zip backup file path. */
protected $file;
/** @var string The zip backup file path. */
protected $file;
/** @var array Clone config settings. */
public $config;
/** @var array Clone config settings. */
public $config;
/** @var $archiver Tar_Archiver */
protected $archiver;
@ -61,21 +62,21 @@ class MainWP_Clone_Install {
return false;
}
/**
* Check if unzip_file function exists.
*
* @return bool true|false.
*/
public function check_wp_zip() {
/**
* Check if unzip_file function exists.
*
* @return bool true|false.
*/
public function check_wp_zip() {
return function_exists( 'unzip_file' );
}
/**
* Remove wp-config.php file.
*
* @return bool true|false.
*/
public function remove_config_file() {
/**
* Remove wp-config.php file.
*
* @return bool true|false.
*/
public function remove_config_file() {
if ( ! $this->file || ! file_exists( $this->file ) ) {
return false;
}
@ -110,12 +111,12 @@ class MainWP_Clone_Install {
return false;
}
/**
* Test the download.
*
* @throws \Exception Error message.
*/
public function test_download() {
/**
* Test the download.
*
* @throws \Exception Error message.
*/
public function test_download() {
if ( ! $this->file_exists( 'wp-content/' ) ) {
throw new \Exception( __( 'This is not a full backup.', 'mainwp-child' ) );
}
@ -127,13 +128,13 @@ class MainWP_Clone_Install {
}
}
/**
* Check if clone config.txt exists.
*
* @param $file Config.txt file path.
* @return bool|string False or True on success. Return config.txt content on true.
*/
private function file_exists($file ) {
/**
* Check if clone config.txt exists.
*
* @param $file Config.txt file path.
* @return bool|string False or True on success. Return config.txt content on true.
*/
private function file_exists( $file ) {
if ( 'extracted' === $this->file ) {
return file_get_contents( '../clone/config.txt' );
}
@ -168,12 +169,12 @@ class MainWP_Clone_Install {
return false;
}
/**
* Read configuration file.
*
* @throws \Exception Error message on failure.
*/
public function read_configuration_file() {
/**
* Read configuration file.
*
* @throws \Exception Error message on failure.
*/
public function read_configuration_file() {
$configContents = $this->get_config_contents();
if ( false === $configContents ) {
throw new \Exception( __( 'Cant read configuration file from the backup.', 'mainwp-child' ) );
@ -192,10 +193,10 @@ class MainWP_Clone_Install {
}
}
/**
* Clean file structure after installation.
*/
public function clean() {
/**
* Clean file structure after installation.
*/
public function clean() {
$files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' );
foreach ( $files as $file ) {
unlink( $file );
@ -222,10 +223,10 @@ class MainWP_Clone_Install {
}
}
/**
* Update wp-config.php file.
*/
public function update_wp_config() {
/**
* Update wp-config.php file.
*/
public function update_wp_config() {
$wpConfig = file_get_contents( ABSPATH . 'wp-config.php' );
$wpConfig = $this->replace_var( 'table_prefix', $this->config['prefix'], $wpConfig );
if ( isset( $this->config['lang'] ) ) {
@ -234,13 +235,13 @@ class MainWP_Clone_Install {
file_put_contents( ABSPATH . 'wp-config.php', $wpConfig );
}
/**
* Update DB options.
*
* @param $name Option name.
* @param $value Option value to update.
*/
public function update_option($name, $value ) {
/**
* Update DB options.
*
* @param $name Option name.
* @param $value Option value to update.
*/
public function update_option( $name, $value ) {
/** @var $wpdb wpdb */
global $wpdb;
@ -253,13 +254,13 @@ class MainWP_Clone_Install {
}
}
/**
* Database Installation.
*
* @return bool true|false.
* @throws \Exception Error message on failure.
*/
public function install() {
/**
* Database Installation.
*
* @return bool true|false.
* @throws \Exception Error message on failure.
*/
public function install() {
/** @var $wpdb wpdb */
global $wpdb;
@ -332,12 +333,12 @@ class MainWP_Clone_Install {
return true;
}
/**
* Get config contents.
*
* @return bool|false|mixed|string
*/
public function get_config_contents() {
/**
* Get config contents.
*
* @return bool|false|mixed|string
*/
public function get_config_contents() {
if ( 'extracted' === $this->file ) {
return file_get_contents( '../clone/config.txt' );
}
@ -382,12 +383,12 @@ class MainWP_Clone_Install {
return false;
}
/**
* Extract backup file.
*
* @return bool|null true or null.
* @throws \Exception Error message on failure.
*/
/**
* Extract backup file.
*
* @return bool|null true or null.
* @throws \Exception Error message on failure.
*/
public function extract_backup() {
if ( ! $this->file || ! file_exists( $this->file ) ) {
return false;
@ -429,12 +430,12 @@ class MainWP_Clone_Install {
return false;
}
/**
* Extract with unzip_file.
*
* @return bool true|false.
*/
public function extract_wp_zip_backup() {
/**
* Extract with unzip_file.
*
* @return bool true|false.
*/
public function extract_wp_zip_backup() {
MainWP_Helper::get_wp_filesystem();
global $wp_filesystem;
@ -450,13 +451,13 @@ class MainWP_Clone_Install {
return true;
}
/**
* Extract PCLZIP.
*
* @return bool true|false.
* @throws \Exception Error on failure.
*/
public function extract_zip_pcl_backup() {
/**
* Extract PCLZIP.
*
* @return bool true|false.
* @throws \Exception Error on failure.
*/
public function extract_zip_pcl_backup() {
$zip = new \PclZip( $this->file );
if ( 0 === $zip->extract( PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER ) ) {
return false;
@ -503,13 +504,13 @@ class MainWP_Clone_Install {
return preg_replace( '/(\$' . $varname . ' *= *[\'"])(.*?)([\'"] *;)/is', '${1}' . $value . '${3}', $content );
}
/**
* Recursively chmod file structure.
*
* @param $mypath Path to files.
* @param $arg chmod arguments.
*/
public function recurse_chmod($mypath, $arg ) {
/**
* Recursively chmod file structure.
*
* @param $mypath Path to files.
* @param $arg chmod arguments.
*/
public function recurse_chmod( $mypath, $arg ) {
$d = opendir( $mypath );
while ( ( $file = readdir( $d ) ) !== false ) {
if ( '.' !== $file && '..' !== $file ) {
@ -686,12 +687,12 @@ class MainWP_Clone_Install {
return $data;
}
/**
* Request clone.
*
* @return bool|void true|void.
*/
public function request_clone_funct() {
/**
* Request clone.
*
* @return bool|void true|void.
*/
public function request_clone_funct() {
if ( ! isset( $_REQUEST['key'] ) ) {
return;
@ -738,10 +739,10 @@ class MainWP_Clone_Install {
return true;
}
/**
* Create backup of clone.
*/
private function create_clone_backup() {
/**
* Create backup of clone.
*/
private function create_clone_backup() {
MainWP_Helper::end_session();
$files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' );
foreach ( $files as $file ) {