Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rewrite & Republish hooks #301

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/post-duplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,16 @@ 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, $new_post_status );
} else {
do_action( 'dp_duplicate_post', $new_post_id, $post, $new_post_status );
}

$this->copy_post_taxonomies( $new_post_id, $post, $options );
$this->copy_post_meta_info( $new_post_id, $post, $options );

Expand All @@ -173,6 +180,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, $new_post_status );

return $new_post_id;
}

Expand Down