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
f5acc21b32
commit
64931ea48a
10 changed files with 51 additions and 69 deletions
|
@ -153,7 +153,7 @@ class MainWP_Backup {
|
|||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function backup_checkpid() {
|
||||
$pid = $_POST['pid'];
|
||||
|
||||
|
@ -202,7 +202,7 @@ class MainWP_Backup {
|
|||
|
||||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
|
||||
public function backup( $pWrite = true ) {
|
||||
|
||||
$timeout = 20 * 60 * 60;
|
||||
|
|
|
@ -334,7 +334,7 @@ class MainWP_Child_Callable {
|
|||
global $wpdb;
|
||||
return $wpdb->get_results( $wpdb->prepare( " SELECT `post_parent`, COUNT(*) cnt FROM $wpdb->posts WHERE `post_type` = 'revision' GROUP BY `post_parent` HAVING COUNT(*) > %d ", $max_revisions ) );
|
||||
}
|
||||
|
||||
|
||||
private function maintenance_delete_revisions( $results, $max_revisions ) {
|
||||
global $wpdb;
|
||||
|
||||
|
@ -433,7 +433,7 @@ class MainWP_Child_Callable {
|
|||
}
|
||||
|
||||
public function backup_poll() {
|
||||
MainWP_Backup::get()->backup_poll();
|
||||
MainWP_Backup::get()->backup_poll();
|
||||
}
|
||||
|
||||
public function backup_checkpid() {
|
||||
|
@ -441,7 +441,7 @@ class MainWP_Child_Callable {
|
|||
}
|
||||
|
||||
public function backup( $pWrite = true ) {
|
||||
return MainWP_Backup::get()->backup( $pWrite );
|
||||
return MainWP_Backup::get()->backup( $pWrite );
|
||||
}
|
||||
|
||||
protected function backup_full( $fileName ) {
|
||||
|
@ -449,7 +449,7 @@ class MainWP_Child_Callable {
|
|||
}
|
||||
|
||||
protected function backup_db( $fileName = '', $ext = 'zip' ) {
|
||||
return MainWP_Backup::get()->backup_db( $fileName, $ext );
|
||||
return MainWP_Backup::get()->backup_db( $fileName, $ext );
|
||||
}
|
||||
|
||||
public function get_site_icon() {
|
||||
|
|
|
@ -276,7 +276,7 @@ class MainWP_Child_Install {
|
|||
$information['destination_name'] = $result['destination_name'];
|
||||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hook to set ssl verify.
|
||||
*/
|
||||
|
@ -284,7 +284,7 @@ class MainWP_Child_Install {
|
|||
$r['sslverify'] = false;
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Include necessary files.
|
||||
*/
|
||||
|
|
|
@ -76,7 +76,7 @@ class MainWP_Child_Posts {
|
|||
|
||||
$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' ) ) {
|
||||
if ( is_plugin_active( 'wordpress-seo/wp-seo.php' ) && class_exists( '\WPSEO_Link_Column_Count' ) && class_exists( '\WPSEO_Meta' ) ) {
|
||||
$wp_seo_enabled = true;
|
||||
}
|
||||
}
|
||||
|
@ -685,7 +685,7 @@ class MainWP_Child_Posts {
|
|||
}
|
||||
}
|
||||
$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->update_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 );
|
||||
|
@ -736,7 +736,7 @@ class MainWP_Child_Posts {
|
|||
|
||||
global $current_user;
|
||||
|
||||
$this->create_wp_rocket( $post_custom );
|
||||
$this->update_wp_rocket_custom_post( $post_custom );
|
||||
|
||||
// current user may be connected admin or alternative admin.
|
||||
$current_uid = $current_user->ID;
|
||||
|
@ -777,13 +777,13 @@ class MainWP_Child_Posts {
|
|||
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' ) ) {
|
||||
if ( class_exists( '\WPSEO_Meta' ) && class_exists( '\WPSEO_Admin' ) ) {
|
||||
$seo_ext_activated = true;
|
||||
}
|
||||
|
||||
$post_to_only_existing_categories = false;
|
||||
|
||||
$this->create_set_custom_fields( $new_post_id, $post_custom, $seo_ext_activated, $post_to_only_existing_categories );
|
||||
$this->set_custom_post_fields( $new_post_id, $post_custom, $seo_ext_activated, $post_to_only_existing_categories );
|
||||
|
||||
// yoast seo plugin activated.
|
||||
if ( $seo_ext_activated ) {
|
||||
|
@ -791,12 +791,12 @@ class MainWP_Child_Posts {
|
|||
}
|
||||
|
||||
$this->create_set_categories( $new_post_id, $post_category, $post_to_only_existing_categories );
|
||||
|
||||
$this->create_featured_image( $new_post_id, $post_featured_image, $check_image_existed );
|
||||
|
||||
// post plus extension process.
|
||||
if ( $is_post_plus ) {
|
||||
$this->create_post_plus_categories( $new_post_id, $post_custom );
|
||||
$this->post_plus_update_author( $new_post_id, $post_custom );
|
||||
$this->post_plus_update_categories( $new_post_id, $post_custom );
|
||||
}
|
||||
|
||||
// to support custom post author.
|
||||
|
@ -811,7 +811,7 @@ class MainWP_Child_Posts {
|
|||
}
|
||||
}
|
||||
|
||||
private function create_wp_rocket( &$post_custom ) {
|
||||
private function update_wp_rocket_custom_post( &$post_custom ) {
|
||||
// Options fields.
|
||||
$wprocket_fields = array(
|
||||
'lazyload',
|
||||
|
@ -846,7 +846,7 @@ class MainWP_Child_Posts {
|
|||
}
|
||||
}
|
||||
|
||||
private function create_found_images( &$new_post, $upload_dir, $check_image_existed ) {
|
||||
private function update_found_images( &$new_post, $upload_dir, $check_image_existed ) {
|
||||
|
||||
// Search for all the images added to the new post. Some images have a href tag to click to navigate to the image.. we need to replace this too.
|
||||
$foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER );
|
||||
|
@ -970,12 +970,11 @@ class MainWP_Child_Posts {
|
|||
}
|
||||
}
|
||||
|
||||
private function create_post_plus_categories( $new_post_id, $post_custom ) {
|
||||
|
||||
$random_privelege = isset( $post_custom['_saved_draft_random_privelege'] ) ? $post_custom['_saved_draft_random_privelege'] : null;
|
||||
$random_privelege = is_array( $random_privelege ) ? current( $random_privelege ) : null;
|
||||
$random_privelege_base = base64_decode( $random_privelege ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
||||
$random_privelege = maybe_unserialize( $random_privelege_base );
|
||||
private function post_plus_update_author( $new_post_id, $post_custom ) {
|
||||
$random_privelege = isset( $post_custom['_saved_draft_random_privelege'] ) ? $post_custom['_saved_draft_random_privelege'] : null;
|
||||
$random_privelege = is_array( $random_privelege ) ? current( $random_privelege ) : null;
|
||||
$random_privelege_base = base64_decode( $random_privelege ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
||||
$random_privelege = maybe_unserialize( $random_privelege_base );
|
||||
|
||||
if ( is_array( $random_privelege ) && count( $random_privelege ) > 0 ) {
|
||||
$random_post_authors = array();
|
||||
|
@ -996,9 +995,11 @@ class MainWP_Child_Posts {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
$random_category = isset( $post_custom['_saved_draft_random_category'] ) ? $post_custom['_saved_draft_random_category'] : false;
|
||||
$random_category = is_array( $random_category ) ? current( $random_category ) : null;
|
||||
}
|
||||
|
||||
private function post_plus_update_categories( $new_post_id, $post_custom ) {
|
||||
$random_category = isset( $post_custom['_saved_draft_random_category'] ) ? $post_custom['_saved_draft_random_category'] : false;
|
||||
$random_category = is_array( $random_category ) ? current( $random_category ) : null;
|
||||
if ( ! empty( $random_category ) ) {
|
||||
$cats = get_categories(
|
||||
array(
|
||||
|
@ -1045,7 +1046,7 @@ class MainWP_Child_Posts {
|
|||
}
|
||||
}
|
||||
|
||||
private function create_set_custom_fields( $new_post_id, $post_custom, $seo_ext_activated, &$post_to_only ) {
|
||||
private function set_custom_post_fields( $new_post_id, $post_custom, $seo_ext_activated, &$post_to_only ) {
|
||||
|
||||
// Set custom fields.
|
||||
$not_allowed = array(
|
||||
|
|
|
@ -15,7 +15,7 @@ class MainWP_Child_Server_Information extends MainWP_Child_Server_Information_Ba
|
|||
public static function get_class_name() {
|
||||
return __CLASS__;
|
||||
}
|
||||
|
||||
|
||||
public static function init() {
|
||||
add_action(
|
||||
'wp_ajax_mainwp-child_dismiss_warnings',
|
||||
|
@ -890,7 +890,7 @@ class MainWP_Child_Server_Information extends MainWP_Child_Server_Information_Ba
|
|||
<td><?php echo esc_html( $pResult ); ?></td>
|
||||
<td><?php echo ( $pPassed ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>' ); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
<?php
|
||||
}
|
||||
|
||||
protected static function render_row( $pConfig, $pCompare, $pVersion, $pGetter, $pExtraText = '', $pExtraCompare = null, $pExtraVersion = null, $sizeCompare = false ) {
|
||||
|
@ -946,7 +946,7 @@ class MainWP_Child_Server_Information extends MainWP_Child_Server_Information_Ba
|
|||
*Includes last_lines() function by phant0m, licensed under cc-wiki and GPLv2+
|
||||
*/
|
||||
|
||||
private static function render_error_page() {
|
||||
private static function render_error_page() {
|
||||
?>
|
||||
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
||||
<thead title="Click to Toggle" style="cursor: pointer;">
|
||||
|
|
|
@ -563,8 +563,8 @@ class MainWP_Child_Stats {
|
|||
}
|
||||
}
|
||||
}
|
||||
if ( class_exists( 'COM' ) ) {
|
||||
$obj = new COM( 'scripting.filesystemobject' );
|
||||
if ( class_exists( '\COM' ) ) {
|
||||
$obj = new \COM( 'scripting.filesystemobject' );
|
||||
|
||||
if ( is_object( $obj ) ) {
|
||||
$ref = $obj->getfolder( $directory );
|
||||
|
@ -578,9 +578,9 @@ class MainWP_Child_Stats {
|
|||
}
|
||||
}
|
||||
// to fix for window host, performance not good?
|
||||
if ( class_exists( 'RecursiveIteratorIterator' ) ) {
|
||||
if ( class_exists( '\RecursiveIteratorIterator' ) ) {
|
||||
$size = 0;
|
||||
foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $directory ) ) as $file ) {
|
||||
foreach ( new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $directory ) ) as $file ) {
|
||||
$size += $file->getSize();
|
||||
}
|
||||
if ( $size && MainWP_Helper::ctype_digit( $size ) ) {
|
||||
|
|
|
@ -371,11 +371,11 @@ class MainWP_Child_Updates {
|
|||
|
||||
if ( in_array( 'backupbuddy/backupbuddy.php', $plugins ) ) {
|
||||
if ( isset( $GLOBALS['ithemes_updater_path'] ) ) {
|
||||
if ( ! class_exists( 'Ithemes_Updater_Settings' ) ) {
|
||||
if ( ! class_exists( '\Ithemes_Updater_Settings' ) ) {
|
||||
require $GLOBALS['ithemes_updater_path'] . '/settings.php';
|
||||
}
|
||||
if ( class_exists( 'Ithemes_Updater_Settings' ) ) {
|
||||
$ithemes_updater = new Ithemes_Updater_Settings();
|
||||
if ( class_exists( '\Ithemes_Updater_Settings' ) ) {
|
||||
$ithemes_updater = new \Ithemes_Updater_Settings();
|
||||
$ithemes_updater->update();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ class MainWP_Clone {
|
|||
}
|
||||
|
||||
$branding_opts = MainWP_Child_Branding::instance()->get_branding_options();
|
||||
$hide_restore = isset( $branding_opts['remove_restore'] ) && $branding_opts['remove_restore'] ? true : false;
|
||||
$hide_restore = isset( $branding_opts['remove_restore'] ) && $branding_opts['remove_restore'] ? true : false;
|
||||
if ( ! $hide_restore ) {
|
||||
if ( '' == session_id() ) {
|
||||
session_start();
|
||||
|
@ -1464,7 +1464,7 @@ class MainWP_Clone {
|
|||
}
|
||||
return $file;
|
||||
}
|
||||
|
||||
|
||||
public static function is_archive( $pFileName, $pPrefix = '', $pSuffix = '' ) {
|
||||
return preg_match( '/' . $pPrefix . '(.*).(zip|tar|tar.gz|tar.bz2)' . $pSuffix . '$/', $pFileName );
|
||||
}
|
||||
|
|
|
@ -121,7 +121,6 @@ class MainWP_Helper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -151,7 +150,6 @@ class MainWP_Helper {
|
|||
} else {
|
||||
$init = true;
|
||||
}
|
||||
|
||||
return $init;
|
||||
}
|
||||
|
||||
|
@ -192,7 +190,6 @@ class MainWP_Helper {
|
|||
if ( 0 == $length ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ( substr( $haystack, - $length ) == $needle );
|
||||
}
|
||||
|
||||
|
@ -220,7 +217,6 @@ class MainWP_Helper {
|
|||
} else {
|
||||
$url = $url . '/';
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
@ -235,7 +231,6 @@ class MainWP_Helper {
|
|||
while ( $length -- ) {
|
||||
$str .= $charset[ mt_rand( 0, $count - 1 ) ]; // phpcs:ignore
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
@ -255,7 +250,6 @@ class MainWP_Helper {
|
|||
$val *= 1024;
|
||||
break;
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
|
@ -270,7 +264,6 @@ class MainWP_Helper {
|
|||
if ( ! is_readable( $dir ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ( 2 === count( scandir( $dir ) ) );
|
||||
}
|
||||
|
||||
|
@ -304,13 +297,11 @@ class MainWP_Helper {
|
|||
return ( function_exists( $func ) && ! array_search( $func, $suhosin ) );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function get_timestamp( $timestamp ) {
|
||||
$gmtOffset = get_option( 'gmt_offset' );
|
||||
|
||||
return ( $gmtOffset ? ( $gmtOffset * HOUR_IN_SECONDS ) + $timestamp : $timestamp );
|
||||
}
|
||||
|
||||
|
@ -328,11 +319,9 @@ class MainWP_Helper {
|
|||
|
||||
public static function update_option( $option_name, $option_value, $autoload = 'no' ) {
|
||||
$success = add_option( $option_name, $option_value, '', $autoload );
|
||||
|
||||
if ( ! $success ) {
|
||||
$success = update_option( $option_name, $option_value );
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
|
@ -340,7 +329,6 @@ class MainWP_Helper {
|
|||
if ( empty( $value ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( null != $excludes ) {
|
||||
foreach ( $excludes as $exclude ) {
|
||||
if ( self::ends_with( $exclude, '*' ) ) {
|
||||
|
@ -354,7 +342,6 @@ class MainWP_Helper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -362,14 +349,12 @@ class MainWP_Helper {
|
|||
if ( ! function_exists( 'mb_ereg_replace' ) ) {
|
||||
return sanitize_file_name( $filename );
|
||||
}
|
||||
|
||||
// Remove anything which isn't a word, whitespace, number or any of the following caracters -_~,;:[]().
|
||||
// If you don't need to handle multi-byte characters you can use preg_replace rather than mb_ereg_replace.
|
||||
// Thanks @<40>?ukasz Rysiak!
|
||||
$filename = mb_ereg_replace( '([^\w\s\d\-_~,;:\[\]\(\).])', '', $filename );
|
||||
// Remove any runs of periods (thanks falstro!).
|
||||
$filename = mb_ereg_replace( '([\.]{2,})', '', $filename );
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
|
@ -382,11 +367,9 @@ class MainWP_Helper {
|
|||
if ( 0 == $current_user->ID ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 10 == $current_user->wp_user_level || ( isset( $current_user->user_level ) && 10 == $current_user->user_level ) || current_user_can( 'level_10' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -398,11 +381,9 @@ class MainWP_Helper {
|
|||
}
|
||||
|
||||
public static function is_updates_screen() {
|
||||
|
||||
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( function_exists( 'get_current_screen' ) ) {
|
||||
$screen = get_current_screen();
|
||||
if ( $screen ) {
|
||||
|
@ -431,7 +412,6 @@ class MainWP_Helper {
|
|||
$missing[] = $files;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $missing ) ) {
|
||||
$message = 'Missing file(s): ' . implode( ',', $missing );
|
||||
if ( $return ) {
|
||||
|
@ -456,7 +436,6 @@ class MainWP_Helper {
|
|||
$missing[] = $classes;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $missing ) ) {
|
||||
$message = 'Missing classes: ' . implode( ',', $missing );
|
||||
if ( $return ) {
|
||||
|
@ -482,7 +461,6 @@ class MainWP_Helper {
|
|||
$missing[] = $methods;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $missing ) ) {
|
||||
$message = 'Missing method: ' . implode( ',', $missing );
|
||||
if ( $return ) {
|
||||
|
@ -491,7 +469,6 @@ class MainWP_Helper {
|
|||
throw new \Exception( $message );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -508,7 +485,6 @@ class MainWP_Helper {
|
|||
$missing[] = $properties;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $missing ) ) {
|
||||
$message = 'Missing properties: ' . implode( ',', $missing );
|
||||
if ( $return ) {
|
||||
|
@ -517,7 +493,6 @@ class MainWP_Helper {
|
|||
throw new \Exception( $message );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -534,7 +509,6 @@ class MainWP_Helper {
|
|||
$missing[] = $funcs;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $missing ) ) {
|
||||
$message = 'Missing functions: ' . implode( ',', $missing );
|
||||
if ( $return ) {
|
||||
|
@ -543,7 +517,6 @@ class MainWP_Helper {
|
|||
throw new \Exception( $message );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
14
phpcs.xml
14
phpcs.xml
|
@ -28,11 +28,19 @@
|
|||
<!-- Disable Strict comparison check. Not applicable in the mojority of cases. -->
|
||||
<exclude name="WordPress.PHP.StrictComparisons"/>
|
||||
|
||||
<!-- Disable Strict comparison in array check. Not applicable in the mojority of cases. -->
|
||||
<exclude name="WordPress.PHP.StrictInArray"/>
|
||||
<!-- Disable Strict comparison in array check. Not applicable in the mojority of cases. -->
|
||||
<exclude name="WordPress.PHP.StrictInArray"/>
|
||||
|
||||
<!-- Disable Misuse of WP internationalization function check. -->
|
||||
<exclude name="WordPress.WP.I18n"/>
|
||||
<exclude name="WordPress.WP.I18n"/>
|
||||
</rule>
|
||||
|
||||
<!-- Checks the cyclomatic complexity for functions. -->
|
||||
<rule ref="Generic.Metrics.CyclomaticComplexity">
|
||||
<properties>
|
||||
<property name="complexity" value="15" />
|
||||
<property name="absoluteComplexity" value="30" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Enforce PSR1 compatible namespaces. -->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue