Use PHP 7.4 featers and PHP 8 polyfills
This commit is contained in:
@ -15,7 +15,7 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
* @param int $from_site_id duplicated site id
|
||||
* @param int $to_site_id new site id
|
||||
*/
|
||||
public static function copy_data($from_site_id, $to_site_id) {
|
||||
public static function copy_data($from_site_id, $to_site_id): void {
|
||||
self::$to_site_id = $to_site_id;
|
||||
|
||||
// Copy
|
||||
@ -25,16 +25,16 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
self::db_update_data($from_site_id, $to_site_id, $saved_options);
|
||||
}
|
||||
|
||||
public static function db_copy_blog_meta($from_site_id, $to_site_id) {
|
||||
public static function db_copy_blog_meta($from_site_id, $to_site_id): void {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
// Delete everything
|
||||
$wpdb->delete(
|
||||
_get_meta_table('blog'),
|
||||
array(
|
||||
[
|
||||
'blog_id' => $to_site_id,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$meta = get_site_meta($from_site_id);
|
||||
@ -96,12 +96,12 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
|
||||
// die;
|
||||
|
||||
$tables_to_ignore = array(
|
||||
$tables_to_ignore = [
|
||||
'actionscheduler_actions',
|
||||
'actionscheduler_claims',
|
||||
'actionscheduler_groups',
|
||||
'actionscheduler_logs',
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($from_site_table as $table) {
|
||||
$table_base_name = substr((string) $table, $from_site_prefix_length);
|
||||
@ -169,7 +169,7 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
* @param int $from_site_id duplicated site id
|
||||
* @param int $to_site_id new site id
|
||||
*/
|
||||
public static function db_update_data($from_site_id, $to_site_id, $saved_options) {
|
||||
public static function db_update_data($from_site_id, $to_site_id, $saved_options): void {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
@ -192,7 +192,7 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
|
||||
restore_current_blog();
|
||||
|
||||
$tables = array();
|
||||
$tables = [];
|
||||
|
||||
// Bugfix : escape '_' , '%' and '/' character for mysql 'like' queries
|
||||
$to_blog_prefix_like = $wpdb->esc_like($to_blog_prefix);
|
||||
@ -200,13 +200,13 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
$results = self::do_sql_query('SHOW TABLES LIKE \'' . $to_blog_prefix_like . '%\'', 'col', false);
|
||||
|
||||
foreach ( $results as $k => $v ) {
|
||||
$tables[ str_replace($to_blog_prefix, '', (string) $v) ] = array();
|
||||
$tables[ str_replace($to_blog_prefix, '', (string) $v) ] = [];
|
||||
}
|
||||
|
||||
foreach ( $tables as $table => $col) {
|
||||
$results = self::do_sql_query('SHOW COLUMNS FROM `' . $to_blog_prefix . $table . '`', 'col', false);
|
||||
|
||||
$columns = array();
|
||||
$columns = [];
|
||||
|
||||
foreach ( $results as $k => $v ) {
|
||||
$columns[] = $v;
|
||||
@ -224,11 +224,11 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
$from_site_prefix = $wpdb->get_blog_prefix($from_site_id);
|
||||
$to_site_prefix = $wpdb->get_blog_prefix($to_site_id);
|
||||
|
||||
$string_to_replace = array(
|
||||
$string_to_replace = [
|
||||
wu_replace_scheme($from_upload_url) => wu_replace_scheme($to_upload_url),
|
||||
wu_replace_scheme($from_blog_url) => wu_replace_scheme($to_blog_url),
|
||||
$from_site_prefix => $to_site_prefix,
|
||||
);
|
||||
];
|
||||
|
||||
$string_to_replace = apply_filters('mucd_string_to_replace', $string_to_replace, $from_site_id, $to_site_id);
|
||||
|
||||
@ -248,7 +248,7 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
* @param int $from_site_id duplicated site id
|
||||
* @param int $to_site_id new site id
|
||||
*/
|
||||
public static function db_restore_data($to_site_id, $saved_options) {
|
||||
public static function db_restore_data($to_site_id, $saved_options): void {
|
||||
|
||||
switch_to_blog($to_site_id);
|
||||
|
||||
@ -272,7 +272,7 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
* @param string $from_string original string to replace
|
||||
* @param string $to_string new string
|
||||
*/
|
||||
public static function update($table, $fields, $from_string, $to_string) {
|
||||
public static function update($table, $fields, $from_string, $to_string): void {
|
||||
if (is_array($fields) || ! empty($fields)) {
|
||||
global $wpdb;
|
||||
|
||||
@ -336,7 +336,7 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
* @return string the new string
|
||||
*/
|
||||
public static function replace_recursive($val, $from_string, $to_string) {
|
||||
$unset = array();
|
||||
$unset = [];
|
||||
if (is_array($val)) {
|
||||
foreach ($val as $k => $v) {
|
||||
$val[ $k ] = self::try_replace($val, $k, $from_string, $to_string);
|
||||
@ -457,7 +457,7 @@ if ( ! class_exists('MUCD_Data') ) {
|
||||
* @param string $sql_query the query
|
||||
* @param string $sql_error the error
|
||||
*/
|
||||
public static function sql_error($sql_query, $sql_error) {
|
||||
public static function sql_error($sql_query, $sql_error): void {
|
||||
wu_log_add('site-duplication-errors', sprintf('Got error "%s" while running: %s', $sql_error, $sql_query), LogLevel::ERROR);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ if ( ! class_exists('MUCD_Duplicate') ) {
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
public static function init() {
|
||||
public static function init(): void {
|
||||
self::$log = false;
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ if ( ! class_exists('MUCD_Duplicate') ) {
|
||||
public static function duplicate_site($data) {
|
||||
|
||||
global $wpdb;
|
||||
$form_message = array();
|
||||
$form_message = [];
|
||||
$wpdb->hide_errors();
|
||||
|
||||
self::init_log($data);
|
||||
@ -61,7 +61,7 @@ if ( ! class_exists('MUCD_Duplicate') ) {
|
||||
|
||||
// Create new site
|
||||
switch_to_blog(1);
|
||||
$to_site_id = wpmu_create_blog($newdomain, $path, $title, $user_id, array('public' => $public), $network_id);
|
||||
$to_site_id = wpmu_create_blog($newdomain, $path, $title, $user_id, ['public' => $public], $network_id);
|
||||
$wpdb->show_errors();
|
||||
|
||||
if ( is_wp_error($to_site_id) ) {
|
||||
@ -140,7 +140,7 @@ if ( ! class_exists('MUCD_Duplicate') ) {
|
||||
* @param int $from_site_id duplicated site id
|
||||
* @param int $to_site_id new site id
|
||||
*/
|
||||
public static function copy_users($from_site_id, $to_site_id) {
|
||||
public static function copy_users($from_site_id, $to_site_id): void {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
@ -151,7 +151,7 @@ if ( ! class_exists('MUCD_Duplicate') ) {
|
||||
|
||||
if (is_main_site($from_site_id)) {
|
||||
$is_from_main_site = true;
|
||||
$args = array('fields' => 'ids');
|
||||
$args = ['fields' => 'ids'];
|
||||
$all_sites_ids = MUCD_Functions::get_sites($args);
|
||||
if ( ! empty($all_sites_ids)) {
|
||||
$all_sites_ids = array_map('user_array_map', $all_sites_ids);
|
||||
@ -205,12 +205,12 @@ if ( ! class_exists('MUCD_Duplicate') ) {
|
||||
* @since 0.2.0
|
||||
* @param array $data data from FORM
|
||||
*/
|
||||
public static function init_log($data) {
|
||||
public static function init_log($data): void {
|
||||
// INIT LOG AND SAVE OPTION
|
||||
if (isset($data['log']) && $data['log'] == 'yes' ) {
|
||||
if (isset($data['log-path']) && ! empty($data['log-path'])) {
|
||||
$log_name = @date('Y_m_d_His') . '-' . $data['domain'] . '.log';
|
||||
if (substr_compare((string) $data['log-path'], '/', -strlen('/')) !== 0) {
|
||||
if (! str_ends_with((string) $data['log-path'], '/')) {
|
||||
$data['log-path'] = $data['log-path'] . '/';
|
||||
}
|
||||
self::$log = new MUCD_Log(true, $data['log-path'], $log_name);
|
||||
@ -246,7 +246,7 @@ if ( ! class_exists('MUCD_Duplicate') ) {
|
||||
* @since 0.2.0
|
||||
* @param string $msg the message
|
||||
*/
|
||||
public static function write_log($msg) {
|
||||
public static function write_log($msg): void {
|
||||
if (self::log() !== false) {
|
||||
self::$log->write_log($msg);
|
||||
}
|
||||
@ -257,7 +257,7 @@ if ( ! class_exists('MUCD_Duplicate') ) {
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
public static function close_log() {
|
||||
public static function close_log(): void {
|
||||
if (self::log() !== false) {
|
||||
self::$log->close_log();
|
||||
}
|
||||
@ -291,7 +291,7 @@ if ( ! class_exists('MUCD_Duplicate') ) {
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
public static function bypass_server_limit() {
|
||||
public static function bypass_server_limit(): void {
|
||||
@ini_set('memory_limit', '1024M');
|
||||
@ini_set('max_execution_time', '0');
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ if ( ! class_exists('MUCD_Files') ) {
|
||||
switch_to_blog($from_site_id);
|
||||
$wp_upload_info = wp_upload_dir();
|
||||
$from_dir['path'] = $wp_upload_info['basedir'];
|
||||
$from_site_id == MUCD_PRIMARY_SITE_ID ? $from_dir['exclude'] = MUCD_Option::get_primary_dir_exclude() : $from_dir['exclude'] = array();
|
||||
$from_site_id == MUCD_PRIMARY_SITE_ID ? $from_dir['exclude'] = MUCD_Option::get_primary_dir_exclude() : $from_dir['exclude'] = [];
|
||||
|
||||
// Switch to Destination site and get uploads info
|
||||
switch_to_blog($to_site_id);
|
||||
@ -25,12 +25,12 @@ if ( ! class_exists('MUCD_Files') ) {
|
||||
|
||||
restore_current_blog();
|
||||
|
||||
$dirs = array();
|
||||
$dirs[] = array(
|
||||
$dirs = [];
|
||||
$dirs[] = [
|
||||
'from_dir_path' => $from_dir['path'],
|
||||
'to_dir_path' => $to_dir,
|
||||
'exclude_dirs' => $from_dir['exclude'],
|
||||
);
|
||||
];
|
||||
|
||||
$dirs = apply_filters('mucd_copy_dirs', $dirs, $from_site_id, $to_site_id);
|
||||
|
||||
@ -53,7 +53,7 @@ if ( ! class_exists('MUCD_Files') ) {
|
||||
* @param string $dst destination directory path
|
||||
* @param array $exclude_dirs directories to ignore
|
||||
*/
|
||||
public static function recurse_copy($src, $dst, $exclude_dirs = array()) {
|
||||
public static function recurse_copy($src, $dst, $exclude_dirs = []): void {
|
||||
$src = rtrim($src, '/');
|
||||
$dst = rtrim($dst, '/');
|
||||
$dir = opendir($src);
|
||||
@ -102,7 +102,7 @@ if ( ! class_exists('MUCD_Files') ) {
|
||||
* @since 0.2.0
|
||||
* @param string $dir the path
|
||||
*/
|
||||
public static function rrmdir($dir) {
|
||||
public static function rrmdir($dir): void {
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir);
|
||||
foreach ($objects as $object) {
|
||||
@ -125,7 +125,7 @@ if ( ! class_exists('MUCD_Files') ) {
|
||||
* @since 0.2.0
|
||||
* @param string $dir_path the path
|
||||
*/
|
||||
public static function mkdir_error($dir_path) {
|
||||
public static function mkdir_error($dir_path): void {
|
||||
$error_1 = 'ERROR DURING FILE COPY : CANNOT CREATE ' . $dir_path;
|
||||
MUCD_Duplicate::write_log($error_1);
|
||||
$error_2 = sprintf(MUCD_NETWORK_PAGE_DUPLICATE_COPY_FILE_ERROR, MUCD_Functions::get_primary_upload_dir());
|
||||
|
@ -50,7 +50,7 @@ if ( ! class_exists('MUCD_Functions') ) {
|
||||
* @since 0.2.0
|
||||
* @param int $blog_id the blog id
|
||||
*/
|
||||
public static function remove_blog($blog_id) {
|
||||
public static function remove_blog($blog_id): void {
|
||||
switch_to_blog($blog_id);
|
||||
$wp_upload_info = wp_upload_dir();
|
||||
$dir = str_replace(' ', '\\ ', trailingslashit($wp_upload_info['basedir']));
|
||||
@ -87,8 +87,8 @@ if ( ! class_exists('MUCD_Functions') ) {
|
||||
* @return array of blog data
|
||||
*/
|
||||
public static function get_site_list() {
|
||||
$site_list = array();
|
||||
$network_blogs = self::get_sites(apply_filters('mucd_get_site_list_args', array()));
|
||||
$site_list = [];
|
||||
$network_blogs = self::get_sites(apply_filters('mucd_get_site_list_args', []));
|
||||
foreach ( $network_blogs as $blog ) {
|
||||
if (self::is_duplicable($blog['blog_id']) && MUCD_SITE_DUPLICATION_EXCLUDE != $blog['blog_id']) {
|
||||
$site_list[] = $blog;
|
||||
@ -147,7 +147,7 @@ if ( ! class_exists('MUCD_Functions') ) {
|
||||
*
|
||||
* @since 1.3.1
|
||||
*/
|
||||
public static function set_locale_to_en_US() {
|
||||
public static function set_locale_to_en_US(): void {
|
||||
|
||||
// Bugfix Pierre Dargham : relocating this declaration outside of the call to add_filter
|
||||
// PHP < 5.3 does not accept anonymous functions
|
||||
@ -185,9 +185,9 @@ if ( ! class_exists('MUCD_Functions') ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function get_sites($args = array()) {
|
||||
public static function get_sites($args = []) {
|
||||
if (version_compare(get_bloginfo('version'), '4.6', '>=')) {
|
||||
$defaults = array('number' => MUCD_MAX_NUMBER_OF_SITE);
|
||||
$defaults = ['number' => MUCD_MAX_NUMBER_OF_SITE];
|
||||
$args = wp_parse_args($args, $defaults);
|
||||
$args = apply_filters('mucd_get_sites_args', $args);
|
||||
$sites = get_sites($args);
|
||||
@ -196,7 +196,7 @@ if ( ! class_exists('MUCD_Functions') ) {
|
||||
}
|
||||
return $sites;
|
||||
} else {
|
||||
$defaults = array('limit' => MUCD_MAX_NUMBER_OF_SITE);
|
||||
$defaults = ['limit' => MUCD_MAX_NUMBER_OF_SITE];
|
||||
$args = apply_filters('mucd_get_sites_args', $args);
|
||||
$args = wp_parse_args($args, $defaults);
|
||||
return wp_get_sites($args);
|
||||
@ -208,7 +208,7 @@ if ( ! class_exists('MUCD_Functions') ) {
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
public static function check_if_multisite() {
|
||||
public static function check_if_multisite(): void {
|
||||
if ( ! function_exists('is_multisite') || ! is_multisite()) {
|
||||
deactivate_plugins(plugin_basename(__FILE__));
|
||||
wp_die('multisite-clone-duplicator works only for multisite installation');
|
||||
@ -220,7 +220,7 @@ if ( ! class_exists('MUCD_Functions') ) {
|
||||
*
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public static function check_if_network_admin() {
|
||||
public static function check_if_network_admin(): void {
|
||||
if ( ! is_network_admin() ) {
|
||||
deactivate_plugins(plugin_basename(__FILE__));
|
||||
wp_die('multisite-clone-duplicator works only as multisite network-wide plugin');
|
||||
|
@ -146,7 +146,7 @@ if ( ! class_exists('MUCD_Log') ) {
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
public function close_log() {
|
||||
public function close_log(): void {
|
||||
@fclose($this->fp);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
* @param string $network_value the value for site option
|
||||
* @since 0.2.0
|
||||
*/
|
||||
public static function init_duplicable_option($blogs_value = 'no', $network_value = 'all') {
|
||||
public static function init_duplicable_option($blogs_value = 'no', $network_value = 'all'): void {
|
||||
$network_blogs = MUCD_Functions::get_sites();
|
||||
foreach ( $network_blogs as $blog ) {
|
||||
$blog_id = $blog['blog_id'];
|
||||
@ -28,7 +28,7 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
public static function delete_duplicable_option() {
|
||||
public static function delete_duplicable_option(): void {
|
||||
$network_blogs = MUCD_Functions::get_sites();
|
||||
foreach ( $network_blogs as $blog ) {
|
||||
$blog_id = $blog['blog_id'];
|
||||
@ -44,7 +44,7 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
* @since 0.2.0
|
||||
* @param array $blogs list of blogs we want the option set to "yes"
|
||||
*/
|
||||
public static function set_duplicable_option($blogs) {
|
||||
public static function set_duplicable_option($blogs): void {
|
||||
$network_blogs = MUCD_Functions::get_sites();
|
||||
foreach ( $network_blogs as $blog ) {
|
||||
if (in_array($blog['blog_id'], $blogs)) {
|
||||
@ -61,7 +61,7 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public static function init_options() {
|
||||
public static function init_options(): void {
|
||||
add_site_option('mucd_copy_files', 'yes');
|
||||
add_site_option('mucd_keep_users', 'yes');
|
||||
add_site_option('mucd_log', 'no');
|
||||
@ -77,7 +77,7 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public static function delete_options() {
|
||||
public static function delete_options(): void {
|
||||
delete_site_option('mucd_copy_files');
|
||||
delete_site_option('mucd_keep_users');
|
||||
delete_site_option('mucd_log');
|
||||
@ -106,9 +106,9 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
* @return array of string
|
||||
*/
|
||||
public static function get_primary_dir_exclude() {
|
||||
return array(
|
||||
return [
|
||||
'sites',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -119,7 +119,7 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
* @return array of string
|
||||
*/
|
||||
public static function get_default_saved_option() {
|
||||
return array(
|
||||
return [
|
||||
'siteurl' => '',
|
||||
'home' => '',
|
||||
'upload_path' => '',
|
||||
@ -132,7 +132,7 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
'schema-ActionScheduler_StoreSchema' => '',
|
||||
'schema-ActionScheduler_LoggerSchema' => '',
|
||||
'action_scheduler_lock_async-request-runner' => '',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -154,17 +154,17 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
* @return array '%table_name' => array('%field_name_1','%field_name_2','%field_name_3', ...)
|
||||
*/
|
||||
public static function get_default_fields_to_update() {
|
||||
return array(
|
||||
'commentmeta' => array(),
|
||||
'comments' => array(),
|
||||
'links' => array('link_url', 'link_image'),
|
||||
'options' => array('option_name', 'option_value'),
|
||||
'postmeta' => array('meta_value'),
|
||||
'posts' => array('post_content', 'guid', 'post_title', 'post_name'),
|
||||
'terms' => array(),
|
||||
'term_relationships' => array(),
|
||||
'term_taxonomy' => array(),
|
||||
);
|
||||
return [
|
||||
'commentmeta' => [],
|
||||
'comments' => [],
|
||||
'links' => ['link_url', 'link_image'],
|
||||
'options' => ['option_name', 'option_value'],
|
||||
'postmeta' => ['meta_value'],
|
||||
'posts' => ['post_content', 'guid', 'post_title', 'post_name'],
|
||||
'terms' => [],
|
||||
'term_relationships' => [],
|
||||
'term_taxonomy' => [],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -186,7 +186,7 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
* @return array of string
|
||||
*/
|
||||
public static function get_default_primary_tables_to_copy() {
|
||||
return array(
|
||||
return [
|
||||
'commentmeta',
|
||||
'comments',
|
||||
'links',
|
||||
@ -197,7 +197,7 @@ if ( ! class_exists('MUCD_Option') ) {
|
||||
'term_relationships',
|
||||
'term_taxonomy',
|
||||
'termmeta',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user