From 5e8206fb60ea3165dea59be249c742a7d88e318a Mon Sep 17 00:00:00 2001 From: Michael Phillips Date: Tue, 4 Apr 2023 10:31:29 -0700 Subject: [PATCH 1/2] Add hooks when a post is duplicated for rewrite and republish to mirror the hooks already present when a post is copied. --- src/post-duplicator.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/post-duplicator.php b/src/post-duplicator.php index addcd9c26..f5bce4d2e 100644 --- a/src/post-duplicator.php +++ b/src/post-duplicator.php @@ -165,6 +165,12 @@ public function create_duplicate_for_rewrite_and_republish( WP_Post $post ) { $new_post_id = $this->create_duplicate( $post, $options ); if ( ! \is_wp_error( $new_post_id ) ) { + if ( $post->post_type === 'page' || is_post_type_hierarchical( $post->post_type ) ) { + do_action( 'dp_duplicate_page', $new_post_id, $post, $post->post_status ); + } else { + do_action( 'dp_duplicate_post', $new_post_id, $post, $post->post_status ); + } + $this->copy_post_taxonomies( $new_post_id, $post, $options ); $this->copy_post_meta_info( $new_post_id, $post, $options ); @@ -173,6 +179,15 @@ public function create_duplicate_for_rewrite_and_republish( WP_Post $post ) { \update_post_meta( $new_post_id, '_dp_creation_date_gmt', \current_time( 'mysql', 1 ) ); } + /** + * Fires after duplicating a post. + * + * @param int|WP_Error $new_post_id The new post id or WP_Error object on error. + * @param WP_Post $post The original post object. + * @param bool $status The intended destination status. + */ + do_action( 'duplicate_rewrite_and_republish_post_copy', $new_post_id, $post, $post->post_status ); + return $new_post_id; } From 89b61e9e592c9b5b835fc47e833bb06322efcf9f Mon Sep 17 00:00:00 2001 From: Michael Phillips Date: Thu, 6 Apr 2023 12:00:30 -0700 Subject: [PATCH 2/2] Pass the new post's status through hooks fired when duplicating a post for Rewrite & Republish. --- src/post-duplicator.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/post-duplicator.php b/src/post-duplicator.php index f5bce4d2e..991b2df14 100644 --- a/src/post-duplicator.php +++ b/src/post-duplicator.php @@ -162,13 +162,14 @@ public function create_duplicate_for_rewrite_and_republish( WP_Post $post ) { $defaults = $this->get_default_options(); $options = \wp_parse_args( $options, $defaults ); - $new_post_id = $this->create_duplicate( $post, $options ); + $new_post_id = $this->create_duplicate( $post, $options ); + $new_post_status = $this->generate_copy_status( $post, $options ); if ( ! \is_wp_error( $new_post_id ) ) { if ( $post->post_type === 'page' || is_post_type_hierarchical( $post->post_type ) ) { - do_action( 'dp_duplicate_page', $new_post_id, $post, $post->post_status ); + do_action( 'dp_duplicate_page', $new_post_id, $post, $new_post_status ); } else { - do_action( 'dp_duplicate_post', $new_post_id, $post, $post->post_status ); + do_action( 'dp_duplicate_post', $new_post_id, $post, $new_post_status ); } $this->copy_post_taxonomies( $new_post_id, $post, $options ); @@ -186,7 +187,7 @@ public function create_duplicate_for_rewrite_and_republish( WP_Post $post ) { * @param WP_Post $post The original post object. * @param bool $status The intended destination status. */ - do_action( 'duplicate_rewrite_and_republish_post_copy', $new_post_id, $post, $post->post_status ); + do_action( 'duplicate_rewrite_and_republish_post_copy', $new_post_id, $post, $new_post_status ); return $new_post_id; }