Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions config/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
return [
'acf' => Yard\Brave\Hooks\ACF::class,
'authorization' => Yard\Brave\Hooks\Authorization::class,
'duplicate-post' => Yard\Brave\Hooks\DuplicatePost::class,
'elasticsearch' => Yard\Brave\Hooks\Elasticsearch::class,
'facetwp' => Yard\Brave\Hooks\FacetWP::class,
'gravityforms' => Yard\Brave\Hooks\GravityForms::class,
Expand Down
40 changes: 40 additions & 0 deletions src/DuplicatePost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Yard\Brave\Hooks;

use Yard\Hook\Action;
use Yoast\WP\Duplicate_Post\Permissions_Helper;

#[Plugin('duplicate-post/duplicate-post.php')]
class DuplicatePost
{
// This is a workaround for the Duplicate Post plugin to save revisions for the rewrite and republish copy
// Can be removed when this issue is fixed: https://github.com/Yoast/duplicate-post/issues/404
#[Action('load-post.php')]
public function saveRevisionForRewriteAndRepublishCopy(): void
{
if (! class_exists(Permissions_Helper::class)) {
return;
}

$postID = intval($_GET['post']);
$post = get_post($postID);
if (! $post instanceof \WP_Post) {
return;
}

if (! (new Permissions_Helper())->is_rewrite_and_republish_copy($post)) {
return;
}

$revisionData = wp_get_latest_revision_id_and_total_count($post->ID);

if (is_wp_error($revisionData) || 0 < $revisionData['count']) {
return;
}

wp_save_post_revision($post->ID);
}
}