mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-09-06 11:10:43 +08:00
Fixed: CodeFactor issues
This commit is contained in:
parent
b0aea12aab
commit
15c17d71c7
1 changed files with 52 additions and 66 deletions
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
/**
|
||||
* Credits
|
||||
*
|
||||
* Plugin-Name: WP Staging
|
||||
|
@ -12,16 +10,14 @@
|
|||
*
|
||||
* The code is used for the MainWP Staging Extension
|
||||
* Extension URL: https://mainwp.com/extension/staging/
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class MainWP_Child_Staging {
|
||||
|
||||
public static $instance = null;
|
||||
public $is_plugin_installed = false;
|
||||
|
||||
static function Instance() {
|
||||
public static function Instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new MainWP_Child_Staging();
|
||||
}
|
||||
|
@ -45,7 +41,7 @@ class MainWP_Child_Staging {
|
|||
|
||||
|
||||
public function init() {
|
||||
if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' ) {
|
||||
if ( 'Y' !== get_option( 'mainwp_wp_staging_ext_enabled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -53,7 +49,7 @@ class MainWP_Child_Staging {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( get_option( 'mainwp_wp_staging_hide_plugin' ) === 'hide' ) {
|
||||
if ( 'hide' === get_option( 'mainwp_wp_staging_hide_plugin' ) ) {
|
||||
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
||||
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
||||
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
||||
|
@ -66,28 +62,29 @@ class MainWP_Child_Staging {
|
|||
try {
|
||||
$information['syncWPStaging'] = $this->get_sync_data();
|
||||
} catch ( Exception $e ) {
|
||||
// do not exit
|
||||
// ok!
|
||||
}
|
||||
}
|
||||
return $information;
|
||||
}
|
||||
// ok
|
||||
|
||||
public function get_sync_data() {
|
||||
return $this->get_overview();
|
||||
}
|
||||
|
||||
public function action() {
|
||||
if ( ! $this->is_plugin_installed ) {
|
||||
MainWP_Helper::write( array( 'error' => 'Please install WP Staging plugin on child website' ) );
|
||||
MainWP_Helper::write( array( 'error' => __( 'Please install WP Staging plugin on child website', 'mainwp-child' ) ) );
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WPStaging\WPStaging' ) ) {
|
||||
require_once WPSTG_PLUGIN_DIR . 'apps/Core/WPStaging.php';
|
||||
}
|
||||
\WPStaging\WPStaging::getInstance();
|
||||
|
||||
\WPStaging\WPStaging::getInstance();
|
||||
$information = array();
|
||||
if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' ) {
|
||||
|
||||
if ( 'Y' !== get_option( 'mainwp_wp_staging_ext_enabled' ) ) {
|
||||
MainWP_Helper::update_option( 'mainwp_wp_staging_ext_enabled', 'Y', 'yes' );
|
||||
}
|
||||
|
||||
|
@ -149,14 +146,14 @@ class MainWP_Child_Staging {
|
|||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
function set_showhide() {
|
||||
public function set_showhide() {
|
||||
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
||||
MainWP_Helper::update_option( 'mainwp_wp_staging_hide_plugin', $hide, 'yes' );
|
||||
$information['result'] = 'SUCCESS';
|
||||
return $information;
|
||||
}
|
||||
|
||||
function save_settings() {
|
||||
public function save_settings() {
|
||||
$settings = $_POST['settings'];
|
||||
$filters = array(
|
||||
'queryLimit',
|
||||
|
@ -167,12 +164,10 @@ class MainWP_Child_Staging {
|
|||
'disableAdminLogin',
|
||||
'querySRLimit',
|
||||
'maxFileSize',
|
||||
// 'wpSubDirectory', // removed
|
||||
'debugMode',
|
||||
'unInstallOnDelete',
|
||||
'checkDirectorySize',
|
||||
'optimizer',
|
||||
// 'loginSlug' // removed
|
||||
);
|
||||
|
||||
$save_fields = array();
|
||||
|
@ -193,11 +188,9 @@ class MainWP_Child_Staging {
|
|||
}
|
||||
|
||||
public function get_scan() {
|
||||
// Scan
|
||||
$scan = new WPStaging\Backend\Modules\Jobs\Scan();
|
||||
$scan->start();
|
||||
|
||||
// Get Options
|
||||
$options = $scan->getOptions();
|
||||
|
||||
$return = array(
|
||||
|
@ -214,7 +207,6 @@ class MainWP_Child_Staging {
|
|||
$cloneNameLength = strlen( $cloneName );
|
||||
$clones = get_option( 'wpstg_existing_clones_beta', array() );
|
||||
|
||||
// Check clone name length
|
||||
if ( $cloneNameLength < 1 || $cloneNameLength > 16 ) {
|
||||
echo array(
|
||||
'status' => 'failed',
|
||||
|
@ -232,7 +224,7 @@ class MainWP_Child_Staging {
|
|||
|
||||
public function ajaxStartClone() {
|
||||
|
||||
$this->url = ''; // to fix warning
|
||||
$this->url = '';
|
||||
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
||||
|
||||
if ( ! $cloning->save() ) {
|
||||
|
@ -246,7 +238,6 @@ class MainWP_Child_Staging {
|
|||
}
|
||||
|
||||
public function ajaxCloneDatabase() {
|
||||
|
||||
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
||||
|
||||
return $cloning->start();
|
||||
|
@ -256,7 +247,6 @@ class MainWP_Child_Staging {
|
|||
* Ajax Prepare Directories (get listing of files)
|
||||
*/
|
||||
public function ajaxPrepareDirectories() {
|
||||
|
||||
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
||||
|
||||
return $cloning->start();
|
||||
|
@ -266,7 +256,6 @@ class MainWP_Child_Staging {
|
|||
* Ajax Clone Files
|
||||
*/
|
||||
public function ajaxCopyFiles() {
|
||||
|
||||
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
||||
|
||||
return $cloning->start();
|
||||
|
@ -284,9 +273,8 @@ class MainWP_Child_Staging {
|
|||
* Ajax Finish
|
||||
*/
|
||||
public function ajaxFinish() {
|
||||
|
||||
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
|
||||
$this->url = ''; // to fix warning
|
||||
$this->url = '';
|
||||
$return = $cloning->start();
|
||||
$return->blogInfoName = get_bloginfo( 'name' );
|
||||
|
||||
|
@ -297,7 +285,6 @@ class MainWP_Child_Staging {
|
|||
* Ajax Delete Confirmation
|
||||
*/
|
||||
public function ajaxDeleteConfirmation() {
|
||||
|
||||
$delete = new WPStaging\Backend\Modules\Jobs\Delete();
|
||||
$delete->setData();
|
||||
$clone = $delete->getClone();
|
||||
|
@ -305,6 +292,7 @@ class MainWP_Child_Staging {
|
|||
'clone' => $clone,
|
||||
'deleteTables' => $delete->getTables(),
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -312,8 +300,8 @@ class MainWP_Child_Staging {
|
|||
* Delete clone
|
||||
*/
|
||||
public function ajaxDeleteClone() {
|
||||
|
||||
$delete = new WPStaging\Backend\Modules\Jobs\Delete();
|
||||
|
||||
return $delete->start();
|
||||
}
|
||||
|
||||
|
@ -322,16 +310,17 @@ class MainWP_Child_Staging {
|
|||
*/
|
||||
public function ajaxCancelClone() {
|
||||
$cancel = new WPStaging\Backend\Modules\Jobs\Cancel();
|
||||
|
||||
return $cancel->start();
|
||||
}
|
||||
|
||||
public function ajaxCancelUpdate() {
|
||||
$cancel = new WPStaging\Backend\Modules\Jobs\CancelUpdate();
|
||||
|
||||
return $cancel->start();
|
||||
}
|
||||
|
||||
public function ajaxUpdateProcess() {
|
||||
|
||||
$cloning = new WPStaging\Backend\Modules\Jobs\Updating();
|
||||
|
||||
if ( ! $cloning->save() ) {
|
||||
|
@ -348,7 +337,6 @@ class MainWP_Child_Staging {
|
|||
return $this->hasFreeDiskSpace();
|
||||
}
|
||||
|
||||
// from wp-staging plugin
|
||||
public function hasFreeDiskSpace() {
|
||||
if ( ! function_exists( 'disk_free_space' ) ) {
|
||||
return null;
|
||||
|
@ -368,8 +356,7 @@ class MainWP_Child_Staging {
|
|||
return $data;
|
||||
}
|
||||
|
||||
// from wp-staging plugin
|
||||
function getDirectorySizeInclSubdirs( $dir ) {
|
||||
public function getDirectorySizeInclSubdirs( $dir ) {
|
||||
$size = 0;
|
||||
foreach ( glob( rtrim( $dir, '/' ) . '/*', GLOB_NOSORT ) as $each ) {
|
||||
$size += is_file( $each ) ? filesize( $each ) : $this->getDirectorySizeInclSubdirs( $each );
|
||||
|
@ -377,7 +364,6 @@ class MainWP_Child_Staging {
|
|||
return $size;
|
||||
}
|
||||
|
||||
// from wp-staging plugin
|
||||
public function formatSize( $bytes, $precision = 2 ) {
|
||||
if ( (float) $bytes < 1 ) {
|
||||
return '';
|
||||
|
@ -386,8 +372,8 @@ class MainWP_Child_Staging {
|
|||
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
|
||||
|
||||
$bytes = (float) $bytes;
|
||||
$base = log($bytes) / log(1000); // 1024 would be for MiB KiB etc
|
||||
$pow = pow(1000, $base - floor($base)); // Same rule for 1000
|
||||
$base = log( $bytes ) / log( 1000 );
|
||||
$pow = pow( 1000, $base - floor( $base ) );
|
||||
|
||||
return round( $pow, $precision ) . ' ' . $units[ (int) floor( $base ) ];
|
||||
}
|
||||
|
@ -413,12 +399,13 @@ class MainWP_Child_Staging {
|
|||
}
|
||||
}
|
||||
|
||||
function hide_update_notice( $slugs ) {
|
||||
public function hide_update_notice( $slugs ) {
|
||||
$slugs[] = 'wp-staging/wp-staging.php';
|
||||
|
||||
return $slugs;
|
||||
}
|
||||
|
||||
function remove_update_nag( $value ) {
|
||||
public function remove_update_nag( $value ) {
|
||||
if ( isset( $_POST['mainwpsignature'] ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
@ -438,4 +425,3 @@ class MainWP_Child_Staging {
|
|||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue