Merge pull request #161 from kwcjr/Documentation

Documentation
This commit is contained in:
Thang Hoang Van 2020-05-22 14:42:48 +07:00 committed by GitHub
commit f00d530065
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 346 additions and 181 deletions

11
.idea/mainwp-child.iml generated
View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/misc.xml generated
View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>

8
.idea/modules.xml generated
View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mainwp-child.iml" filepath="$PROJECT_DIR$/.idea/mainwp-child.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated
View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

90
.idea/workspace.xml generated
View file

@ -1,90 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BranchesTreeState">
<expand>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:upstream" type="e8cecc67:BranchNodeDescriptor" />
</path>
</expand>
<select />
</component>
<component name="ChangeListManager">
<list default="true" id="af1ea369-c116-42d4-a785-32f1af9168e6" name="Default Changelist" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ComposerSettings" synchronizationState="SYNCHRONIZE">
<pharConfigPath>$PROJECT_DIR$/composer.json</pharConfigPath>
<execution />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectId" id="1c9gwReF7cQZDLzR4KESkhLpKCq" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="af1ea369-c116-42d4-a785-32f1af9168e6" name="Default Changelist" comment="" />
<created>1589946461231</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1589946461231</updated>
<workItem from="1589946465949" duration="2317000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="2" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="WindowStateProjectService">
<state x="574" y="128" key="#com.intellij.ide.util.MemberChooser" timestamp="1590028259611">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="574" y="128" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1590028259611" />
<state x="501" y="135" key="NewPhpClassDialog" timestamp="1590028599218">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="501" y="135" key="NewPhpClassDialog/0.0.1536.824@0.0.1536.824" timestamp="1590028599218" />
</component>
</project>

View file

@ -1,28 +1,50 @@
<?php
/**
* MainWP Child Comments
*
* This file handles all Child Site comment actions.
*/
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;
/**
* @var string
*/
private $comments_and_clauses;
/**
* Method get_class_name()
*
* Get Class Name.
*
* @return object
* @return string
*/
public static function get_class_name() {
return __CLASS__;
}
/**
* 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() {
if ( null === self::$instance ) {
self::$instance = new self();
@ -30,6 +52,9 @@ class MainWP_Child_Comments {
return self::$instance;
}
/**
* MainWP Child Comment actions: approve, unapprove, spam, unspam, trash, restore, delete.
*/
public function comment_action() {
$action = $_POST['action'];
$commentId = $_POST['id'];
@ -59,6 +84,9 @@ 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() {
$action = $_POST['action'];
$commentIds = explode( ',', $_POST['ids'] );
@ -89,6 +117,12 @@ 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 ) {
if ( $this->comments_and_clauses ) {
$clauses['where'] .= ' ' . $this->comments_and_clauses;
@ -97,7 +131,14 @@ class MainWP_Child_Comments {
return $clauses;
}
/**
* Get all comments.
*
* @return array $rslt Array of comments.
*/
public function get_all_comments() {
/** @var global $wbdb wpdb. */
global $wpdb;
add_filter( 'comments_clauses', array( &$this, 'comments_clauses' ) );
@ -135,6 +176,13 @@ 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 ) {
if ( ! function_exists( 'get_comment_author_url' ) ) {
include_once WPINC . '/comment-template.php';

View file

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

View file

@ -11,16 +11,49 @@
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';
/**
* @static
* @var null Holds the Public static instance of MainWP_Child_Plugins_Check.
*/
public static $instance = null;
private $cron_name_watcher = 'mainwp_child_cron_plugin_health_check_watcher';
private $cron_name_daily = 'mainwp_child_cron_plugin_health_check_daily';
private $cron_name_batching = 'mainwp_child_cron_plugin_health_check_batching';
private $tran_name_plugin_timestamps = 'mainwp_child_tran_name_plugin_timestamps';
private $tran_name_plugins_to_batch = 'mainwp_child_tran_name_plugins_to_batch';
private $option_name_last_daily_run = 'mainwp_child_plugin_last_daily_run';
/**
* 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();
@ -29,6 +62,9 @@ class MainWP_Child_Plugins_Check {
return self::$instance;
}
/**
* MainWP_Child_Plugins_Check constructor.
*/
public function __construct() {
if ( get_option( 'mainwp_child_plugintheme_days_outdate' ) ) {
$this->schedule_watchdog();
@ -41,6 +77,13 @@ 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() {
wp_clear_scheduled_hook( $this->cron_name_daily );
wp_clear_scheduled_hook( $this->cron_name_batching );
@ -48,6 +91,14 @@ class MainWP_Child_Plugins_Check {
}
/**
* 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 );
@ -57,7 +108,13 @@ 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 ) {
if ( isset( $action ) && 'query_plugins' === $action ) {
@ -75,6 +132,11 @@ class MainWP_Child_Plugins_Check {
return $args;
}
/**
* 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 );
@ -98,13 +160,20 @@ 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 watching cron just in case both other crons get killed.
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() {
$plugins_outdate = get_transient( $this->tran_name_plugin_timestamps );
if ( ! is_array( $plugins_outdate ) ) {
@ -128,6 +197,9 @@ class MainWP_Child_Plugins_Check {
return $plugins_outdate;
}
/**
* 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 );
@ -140,6 +212,11 @@ class MainWP_Child_Plugins_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';
@ -174,6 +251,7 @@ class MainWP_Child_Plugins_Check {
}
$avoid_plugins = array( 'sitepress-multilingual-cms/sitepress.php' );
// Grab a small number of plugins to scan.
$plugins_to_scan = array_splice( $all_plugins, 0, apply_filters( 'mainwp_child_plugin_health_check_max_plugins_to_batch', 10 ) );
$tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
@ -229,10 +307,19 @@ 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 ) {
// Get the WordPress current version to be polite in the API call.
include ABSPATH . WPINC . '/version.php';
/** @var global $wp_version WordPress Version. */
global $wp_version;
// General options to be passed to wp_remote_get.

View file

@ -112,7 +112,6 @@ class MainWP_Child_Users {
MainWP_Helper::write( $information );
}
/**
* Get all users.
*
@ -150,7 +149,6 @@ class MainWP_Child_Users {
return $allusers;
}
/**
* Get all Child Site users.
*
@ -185,7 +183,6 @@ class MainWP_Child_Users {
MainWP_Helper::write( $allusers );
}
/**
* Search Child Site users.
*/
@ -251,7 +248,6 @@ class MainWP_Child_Users {
MainWP_Helper::write( $allusers );
}
/**
* Edit Child Site user.
*
@ -454,7 +450,6 @@ class MainWP_Child_Users {
return $edit_data;
}
/**
* New Child Site administrator password.
*
@ -526,5 +521,4 @@ class MainWP_Child_Users {
MainWP_Helper::write( $information );
}
}

View file

@ -1,5 +1,10 @@
<?php
/**
* MainWP Child
*
* This file handles all of the task that deal with the
* MainWP Child Plugin itself.
*/
namespace MainWP\Child;
// phpcs:disable
@ -19,14 +24,39 @@ if ( defined( 'MAINWP_CHILD_DEBUG' ) && MAINWP_CHILD_DEBUG === true ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
require_once ABSPATH . '/wp-admin/includes/plugin.php';
/**
* Class MainWP_Child
*
* @package MainWP\Child
*/
class MainWP_Child {
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 MainWP Child Plugin slug.
*/
public $plugin_slug;
/**
* @var string MainWP Child Plugin directory.
*/
private $plugin_dir;
/**
* MainWP_Child constructor.
*
* @param $plugin_file MainWP Child Plugin file.
*/
public function __construct( $plugin_file ) {
$this->update();
$this->load_all_options();
@ -69,7 +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() {
/** @var global $wbdb wpdb. */
global $wpdb;
if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
@ -143,6 +180,11 @@ class MainWP_Child {
}
/**
* Update MainWP Child Plugin.
*
* @return string Update verison.
*/
public function update() {
$update_version = get_option( 'mainwp_child_update_version' );
@ -153,14 +195,23 @@ class MainWP_Child {
MainWP_Helper::update_option( 'mainwp_child_update_version', $this->update_version, 'yes' );
}
/**
* 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() {
MainWP_Utility::instance()->maintenance_alert();
}
/**
*
*/
public function parse_init() {
if ( isset( $_REQUEST['cloneFunc'] ) ) {
@ -173,7 +224,9 @@ class MainWP_Child {
}
}
/** @var global $wp_rewrite Core class used to implement a rewrite component API. */
global $wp_rewrite;
$snPluginDir = basename( $this->plugin_dir );
if ( isset( $wp_rewrite->non_wp_rules[ 'wp-content/plugins/' . $snPluginDir . '/([^js\/]*)$' ] ) ) {
unset( $wp_rewrite->non_wp_rules[ 'wp-content/plugins/' . $snPluginDir . '/([^js\/]*)$' ] );
@ -233,16 +286,25 @@ class MainWP_Child {
MainWP_Keyword_Links::instance()->parse_init_keyword_links();
}
/**
* 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 ( MainWP_Helper::is_admin() && is_admin() ) {
MainWP_Clone::get()->init_ajax();
}
}
/**
* Parse MainWP Extension initiations.
*/
private function parse_init_extensions() {
// Handle fatal errors for those init if needed.
MainWP_Child_Branding::instance()->branding_init();
@ -261,9 +323,10 @@ class MainWP_Child {
\MainWP_Child_WPvivid_BackupRestore::instance()->init();
}
/*
* hook to deactivation child plugin action
/**
* Hook to deactivate MainWP Child Plugin.
*
* @param bool $deact Whether or not to deactivate pugin. Default: true.
*/
public function deactivation( $deact = true ) {
@ -295,8 +358,8 @@ class MainWP_Child {
}
}
/*
* hook to activation child plugin action
/**
* Hook to deactivate Child Plugin.
*/
public function activation() {
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );

View file

@ -1,19 +1,33 @@
<?php
/**
* MainWP Clone Installer.
*
* This file handles installing a cloned child site.
*/
namespace MainWP\Child;
// phpcs:disable WordPress.WP.AlternativeFunctions -- to custom functions.
/**
* Class MainWP_Clone_Install
*
* @package MainWP\Child
*/
class MainWP_Clone_Install {
/** @var string The zip backup file path. */
protected $file;
/** @var array Clone config settings. */
public $config;
/** @var $archiver Tar_Archiver */
protected $archiver;
/**
* Class constructor
* Class constructor.
*
* @param string $file The zip backup file path
* @param string $file The zip backup file path.
*/
public function __construct( $file ) {
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
@ -31,27 +45,37 @@ class MainWP_Clone_Install {
}
/**
* Check for default PHP zip support
* Check for default PHP zip support.
*
* @return bool
* @return bool true|false.
*/
public function check_zip_support() {
return class_exists( '\ZipArchive' );
}
/**
* Check if we could run zip on console
* Check if we could run zip on console.
*
* @return bool
* @return bool true|false.
*/
public function check_zip_console() {
return false;
}
/**
* 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() {
if ( ! $this->file || ! file_exists( $this->file ) ) {
return false;
@ -87,6 +111,11 @@ class MainWP_Clone_Install {
return false;
}
/**
* 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' ) );
@ -99,6 +128,12 @@ 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 ) {
if ( 'extracted' === $this->file ) {
return file_get_contents( '../clone/config.txt' );
@ -134,6 +169,11 @@ class MainWP_Clone_Install {
return false;
}
/**
* Read configuration file.
*
* @throws \Exception Error message on failure.
*/
public function read_configuration_file() {
$configContents = $this->get_config_contents();
if ( false === $configContents ) {
@ -153,6 +193,9 @@ class MainWP_Clone_Install {
}
}
/**
* Clean file structure after installation.
*/
public function clean() {
$files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' );
foreach ( $files as $file ) {
@ -180,6 +223,9 @@ class MainWP_Clone_Install {
}
}
/**
* 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 );
@ -189,7 +235,14 @@ 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 ) {
/** @var $wpdb wpdb */
global $wpdb;
@ -201,7 +254,14 @@ class MainWP_Clone_Install {
}
}
/**
* Database Installation.
*
* @return bool true|false.
* @throws \Exception Error message on failure.
*/
public function install() {
/** @var $wpdb wpdb */
global $wpdb;
@ -273,6 +333,11 @@ class MainWP_Clone_Install {
return true;
}
/**
* Get config contents.
*
* @return bool|false|mixed|string
*/
public function get_config_contents() {
if ( 'extracted' === $this->file ) {
return file_get_contents( '../clone/config.txt' );
@ -319,9 +384,10 @@ class MainWP_Clone_Install {
}
/**
* Extract backup
* Extract backup file.
*
* @return bool
* @return bool|null true or null.
* @throws \Exception Error message on failure.
*/
public function extract_backup() {
if ( ! $this->file || ! file_exists( $this->file ) ) {
@ -347,9 +413,9 @@ class MainWP_Clone_Install {
}
/**
* Extract backup using default PHP zip library
* Extract backup using default PHP zip library.
*
* @return bool
* @return bool true|false.
*/
public function extract_zip_backup() {
$zip = new \ZipArchive();
@ -364,6 +430,11 @@ class MainWP_Clone_Install {
return false;
}
/**
* Extract with unzip_file.
*
* @return bool true|false.
*/
public function extract_wp_zip_backup() {
MainWP_Helper::get_wp_filesystem();
global $wp_filesystem;
@ -380,6 +451,12 @@ class MainWP_Clone_Install {
return true;
}
/**
* 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 ) ) {
@ -393,40 +470,46 @@ class MainWP_Clone_Install {
}
/**
* Extract backup using zip on console
* Extract backup using zip on console.
*
* @return bool
* @return bool true|false.
*/
public function extract_zip_console_backup() {
return false;
}
/**
* Replace define statement to work with wp-config.php
* Replace define statement to work with wp-config.php.
*
* @param string $constant The constant name
* @param string $value The new value
* @param string $content The PHP file content
* @param string $constant The constant name.
* @param string $value The new value.
* @param string $content The PHP file content.
*
* @return string Replaced define statement with new value
* @return string Replaced define statement with new value.
*/
protected function replace_define( $constant, $value, $content ) {
return preg_replace( '/(define *\( *[\'"]' . $constant . '[\'"] *, *[\'"])(.*?)([\'"] *\))/is', '${1}' . $value . '${3}', $content );
}
/**
* Replace variable value to work with wp-config.php
* Replace variable value to work with wp-config.php.
*
* @param string $varname The variable name
* @param string $value The new value
* @param string $content The PHP file content
* @param string $varname The variable name.
* @param string $value The new value.
* @param string $content The PHP file content.
*
* @return string Replaced variable value with new value
* @return string Replaced variable value with new value.
*/
protected function replace_var( $varname, $value, $content ) {
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 ) {
$d = opendir( $mypath );
while ( ( $file = readdir( $d ) ) !== false ) {
@ -440,20 +523,19 @@ class MainWP_Clone_Install {
}
}
/**
* The main loop triggered in step 5. Up here to keep it out of the way of the
* HTML. This walks every table in the db that was selected in step 3 and then
* walks every row and column replacing all occurences of a string with another.
* walks every row and column replacing all occurrences of a string with another.
* We split large tables into 50,000 row blocks when dealing with them to save
* on memmory consumption.
* on memory consumption.
*
* @param mysql $connection The db connection object
* @param string $search What we want to replace
* @param mysql $connection The db connection object.
* @param string $search What we want to replace.
* @param string $replace What we want to replace it with.
* @param array $tables The tables we want to look at.
*
* @return array Collection of information gathered during the run.
* @return array Collection of information gathered during the run.
*/
public function icit_srdb_replacer( $connection, $search = '', $replace = '', $tables = array() ) {
global $guid, $exclude_cols;
@ -550,15 +632,15 @@ class MainWP_Clone_Install {
}
/**
* Take a serialised array and unserialise it replacing elements as needed and
* unserialising any subordinate arrays and performing the replace on those too.
* Take a serialised array and un-serialize it replacing elements as needed and
* un-serializing any subordinate arrays and performing the replace on those too.
*
* @param string $from String we're looking to replace.
* @param string $to What we want it to be replaced with
* @param array $data Used to pass any subordinate arrays back to in.
* @param string $to What we want it to be replaced with.
* @param array $data Used to pass any subordinate arrays back.
* @param bool $serialised Does the array passed via $data need serialising.
*
* @return array The original array with all elements replaced as needed.
* @return array The original array with all elements replaced as needed.
*/
public function recursive_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) {
@ -605,6 +687,11 @@ class MainWP_Clone_Install {
return $data;
}
/**
* Request clone.
*
* @return bool|void true|void.
*/
public function request_clone_funct() {
if ( ! isset( $_REQUEST['key'] ) ) {
@ -652,6 +739,9 @@ class MainWP_Clone_Install {
return true;
}
/**
* Create backup of clone.
*/
private function create_clone_backup() {
MainWP_Helper::end_session();
$files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' );