• 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

27.42
/src/ui/column.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 custom column + quick edit.
11
 */
12
class Column {
13

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

21
        /**
22
         * Holds the asset manager.
23
         *
24
         * @var Asset_Manager
25
         */
26
        protected $asset_manager;
27

28
        /**
29
         * Initializes the class.
30
         *
31
         * @param Permissions_Helper $permissions_helper The permissions helper.
32
         * @param Asset_Manager      $asset_manager      The asset manager.
33
         */
34
        public function __construct( Permissions_Helper $permissions_helper, Asset_Manager $asset_manager ) {
2✔
35
                $this->permissions_helper = $permissions_helper;
2✔
36
                $this->asset_manager      = $asset_manager;
2✔
37
        }
38

39
        /**
40
         * Adds hooks to integrate with WordPress.
41
         *
42
         * @return void
43
         */
44
        public function register_hooks() {
2✔
45
                if ( \intval( \get_option( 'duplicate_post_show_original_column' ) ) === 1 ) {
2✔
46
                        $enabled_post_types = $this->permissions_helper->get_enabled_post_types();
2✔
47
                        if ( \count( $enabled_post_types ) ) {
2✔
48
                                foreach ( $enabled_post_types as $enabled_post_type ) {
2✔
49
                                        \add_filter( "manage_{$enabled_post_type}_posts_columns", [ $this, 'add_original_column' ] );
2✔
50
                                        \add_action( "manage_{$enabled_post_type}_posts_custom_column", [ $this, 'show_original_item' ], 10, 2 );
2✔
51
                                }
52
                                \add_action( 'quick_edit_custom_box', [ $this, 'quick_edit_remove_original' ] );
2✔
53
                                \add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
2✔
54
                                \add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_styles' ] );
2✔
55
                        }
56
                }
57
        }
58

59
        /**
60
         * Adds Original item column to the post list.
61
         *
62
         * @param array $post_columns The post columns array.
63
         *
64
         * @return array The updated array.
65
         */
66
        public function add_original_column( $post_columns ) {
2✔
67
                if ( \is_array( $post_columns ) ) {
2✔
68
                        $post_columns['duplicate_post_original_item'] = \__( 'Original item', 'duplicate-post' );
2✔
69
                }
70
                return $post_columns;
2✔
71
        }
72

73
        /**
74
         * Sets the text to be displayed in the Original item column for the current post.
75
         *
76
         * @param string $column_name The name for the current column.
77
         * @param int    $post_id     The ID for the current post.
78
         *
79
         * @return void
80
         */
81
        public function show_original_item( $column_name, $post_id ) {
×
82
                if ( $column_name === 'duplicate_post_original_item' ) {
×
83
                        $column_content = '-';
×
84
                        $data_attr      = ' data-no-original="1"';
×
85
                        $original_item  = Utils::get_original( $post_id );
×
86
                        if ( $original_item ) {
×
87
                                $post      = \get_post( $post_id );
×
88
                                $data_attr = '';
×
89

90
                                if ( $post instanceof WP_Post
×
91
                                        && $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
×
92
                                        $data_attr = ' data-copy-is-for-rewrite-and-republish="1"';
×
93
                                }
94

95
                                $column_content = Utils::get_edit_or_view_link( $original_item );
×
96
                        }
97
                        \printf(
×
98
                                '<span class="duplicate_post_original_link"%s>%s</span>',
×
99
                                $data_attr, // phpcs:ignore WordPress.Security.EscapeOutput
×
100
                                $column_content // phpcs:ignore WordPress.Security.EscapeOutput
×
101
                        );
×
102
                }
103
        }
104

105
        /**
106
         * Adds original item checkbox + edit link in the Quick Edit.
107
         *
108
         * @param string $column_name The name for the current column.
109
         *
110
         * @return void
111
         */
112
        public function quick_edit_remove_original( $column_name ) {
×
113
                if ( $column_name !== 'duplicate_post_original_item' ) {
×
114
                        return;
×
115
                }
116
                \printf(
×
117
                        '<fieldset class="inline-edit-col-left" id="duplicate_post_quick_edit_fieldset">
×
118
                        <div class="inline-edit-col">
119
                                <input type="checkbox"
120
                                name="duplicate_post_remove_original"
121
                                id="duplicate-post-remove-original"
122
                                value="duplicate_post_remove_original"
123
                                aria-describedby="duplicate-post-remove-original-description">
124
                                <label for="duplicate-post-remove-original">
125
                                        <span class="checkbox-title">%s</span>
126
                                </label>
127
                                <span id="duplicate-post-remove-original-description" class="checkbox-title">%s</span>
128
                        </div>
129
                </fieldset>',
×
130
                        \esc_html__(
×
131
                                'Delete reference to original item.',
×
132
                                'duplicate-post'
×
133
                        ),
×
134
                        \wp_kses(
×
135
                                \__(
×
136
                                        'The original item this was copied from is: <span class="duplicate_post_original_item_title_span"></span>',
×
137
                                        'duplicate-post'
×
138
                                ),
×
139
                                [
×
140
                                        'span' => [
×
141
                                                'class' => [],
×
142
                                        ],
×
143
                                ]
×
144
                        )
×
145
                );
×
146
        }
147

148
        /**
149
         * Enqueues the Javascript file to inject column data into the Quick Edit.
150
         *
151
         * @param string $hook The current admin page.
152
         *
153
         * @return void
154
         */
155
        public function admin_enqueue_scripts( $hook ) {
×
156
                if ( $hook === 'edit.php' ) {
×
157
                        $this->asset_manager->enqueue_quick_edit_script();
×
158
                }
159
        }
160

161
        /**
162
         * Enqueues the CSS file to for the Quick edit
163
         *
164
         * @param string $hook The current admin page.
165
         *
166
         * @return void
167
         */
168
        public function admin_enqueue_styles( $hook ) {
×
169
                if ( $hook === 'edit.php' ) {
×
170
                        $this->asset_manager->enqueue_styles();
×
171
                }
172
        }
173
}
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

© 2025 Coveralls, Inc