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

Yoast / duplicate-post / 14725616456

29 Apr 2025 07:21AM UTC coverage: 45.469% (-4.7%) from 50.122%
14725616456

push

github

web-flow
Merge pull request #402 from Yoast/feature/drop-php-7.2-7.3

Drop support for Php 7.2 and 7.3

1164 of 2560 relevant lines covered (45.47%)

1.61 hits per line

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

38.46
/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 ) {
6✔
50
                $enabled_post_types = $this->permissions_helper->get_enabled_post_types();
6✔
51

52
                if ( \in_array( $post_type, $enabled_post_types, true )
6✔
53
                        && $post instanceof WP_Post ) {
6✔
54
                        $original_item = Utils::get_original( $post );
4✔
55

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

70
        /**
71
         * Outputs the HTML for the metabox.
72
         *
73
         * @param WP_Post $post    The current post.
74
         * @param array   $metabox The array containing the metabox data.
75
         *
76
         * @return void
77
         */
78
        public function custom_metabox_html( $post, $metabox ) {
×
79
                $original_item = $metabox['args']['original'];
×
80
                if ( ! $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
×
81
                        ?>
82
                <p>
×
83
                        <input type="checkbox"
×
84
                                name="duplicate_post_remove_original"
×
85
                                id="duplicate-post-remove-original"
×
86
                                value="duplicate_post_remove_original"
×
87
                                aria-describedby="duplicate-post-remove-original-description">
×
88
                        <label for="duplicate-post-remove-original">
×
89
                                <?php \esc_html_e( 'Delete reference to original item.', 'duplicate-post' ); ?>
×
90
                        </label>
×
91
                </p>
×
92
                        <?php
×
93
                }
94
                ?>
95
                <p id="duplicate-post-remove-original-description">
×
96
                        <?php
×
97
                        \printf(
×
98
                                \wp_kses(
×
99
                                        /* translators: %s: post title */
100
                                        \__(
×
101
                                                'The original item this was copied from is: <span class="duplicate_post_original_item_title_span">%s</span>',
×
102
                                                'duplicate-post'
×
103
                                        ),
×
104
                                        [
×
105
                                                'span' => [
×
106
                                                        'class' => [],
×
107
                                                ],
×
108
                                        ]
×
109
                                ),
×
110
                                Utils::get_edit_or_view_link( $original_item )  // phpcs:ignore WordPress.Security.EscapeOutput
×
111
                        );
×
112
                        ?>
113
                </p>
×
114
                <?php
×
115
        }
116
}
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