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

Yoast / duplicate-post / 8307344294

16 Mar 2024 11:12AM UTC coverage: 50.223% (-0.02%) from 50.244%
8307344294

push

github

web-flow
Merge pull request #364 from Yoast/fix/parse-errors

Fix notices errors with some locales

7 of 9 new or added lines in 4 files covered. (77.78%)

1237 of 2463 relevant lines covered (50.22%)

1.62 hits per line

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

65.71
/src/watchers/original-post-watcher.php
1
<?php
2

3
namespace Yoast\WP\Duplicate_Post\Watchers;
4

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

8
/**
9
 * Duplicate Post Original post watcher class.
10
 *
11
 * Watches the original post for changes.
12
 *
13
 * @since 4.0
14
 */
15
class Original_Post_Watcher {
16

17
        /**
18
         * Holds the permissions helper.
19
         *
20
         * @var Permissions_Helper
21
         */
22
        protected $permissions_helper;
23

24
        /**
25
         * Initializes the class.
26
         *
27
         * @param Permissions_Helper $permissions_helper The Permissions helper object.
28
         */
29
        public function __construct( Permissions_Helper $permissions_helper ) {
2✔
30
                $this->permissions_helper = $permissions_helper;
2✔
31

32
                $this->register_hooks();
2✔
33
        }
1✔
34

35
        /**
36
         * Registers the hooks.
37
         *
38
         * @return void
39
         */
40
        public function register_hooks() {
2✔
41
                \add_action( 'admin_notices', [ $this, 'add_admin_notice' ] );
2✔
42
                \add_action( 'enqueue_block_editor_assets', [ $this, 'add_block_editor_notice' ], 11 );
2✔
43
        }
1✔
44

45
        /**
46
         * Generates the translated text for the notice.
47
         *
48
         * @return string The translated text for the notice.
49
         */
50
        public function get_notice_text() {
2✔
51
                return \__(
2✔
52
                        'The original post has been edited in the meantime. If you click "Republish", this rewritten post will replace the original post.',
2✔
53
                        'duplicate-post'
2✔
54
                );
1✔
55
        }
56

57
        /**
58
         * Shows a notice on the Classic editor.
59
         *
60
         * @return void
61
         */
62
        public function add_admin_notice() {
4✔
63
                if ( ! $this->permissions_helper->is_classic_editor() ) {
4✔
64
                        return;
2✔
65
                }
66

67
                $post = \get_post();
2✔
68

69
                if ( ! $post instanceof WP_Post ) {
2✔
70
                        return;
×
71
                }
72

73
                if ( $this->permissions_helper->has_original_changed( $post ) ) {
2✔
74
                        print '<div id="message" class="notice notice-warning is-dismissible fade"><p>'
1✔
75
                                . \esc_html( $this->get_notice_text() )
2✔
76
                                . '</p></div>';
2✔
77
                }
78
        }
1✔
79

80
        /**
81
         * Shows a notice on the Block editor.
82
         *
83
         * @return void
84
         */
85
        public function add_block_editor_notice() {
×
86
                $post = \get_post();
×
87

88
                if ( ! $post instanceof WP_Post ) {
×
89
                        return;
×
90
                }
91

92
                if ( $this->permissions_helper->has_original_changed( $post ) ) {
×
93

94
                        $notice = [
NEW
95
                                'text'          => $this->get_notice_text(),
×
96
                                'status'        => 'warning',
×
97
                                'isDismissible' => true,
98
                        ];
99

100
                        \wp_add_inline_script(
×
101
                                'duplicate_post_edit_script',
×
NEW
102
                                'duplicatePostNotices.has_original_changed_notice = ' . \wp_json_encode( $notice ) . ';',
×
103
                                'before'
×
104
                        );
105
                }
106
        }
107
}
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