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

Apply fixes from CodeFactor
This commit is contained in:
Thang Hoang Van 2020-05-11 20:35:16 +07:00 committed by GitHub
commit 3936785bd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 59 deletions

View file

@ -315,7 +315,7 @@ class MainWP_Child_Branding {
public static function upload_image( $img_url ) {
include_once ABSPATH . 'wp-admin/includes/file.php';
add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
$temporary_file = download_url( $img_url );
remove_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );

View file

@ -3,10 +3,10 @@
namespace MainWP\Child;
class MainWP_Child_Install {
protected static $instance = null;
/**
* Method get_class_name()
*
@ -19,9 +19,8 @@ class MainWP_Child_Install {
}
public function __construct() {
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
@ -34,7 +33,7 @@ class MainWP_Child_Install {
* Functions to support core functionality
*/
public function install_plugin_theme() {
MainWP_Helper::check_wp_filesystem();
if ( ! isset( $_POST['type'] ) || ! isset( $_POST['url'] ) || ( 'plugin' !== $_POST['type'] && 'theme' !== $_POST['type'] ) || '' === $_POST['url'] ) {

View file

@ -127,7 +127,7 @@ class MainWP_Child_Plugins_Check {
return $plugins_outdate;
}
public static function may_outdate_number_change() {
if ( isset( $_POST['numberdaysOutdatePluginTheme'] ) ) {
$days_outdate = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );

View file

@ -3,12 +3,12 @@
namespace MainWP\Child;
class MainWP_Child_Updates {
protected static $instance = null;
private $filterFunction = null;
private $filterFunction = null;
/**
* Method get_class_name()
*
@ -30,7 +30,7 @@ class MainWP_Child_Updates {
return $a;
};
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
@ -354,8 +354,8 @@ class MainWP_Child_Updates {
$information['sync'] = $this->get_site_stats( array(), false );
mainwp_child_helper()->write( $information );
}
public function hook_fix_optimize_press_theme_update( $transient ) {
if ( ! defined( 'OP_FUNC' ) ) {
return $transient;
@ -388,7 +388,7 @@ class MainWP_Child_Updates {
return $transient;
}
public function set_cached_update_plugins( $false = false, $_transient_data = null ) {
if ( ! is_object( $_transient_data ) ) {
@ -412,8 +412,8 @@ class MainWP_Child_Updates {
return $_transient_data;
}
public function set_cached_update_themes( $false = false, $_transient_data = null ) {
if ( ! is_object( $_transient_data ) ) {
@ -437,7 +437,7 @@ class MainWP_Child_Updates {
return $_transient_data;
}
public function detect_premium_themesplugins_updates() {
if ( isset( $_GET['_detect_plugins_updates'] ) && 'yes' == $_GET['_detect_plugins_updates'] ) {
@ -461,32 +461,31 @@ class MainWP_Child_Updates {
}
$type = isset( $_GET['_request_update_premiums_type'] ) ? $_GET['_request_update_premiums_type'] : '';
if ( 'plugin' == $type || 'theme' == $type ) {
$list = isset( $_GET['list'] ) ? $_GET['list'] : '';
if ( ! empty( $list ) ) {
// to call function upgrade_plugin_theme().
$_POST['type'] = $type;
$_POST['list'] = $list;
global $mainWPChild;
$callable = $mainWPChild->get_callable_functions();
$function = 'upgradeplugintheme';
if ( isset( $callable [ $function ] ) ) {
call_user_func( array( $this, $callable [ $function ] ) );
}
}
}
}
/**
* Functions to support core functionality
*/
public function install_plugin_theme() {
MainWP_Helper::check_wp_filesystem();
if ( ! isset( $_POST['type'] ) || ! isset( $_POST['url'] ) || ( 'plugin' !== $_POST['type'] && 'theme' !== $_POST['type'] ) || '' === $_POST['url'] ) {
@ -610,13 +609,13 @@ class MainWP_Child_Updates {
mainwp_child_helper()->write( $information );
}
// This will upgrade WP!
public function upgrade_wp() {
global $wp_version;
global $wp_version;
MainWP_Helper::get_wp_filesystem();
$information = array();
include_once ABSPATH . '/wp-admin/includes/update.php';
@ -750,5 +749,5 @@ class MainWP_Child_Updates {
$information['sync'] = $this->get_site_stats( array(), false );
mainwp_child_helper()->write( $information );
}
}
}

View file

@ -486,7 +486,7 @@ class MainWP_Child {
public function get_callable_functions() {
return $this->callableFunctions;
}
public function admin_menu() {
$branding_opts = MainWP_Child_Branding::instance()->get_branding_options();
$is_hide = isset( $branding_opts['hide'] ) ? $branding_opts['hide'] : '';
@ -1496,16 +1496,16 @@ class MainWP_Child {
/**
* Functions to support core functionality
*/
* Functions to support core functionality
*/
public function install_plugin_theme() {
MainWP_Child_Install::get_instance()->install_plugin_theme();
}
public function upgrade_wp() {
MainWP_Child_Updates::get_instance()->upgrade_wp();
}
public function upgrade_translation() {
MainWP_Child_Updates::get_instance()->upgrade_translation();
}
@ -2965,9 +2965,9 @@ class MainWP_Child {
$recent_number = 5;
}
$information['recent_posts'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number );
$information['recent_pages'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number, 'page' );
$information['securityIssues'] = MainWP_Security::get_stats_security();;
$information['recent_posts'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number );
$information['recent_pages'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number, 'page' );
$information['securityIssues'] = MainWP_Security::get_stats_security();
// Directory listings!
$information['directories'] = $this->scan_dir( ABSPATH, 3 );
@ -3607,11 +3607,11 @@ class MainWP_Child {
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
global $wp_filesystem;
MainWP_Helper::check_wp_filesystem();
if ( empty( $wp_filesystem ) ) {
$wp_filesystem = new WP_Filesystem_Direct( null );
}
@ -3737,9 +3737,9 @@ class MainWP_Child {
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
global $wp_filesystem;
global $wp_filesystem;
MainWP_Helper::check_wp_filesystem();
if ( null === $wp_filesystem ) {
$wp_filesystem = new WP_Filesystem_Direct( null );
}

View file

@ -16,7 +16,7 @@ class MainWP_Helper {
public static function get_class_name() {
return __CLASS__;
}
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
@ -225,7 +225,7 @@ class MainWP_Helper {
if ( ! is_array( $img_data ) ) {
$img_data = array();
}
include_once ABSPATH . 'wp-admin/includes/file.php';
$upload_dir = wp_upload_dir();
add_filter( 'http_request_args', array( self::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );
@ -1002,29 +1002,29 @@ class MainWP_Helper {
return $init;
}
public static function check_wp_filesystem() {
self::get_wp_filesystem();
public static function check_wp_filesystem() {
self::get_wp_filesystem();
global $wp_filesystem;
if ( empty( $wp_filesystem ) ) {
MainWP_Helper::error( $this->FTP_ERROR );
self::error( $this->FTP_ERROR );
} elseif ( is_wp_error( $wp_filesystem->errors ) ) {
$errorCodes = $wp_filesystem->errors->get_error_codes();
if ( ! empty( $errorCodes ) ) {
MainWP_Helper::error( __( 'WordPress Filesystem error: ', 'mainwp-child' ) . $wp_filesystem->errors->get_error_message() );
self::error( __( 'WordPress Filesystem error: ', 'mainwp-child' ) . $wp_filesystem->errors->get_error_message() );
}
}
return $wp_filesystem;
}
public static function no_ssl_filter_function( $r, $url ) {
$r['sslverify'] = false;
return $r;
}
public static function reject_unsafe_urls( $r, $url ) {
$r['reject_unsafe_urls'] = false;
if ( isset( $_POST['wpadmin_user'] ) && ! empty( $_POST['wpadmin_user'] ) && isset( $_POST['wpadmin_passwd'] ) && ! empty( $_POST['wpadmin_passwd'] ) ) {
@ -1033,7 +1033,7 @@ class MainWP_Helper {
}
return $r;
}
public static function starts_with( $haystack, $needle ) {
return ! strncmp( $haystack, $needle, strlen( $needle ) );
}

View file

@ -299,10 +299,10 @@ class MainWP_Security {
}
if ( ! self::remove_readme_ok() ) {
$securityIssuess ++;
}
}
return $securityIssuess;
}
public static function update_security_option( $key, $value ) {
$security = get_option( 'mainwp_security' );
if ( ! empty( $key ) ) {

View file

@ -55,7 +55,7 @@ class MainWP_WordPress_SEO {
if ( isset( $_POST['file_url'] ) ) {
$file_url = base64_decode( $_POST['file_url'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
$temporary_file = '';
try {
include_once ABSPATH . 'wp-admin/includes/file.php';
add_filter( 'http_request_args', array( MainWP_Helper::get_class_name(), 'reject_unsafe_urls' ), 99, 2 );