Skip to content

Commit a4f23a5

Browse files
Refactor the watchers (and their tests) to make some methods private
1 parent 3080bae commit a4f23a5

File tree

6 files changed

+187
-178
lines changed

6 files changed

+187
-178
lines changed

src/watchers/copied-post-watcher.php

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,40 +38,6 @@ public function register_hooks() {
3838
\add_action( 'enqueue_block_editor_assets', [ $this, 'add_block_editor_notice' ], 11 );
3939
}
4040

41-
/**
42-
* Generates the translated text for the notice.
43-
*
44-
* @param WP_Post $post The current post object.
45-
*
46-
* @return string The translated text for the notice.
47-
*/
48-
public function get_notice_text( $post ) {
49-
if ( $this->permissions_helper->has_trashed_rewrite_and_republish_copy( $post ) ) {
50-
return \__(
51-
'You can only make one Rewrite & Republish duplicate at a time, and a duplicate of this post already exists in the trash. Permanently delete it if you want to make a new duplicate.',
52-
'duplicate-post'
53-
);
54-
}
55-
56-
$scheduled_copy = $this->permissions_helper->has_scheduled_rewrite_and_republish_copy( $post );
57-
if ( ! $scheduled_copy ) {
58-
return \__(
59-
'A duplicate of this post was made. Please note that any changes you make to this post will be replaced when the duplicated version is republished.',
60-
'duplicate-post'
61-
);
62-
}
63-
64-
return \sprintf(
65-
/* translators: %1$s: scheduled date of the copy, %2$s: scheduled time of the copy. */
66-
\__(
67-
'A duplicate of this post was made, which is scheduled to replace this post on %1$s at %2$s.',
68-
'duplicate-post'
69-
),
70-
\get_the_time( \get_option( 'date_format' ), $scheduled_copy ),
71-
\get_the_time( \get_option( 'time_format' ), $scheduled_copy )
72-
);
73-
}
74-
7541
/**
7642
* Shows a notice on the Classic editor.
7743
*
@@ -90,7 +56,7 @@ public function add_admin_notice() {
9056

9157
if ( $this->permissions_helper->has_rewrite_and_republish_copy( $post ) ) {
9258
print '<div id="message" class="notice notice-warning is-dismissible fade"><p>'
93-
. \esc_html( $this->get_notice_text( $post ) )
59+
. \esc_html( $this->get_notice_copy( $post ) )
9460
. '</p></div>';
9561
}
9662
}
@@ -110,7 +76,7 @@ public function add_block_editor_notice() {
11076
if ( $this->permissions_helper->has_rewrite_and_republish_copy( $post ) ) {
11177

11278
$notice = [
113-
'text' => $this->get_notice_text( $post ),
79+
'text' => $this->get_notice_copy( $post ),
11480
'status' => 'warning',
11581
'isDismissible' => true,
11682
];
@@ -122,4 +88,53 @@ public function add_block_editor_notice() {
12288
);
12389
}
12490
}
91+
92+
/**
93+
* Generates the translated text for the notice.
94+
*
95+
* @param WP_Post $post The current post object.
96+
*
97+
* @return string The translated text for the notice.
98+
*/
99+
private function get_notice_copy( $post ) {
100+
if ( $this->permissions_helper->has_trashed_rewrite_and_republish_copy( $post ) ) {
101+
return \__(
102+
'You can only make one Rewrite & Republish duplicate at a time, and a duplicate of this post already exists in the trash. Permanently delete it if you want to make a new duplicate.',
103+
'duplicate-post'
104+
);
105+
}
106+
107+
$scheduled_copy = $this->permissions_helper->has_scheduled_rewrite_and_republish_copy( $post );
108+
if ( ! $scheduled_copy ) {
109+
return \__(
110+
'A duplicate of this post was made. Please note that any changes you make to this post will be replaced when the duplicated version is republished.',
111+
'duplicate-post'
112+
);
113+
}
114+
115+
return \sprintf(
116+
/* translators: %1$s: scheduled date of the copy, %2$s: scheduled time of the copy. */
117+
\__(
118+
'A duplicate of this post was made, which is scheduled to replace this post on %1$s at %2$s.',
119+
'duplicate-post'
120+
),
121+
\get_the_time( \get_option( 'date_format' ), $scheduled_copy ),
122+
\get_the_time( \get_option( 'time_format' ), $scheduled_copy )
123+
);
124+
}
125+
126+
/**
127+
* Generates the translated text for the republished notice.
128+
*
129+
* @deprecated 4.6
130+
* @codeCoverageIgnore
131+
*
132+
* @param WP_Post $post The current post object.
133+
*
134+
* @return string The translated text for the republished notice.
135+
*/
136+
public function get_notice_text( $post ) {
137+
\_deprecated_function( __METHOD__, '4.6', self::class . '::get_notice_copy' );
138+
return $this->get_notice_copy( $post );
139+
}
125140
}

src/watchers/original-post-watcher.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ public function register_hooks() {
4242
\add_action( 'enqueue_block_editor_assets', [ $this, 'add_block_editor_notice' ], 11 );
4343
}
4444

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() {
51-
return \__(
52-
'The original post has been edited in the meantime. If you click "Republish", this rewritten post will replace the original post.',
53-
'duplicate-post'
54-
);
55-
}
56-
5745
/**
5846
* Shows a notice on the Classic editor.
5947
*
@@ -72,7 +60,7 @@ public function add_admin_notice() {
7260

7361
if ( $this->permissions_helper->has_original_changed( $post ) ) {
7462
print '<div id="message" class="notice notice-warning is-dismissible fade"><p>'
75-
. \esc_html( $this->get_notice_text() )
63+
. \esc_html( $this->get_notice_copy() )
7664
. '</p></div>';
7765
}
7866
}
@@ -92,7 +80,7 @@ public function add_block_editor_notice() {
9280
if ( $this->permissions_helper->has_original_changed( $post ) ) {
9381

9482
$notice = [
95-
'text' => $this->get_notice_text(),
83+
'text' => $this->get_notice_copy(),
9684
'status' => 'warning',
9785
'isDismissible' => true,
9886
];
@@ -104,4 +92,29 @@ public function add_block_editor_notice() {
10492
);
10593
}
10694
}
95+
96+
/**
97+
* Generates the translated text for the notice.
98+
*
99+
* @return string The translated text for the notice.
100+
*/
101+
private function get_notice_copy() {
102+
return \__(
103+
'The original post has been edited in the meantime. If you click "Republish", this rewritten post will replace the original post.',
104+
'duplicate-post'
105+
);
106+
}
107+
108+
/**
109+
* Generates the translated text for the notice.
110+
*
111+
* @deprecated 4.6
112+
* @codeCoverageIgnore
113+
*
114+
* @return string The translated text for the notice.
115+
*/
116+
public function get_notice_text() {
117+
\_deprecated_function( __METHOD__, '4.6', self::class . '::get_notice_copy' );
118+
return $this->get_notice_copy();
119+
}
107120
}

src/watchers/republished-post-watcher.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,6 @@ public function add_removable_query_args( $removable_query_args ) {
5656
return $removable_query_args;
5757
}
5858

59-
/**
60-
* Generates the translated text for the republished notice.
61-
*
62-
* @return string The translated text for the republished notice.
63-
*/
64-
public function get_notice_text() {
65-
return \__(
66-
'Your original post has been replaced with the rewritten post. You are now viewing the (rewritten) original post.',
67-
'duplicate-post'
68-
);
69-
}
70-
7159
/**
7260
* Shows a notice on the Classic editor.
7361
*
@@ -80,7 +68,7 @@ public function add_admin_notice() {
8068

8169
if ( ! empty( $_REQUEST['dprepublished'] ) ) {
8270
echo '<div id="message" class="notice notice-success is-dismissible"><p>'
83-
. \esc_html( $this->get_notice_text() )
71+
. \esc_html( $this->get_notice_copy() )
8472
. '</p></div>';
8573
}
8674
}
@@ -93,7 +81,7 @@ public function add_admin_notice() {
9381
public function add_block_editor_notice() {
9482
if ( ! empty( $_REQUEST['dprepublished'] ) ) {
9583
$notice = [
96-
'text' => $this->get_notice_text(),
84+
'text' => $this->get_notice_copy(),
9785
'status' => 'success',
9886
'isDismissible' => true,
9987
];
@@ -105,4 +93,29 @@ public function add_block_editor_notice() {
10593
);
10694
}
10795
}
96+
97+
/**
98+
* Generates the translated text for the notice.
99+
*
100+
* @return string The translated text for the notice.
101+
*/
102+
private function get_notice_copy() {
103+
return \__(
104+
'Your original post has been replaced with the rewritten post. You are now viewing the (rewritten) original post.',
105+
'duplicate-post'
106+
);
107+
}
108+
109+
/**
110+
* Generates the translated text for the republished notice.
111+
*
112+
* @deprecated 4.6
113+
* @codeCoverageIgnore
114+
*
115+
* @return string The translated text for the republished notice.
116+
*/
117+
public function get_notice_text() {
118+
\_deprecated_function( __METHOD__, '4.6', self::class . '::get_notice_copy' );
119+
return $this->get_notice_copy();
120+
}
108121
}

0 commit comments

Comments
 (0)