• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / duplicate-post / 21727773261

05 Feb 2026 08:43PM UTC coverage: 58.14% (+0.02%) from 58.118%
21727773261

push

github

web-flow
Merge pull request #453 from Yoast/JRF/composer-update-yoastcs

Update to YoastCS 3.3.0

66 of 118 new or added lines in 29 files covered. (55.93%)

4 existing lines in 2 files now uncovered.

1532 of 2635 relevant lines covered (58.14%)

7.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.74
/src/ui/metabox.php
1
<?php
2

3
namespace Yoast\WP\Duplicate_Post\UI;
4

5
use WP_Post;
6
use Yoast\WP\Duplicate_Post\Permissions_Helper;
7
use Yoast\WP\Duplicate_Post\Utils;
8

9
/**
10
 * Duplicate Post class to manage the metabox.
11
 */
12
class Metabox {
13

14
        /**
15
         * Holds the permissions helper.
16
         *
17
         * @var Permissions_Helper
18
         */
19
        protected $permissions_helper;
20

21
        /**
22
         * Initializes the class.
23
         *
24
         * @param Permissions_Helper $permissions_helper The permissions helper.
25
         */
26
        public function __construct( Permissions_Helper $permissions_helper ) {
2✔
27
                $this->permissions_helper = $permissions_helper;
2✔
28
        }
29

30
        /**
31
         * Adds hooks to integrate with WordPress.
32
         *
33
         * @return void
34
         */
35
        public function register_hooks() {
2✔
36
                if ( \intval( \get_option( 'duplicate_post_show_original_meta_box' ) ) === 1 ) {
2✔
37
                        \add_action( 'add_meta_boxes', [ $this, 'add_custom_metabox' ], 10, 2 );
2✔
38
                }
39
        }
40

41
        /**
42
         * Adds a metabox to Edit screen.
43
         *
44
         * @param string  $post_type The post type.
45
         * @param WP_Post $post      The current post object.
46
         *
47
         * @return void
48
         */
49
        public function add_custom_metabox( $post_type, $post ) {
8✔
50
                // Don't show the metabox in the block editor, we use the sidebar panel instead.
51
                if ( \use_block_editor_for_post( $post ) ) {
8✔
52
                        return;
2✔
53
                }
54

55
                $enabled_post_types = $this->permissions_helper->get_enabled_post_types();
6✔
56

57
                if ( \in_array( $post_type, $enabled_post_types, true )
6✔
58
                        && $post instanceof WP_Post ) {
6✔
59
                        $original_item = Utils::get_original( $post );
4✔
60

61
                        if ( $original_item instanceof WP_Post ) {
4✔
62
                                \add_meta_box(
2✔
63
                                        'duplicate_post_show_original',
2✔
64
                                        \__( 'Duplicate Post', 'duplicate-post' ),
2✔
65
                                        [ $this, 'custom_metabox_html' ],
2✔
66
                                        $post_type,
2✔
67
                                        'side',
2✔
68
                                        'default',
2✔
69
                                        [ 'original' => $original_item ],
2✔
70
                                );
2✔
71
                        }
72
                }
73
        }
74

75
        /**
76
         * Outputs the HTML for the metabox.
77
         *
78
         * @param WP_Post $post    The current post.
79
         * @param array   $metabox The array containing the metabox data.
80
         *
81
         * @return void
82
         */
83
        public function custom_metabox_html( $post, $metabox ) {
×
84
                $original_item = $metabox['args']['original'];
×
85
                if ( ! $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
×
86
                        ?>
87
                <p>
×
88
                        <input type="checkbox"
×
89
                                name="duplicate_post_remove_original"
×
90
                                id="duplicate-post-remove-original"
×
91
                                value="duplicate_post_remove_original"
×
92
                                aria-describedby="duplicate-post-remove-original-description">
×
93
                        <label for="duplicate-post-remove-original">
×
94
                                <?php \esc_html_e( 'Delete reference to original item.', 'duplicate-post' ); ?>
×
95
                        </label>
×
96
                </p>
×
97
                        <?php
×
98
                }
99
                ?>
100
                <p id="duplicate-post-remove-original-description">
×
101
                        <?php
×
102
                        \printf(
×
103
                                \wp_kses(
×
104
                                        /* translators: %s: post title */
105
                                        \__(
×
106
                                                'The original item this was copied from is: <span class="duplicate_post_original_item_title_span">%s</span>',
×
NEW
107
                                                'duplicate-post',
×
108
                                        ),
×
109
                                        [
×
110
                                                'span' => [
×
111
                                                        'class' => [],
×
112
                                                ],
×
NEW
113
                                        ],
×
114
                                ),
×
NEW
115
                                Utils::get_edit_or_view_link( $original_item ),  // phpcs:ignore WordPress.Security.EscapeOutput
×
116
                        );
×
117
                        ?>
118
                </p>
×
119
                <?php
×
120
        }
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc