From dace311d45736f1ae4c7318122433fd44077054c Mon Sep 17 00:00:00 2001
From: Justin Grubbs
Date: Fri, 2 Feb 2024 13:25:26 -0500
Subject: [PATCH 1/4] fix PHP 8.2 deprecations
---
inc/mpd-functions.php | 188 +++++++++++++++++++++---------------------
1 file changed, 94 insertions(+), 94 deletions(-)
diff --git a/inc/mpd-functions.php b/inc/mpd-functions.php
index 8b4b138..7de314a 100644
--- a/inc/mpd-functions.php
+++ b/inc/mpd-functions.php
@@ -29,7 +29,7 @@ function mpd_get_post_types_to_ignore(){
'revision',
'nav_menu_item',
//'attachment',
-
+
)
);
@@ -53,7 +53,7 @@ function mpd_information_icon($c){
$u = uniqid(); ?>
slug] = (object) $new_term;
do_action( 'mpd_after_insert_term', $new_term, $post_term, $source_blog_id );
-
+
return $new_term['term_id'];
}
}
/**
- *
+ *
* This function performs the action of setting the taxonomies of the source post and
* to the destination post.
* Works with mpd_get_post_taxonomy_terms();
@@ -1215,7 +1215,7 @@ function mpd_add_term_recursively( $post_term, &$orig_all_terms_by_id, &$all_ter
* @since 0.9
* @param $post_id The ID of the newly created post
* @param $source_taxonomy_terms_object An array of term objects used in the source post
- *
+ *
* @return array An array of term objects used in the post
*
*/
@@ -1254,49 +1254,49 @@ function mpd_set_post_taxonomy_terms( $post_id, $source_taxonomy_terms_object, $
}
/**
- *
+ *
* This function filters out post meta keys from the post meta as requested in the 'keys to ignore' mpd settings page.
*
* @since 0.9
* @param $post_meta_array The source post post_meta
- *
+ *
* @return array A filtered array without the keys as specified in 'keys to ignore' in mpd settings
*
*/
function mpd_ignore_custom_meta_keys($post_meta_array){
-
+
$options = get_option( 'mdp_settings' );
-
+
$meta_to_ignore_raw = str_replace(' ', '', $options['mdp_ignore_custom_meta']);
$meta_to_ignore = explode(',', $meta_to_ignore_raw);
$new_post_meta = array();
-
+
foreach($post_meta_array as $meta_key => $meta_value){
-
+
if(!in_array($meta_key, $meta_to_ignore)){
$new_post_meta[$meta_key] = $meta_value;
-
+
}
-
+
}
-
+
return $new_post_meta;
-
+
}
add_filter('mpd_filter_post_meta', 'mpd_ignore_custom_meta_keys');
add_filter('mpd_filter_persist_post_meta', 'mpd_ignore_custom_meta_keys');
/**
- *
+ *
* This function gets An 'edit url' for a post.
*
* @since 1.0
* @param $blog_id The blog_id where the post is
* @param $post_id The post_id you want to link to
- *
+ *
* @return string An edit url for a post
*
*/
@@ -1316,13 +1316,13 @@ function mpd_get_version(){
}
/**
- *
+ *
* If the user chooses to, this function will collect the post date to of the source post to be used later
* in mpd_set_published_date() to assign the published date to be the same as the destination.
*
* @since 0.9.4
* @param $mpd_process_info Array of the source post information
- *
+ *
* @return array A filtered array of source post information
*
*/
@@ -1333,7 +1333,7 @@ function mpd_get_published_date($mpd_process_info){
if(isset($options['mdp_retain_published_date'])){
$mpd_process_info['post_date'] = get_post_field('post_date', $mpd_process_info['source_post_id']);
}
-
+
return $mpd_process_info;
}
@@ -1341,13 +1341,13 @@ function mpd_get_published_date($mpd_process_info){
add_filter('mpd_source_data', 'mpd_get_published_date');
/**
- *
+ *
* If the user chooses to, this function will set the post date to of the source post to the destination post. Note we have to set the post_status to publish for this activity as no published date would be assigned otherwise.
*
* @since 0.9.4
* @param $mdp_post Array of the destination post info prior to post being created in database
* @param $mpd_process_info Array of the source post information
- *
+ *
* @return array A filtered array of destination post information prior to post being saved in database
*
*/
@@ -1361,7 +1361,7 @@ function mpd_set_published_date($mdp_post, $mpd_process_info){
$mdp_post['post_status'] = 'publish';
}
-
+
return $mdp_post;
}
@@ -1387,14 +1387,14 @@ function mpd_update_published_date($mpd_post, $persist_post) {
}
return $mpd_post;
-
+
}
add_filter('mpd_setup_persist_destination_data', 'mpd_update_published_date', 10, 2);
/**
- *
+ *
* Do the markup for a link to MDP setting page
*
* @since 1.0
@@ -1407,7 +1407,7 @@ function mpd_do_settings_link(){
Settings
-
+
base_prefix . $siteid . $table;
return $tablename;
}
/**
- *
+ *
* UI Function which provides a button to select all checkboxes in the MPD post metabox
*
* @since 1.5
- *
+ *
* @return null
*
*/
function mpd_select_all_checkboxes(){
if(apply_filters('mpd_show_select_all_checkboxes', true)) :?>
-
+
'){
+
+ if(jQuery(this).html() == ''){
jQuery('#mpd_blogschecklist input:checkbox:not(.mpd-current-site)').prop('checked', 'checked');
jQuery(this).html('');
}else{
jQuery(this).html('');
jQuery('#mpd_blogschecklist input:checkbox').removeProp('checked');
}
-
- jQuery('#mpd_blogschecklist .mpd-site-checkbox input').trigger('change');
+
+ jQuery('#mpd_blogschecklist .mpd-site-checkbox input').trigger('change');
});
});
- get_current_blog_id(),
@@ -1619,7 +1619,7 @@ function mpd_process_persist( $post_id, $destination_id, $created_post = false){
'destination_post_id' => $created_post['id']
);
-
+
mpd_add_persist($args);
}
@@ -1630,9 +1630,9 @@ function mpd_process_persist( $post_id, $destination_id, $created_post = false){
function mpd_skip_standard_duplication($choice){
if(get_option('skip_standard_dup')){
-
+
delete_option('skip_standard_dup' );
-
+
return $choice = false;
}
@@ -1644,7 +1644,7 @@ function mpd_skip_standard_duplication($choice){
add_filter('mpd_do_single_metabox_duplication', 'mpd_skip_standard_duplication', 20); //Note priority higher than mpd_copy_acf_field_group()
/**
- *
+ *
* Hooks into mpd_enter_the_loop funciton and set the conditions in which the multisite
* post duplication processes can be accessed
*
@@ -1652,13 +1652,13 @@ function mpd_skip_standard_duplication($choice){
* @param boolean $choice The initial state if we are allowed into the loop
* @param array $post_global the global post object on the form submit
* @param int $post_id the ID of the post being saved
- *
+ *
* @return boolean The desision to continue or not
*
*/
function mpd_enter_the_loop($choice, $post_global, $post_id){
- if(( isset($post_global["post_status"] ) )
+ if(( isset($post_global["post_status"] ) )
&& ( $post_global["post_status"] != "auto-draft" )
&& ( isset($post_global['mpd_blogs'] ) )
&& ( count( $post_global['mpd_blogs'] ) )
@@ -1673,13 +1673,13 @@ function mpd_enter_the_loop($choice, $post_global, $post_id){
add_filter('mpd_enter_the_loop', 'mpd_enter_the_loop', 10, 3);
/**
- *
+ *
* Get media URL on any sub site by ID
*
* @since 1.6.5
* @param int $ID The ID of the media we want the URL of
* @param int $source_blog The blog id this media file resides.
- *
+ *
* @return string The URL of the media file
*
*/
@@ -1694,14 +1694,14 @@ function mpd_wp_get_attachment_url($ID, $source_blog){
}
/**
- *
+ *
* Log the duplication of a media file by creating two meta files
*
* @since 1.6.6
* @param int $attach_id The ID of the media we want to log
* @param int $source_id The blog id this media file resides.
* @param int $source_attachment_id The original ID of the image on the source site
- *
+ *
* @return null
*
*/
@@ -1720,7 +1720,7 @@ function mpd_log_media_file($attach_id, $source_id, $source_attachment_id){
add_action('mpd_media_image_added', 'mpd_log_media_file', 10, 3);
/**
- *
+ *
* Check if a copy of a media file exists on another blog
* Uses the logging structure as set in mpd_log_media_file();
*
@@ -1728,7 +1728,7 @@ function mpd_log_media_file($attach_id, $source_id, $source_attachment_id){
* @param int $source_file_id The ID of the media we want to check
* @param int $source_id The blog id this media file resides.
* @param int $destination_id The blog id to check if there is a copy on
- *
+ *
* @return booleon True if it does exist and false if it doesn't
*
*/
@@ -1773,9 +1773,9 @@ function mpd_does_file_exist($source_file_id, $source_id, $destination_id){
}else{
return false;
- }
+ }
}
-
+
}
return false;
@@ -1809,4 +1809,4 @@ function mpd_process_meta( $post_id, $meta_values ) {
}
}
}
-}
\ No newline at end of file
+}
From 0e2e0d7876bc397163202ca2ec2410480e1c6e69 Mon Sep 17 00:00:00 2001
From: Justin Grubbs
Date: Fri, 2 Feb 2024 14:15:00 -0500
Subject: [PATCH 2/4] add composer.json for package management
---
composer.json | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 composer.json
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..d0b96e4
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,18 @@
+{
+ "name": "wpackagist-plugin/multisite-post-duplicator",
+ "authors": [
+ {
+ "name": "King & Partners",
+ "email": "technology@kingandpartners.com"
+ }
+ ],
+ "require": {
+ "composer/installers": "~1.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^5.6",
+ "brain/monkey": "1.*",
+ "squizlabs/php_codesniffer": "~2.0"
+ },
+ "type": "wordpress-plugin"
+}
From 2b79e8d3d2c8b813a324cf1ffc3ea780f99c64e9 Mon Sep 17 00:00:00 2001
From: Justin Grubbs
Date: Tue, 29 Oct 2024 14:28:56 -0400
Subject: [PATCH 3/4] Return if html is empty
Fixes:
PHP Fatal error: Uncaught ValueError: DOMDocument::loadHTML(): Argument #1 ($source) must not be empty in /var/app/current/wordpress/web/app/mu-plugins/multisite-post-duplicator/inc/mpd-functions.php:406
Addresses:
kingandpartners/auberge#3623
---
inc/mpd-functions.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/inc/mpd-functions.php b/inc/mpd-functions.php
index 7de314a..4d19449 100644
--- a/inc/mpd-functions.php
+++ b/inc/mpd-functions.php
@@ -401,6 +401,7 @@ function mpd_get_images_from_the_content($post_id){
//Collect the sourse content
$html = get_post_field( 'post_content', $post_id);
+ if ( ! $html ) return;
$doc = new DOMDocument();
@$doc->loadHTML($html);
From 74e65d7ba59b3cb2b3f0444cd00e0ff9103fc561 Mon Sep 17 00:00:00 2001
From: Justin Grubbs
Date: Thu, 27 Mar 2025 19:05:40 -0400
Subject: [PATCH 4/4] relax constraints
---
composer.json | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/composer.json b/composer.json
index d0b96e4..930aa14 100644
--- a/composer.json
+++ b/composer.json
@@ -7,12 +7,12 @@
}
],
"require": {
- "composer/installers": "~1.0"
+ "composer/installers": "~1.0 || ~2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.6",
"brain/monkey": "1.*",
- "squizlabs/php_codesniffer": "~2.0"
+ "squizlabs/php_codesniffer": "~2.0 || ~3.0"
},
"type": "wordpress-plugin"
}