|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\DuplicatePost; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Controllers\AbstractController; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Database\CountManager; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Database\ReviewManager; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
|
9
|
|
|
use GeminiLabs\SiteReviews\Review; |
|
10
|
|
|
|
|
11
|
|
|
class Controller extends AbstractController |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @param int|\WP_Error $newPostId |
|
15
|
|
|
* @param \WP_Post $post |
|
16
|
|
|
* |
|
17
|
|
|
* @action duplicate_post_post_copy |
|
18
|
|
|
*/ |
|
19
|
|
|
public function duplicateReview($newPostId, $post): void |
|
20
|
|
|
{ |
|
21
|
|
|
if (!Review::isReview($post)) { |
|
22
|
|
|
return; |
|
23
|
|
|
} |
|
24
|
|
|
if (is_wp_error($newPostId)) { |
|
25
|
|
|
return; |
|
26
|
|
|
} |
|
27
|
|
|
$review = glsr_get_review($post->ID); |
|
28
|
|
|
if ($review->isValid()) { |
|
29
|
|
|
glsr(ReviewManager::class)->createFromPost((int) $newPostId, $review->toArray()); |
|
30
|
|
|
delete_post_meta($newPostId, '_submitted'); |
|
|
|
|
|
|
31
|
|
|
delete_post_meta($newPostId, '_submitted_hash'); |
|
32
|
|
|
update_post_meta($newPostId, '_duplicated_from', $post->ID); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string[] $actions |
|
38
|
|
|
* |
|
39
|
|
|
* @filter bulk_actions-edit-{Application::POST_TYPE} |
|
40
|
|
|
*/ |
|
41
|
|
|
public function filterBulkActions($actions): array |
|
42
|
|
|
{ |
|
43
|
|
|
$actions = Arr::consolidate($actions); |
|
44
|
|
|
unset($actions['duplicate_post_bulk_rewrite_republish']); |
|
45
|
|
|
return $actions; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param string[] $metaKeys |
|
50
|
|
|
* |
|
51
|
|
|
* @filter duplicate_post_excludelist_filter |
|
52
|
|
|
*/ |
|
53
|
|
|
public function filterExcludedMetaKeys($metaKeys): array |
|
54
|
|
|
{ |
|
55
|
|
|
$metaKeys[] = CountManager::META_AVERAGE; |
|
56
|
|
|
$metaKeys[] = CountManager::META_RANKING; |
|
57
|
|
|
$metaKeys[] = CountManager::META_REVIEWS; |
|
58
|
|
|
return $metaKeys; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string[] $actions |
|
63
|
|
|
* @param \WP_Post $post |
|
64
|
|
|
* |
|
65
|
|
|
* @filter post_row_actions |
|
66
|
|
|
*/ |
|
67
|
|
|
public function filterRowActions($actions, $post): array |
|
68
|
|
|
{ |
|
69
|
|
|
$actions = Arr::consolidate($actions); |
|
70
|
|
|
if (Review::isReview($post)) { |
|
71
|
|
|
unset($actions['rewrite']); |
|
72
|
|
|
} |
|
73
|
|
|
return $actions; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param \WP_Post|null $post |
|
78
|
|
|
* |
|
79
|
|
|
* @action post_submitbox_start |
|
80
|
|
|
*/ |
|
81
|
|
|
public function removeRewriteEditorLink($post): void |
|
82
|
|
|
{ |
|
83
|
|
|
if (!Review::isReview($post)) { |
|
84
|
|
|
return; |
|
85
|
|
|
} |
|
86
|
|
|
global $wp_filter; |
|
87
|
|
|
$callbacks = Arr::get($wp_filter, 'post_submitbox_start.callbacks.10', []); |
|
88
|
|
|
foreach ($callbacks as $key => $value) { |
|
89
|
|
|
if (str_ends_with($key, 'add_rewrite_and_republish_post_button')) { |
|
90
|
|
|
remove_action('post_submitbox_start', Arr::get($value, 'function'), 10); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|