Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notices errors with some locales #364

Merged
merged 4 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"Yoast\\WP\\Duplicate_Post\\Config\\Composer\\Actions::check_coding_standards"
],
"check-cs-thresholds": [
"@putenv YOASTCS_THRESHOLD_ERRORS=69",
"@putenv YOASTCS_THRESHOLD_ERRORS=65",
"@putenv YOASTCS_THRESHOLD_WARNINGS=0",
"Yoast\\WP\\Duplicate_Post\\Config\\Composer\\Actions::check_cs_thresholds"
],
Expand Down
11 changes: 5 additions & 6 deletions js/src/duplicate-post-edit-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ class DuplicatePost {
return;
}

for ( const [ key, notice ] of Object.entries( duplicatePostNotices ) ){
let noticeObj = JSON.parse( notice );
if ( noticeObj.status && noticeObj.text ) {
for ( const [ key, notice ] of Object.entries( duplicatePostNotices ) ) {
if ( notice.status && notice.text ) {
dispatch( 'core/notices' ).createNotice(
noticeObj.status,
noticeObj.text,
notice.status,
notice.text,
{
isDismissible: noticeObj.isDismissible || true,
isDismissible: notice.isDismissible || true,
}
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/watchers/copied-post-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ public function add_block_editor_notice() {
if ( $this->permissions_helper->has_rewrite_and_republish_copy( $post ) ) {

$notice = [
'text' => \wp_slash( $this->get_notice_text( $post ) ),
'text' => $this->get_notice_text( $post ),
'status' => 'warning',
'isDismissible' => true,
];

\wp_add_inline_script(
'duplicate_post_edit_script',
"duplicatePostNotices.has_rewrite_and_republish_notice = '" . \wp_json_encode( $notice ) . "';",
'duplicatePostNotices.has_rewrite_and_republish_notice = ' . \wp_json_encode( $notice ) . ';',
'before'
);
}
Expand Down
11 changes: 5 additions & 6 deletions src/watchers/link-actions-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function register_hooks() {
/**
* Adds vars to the removable query args.
*
* @param array $removable_query_args Array of query args keys.
* @param array<string> $removable_query_args Array of query args keys.
*
* @return array The updated array of query args keys.
* @return array<string> The updated array of query args keys.
*/
public function add_removable_query_args( $removable_query_args ) {
if ( \is_array( $removable_query_args ) ) {
Expand Down Expand Up @@ -109,19 +109,18 @@ public function add_rewrite_and_republish_admin_notice() {
public function add_rewrite_and_republish_block_editor_notice() {
if ( ! empty( $_REQUEST['rewriting'] ) ) {
$notice = [
'text' => \wp_slash(
'text' =>
\__(
'You can now start rewriting your post in this duplicate of the original post. If you click "Republish", this rewritten post will replace the original post.',
'duplicate-post'
)
),
),
'status' => 'warning',
'isDismissible' => true,
];

\wp_add_inline_script(
'duplicate_post_edit_script',
"duplicatePostNotices.rewriting_notice = '" . \wp_json_encode( $notice ) . "';",
'duplicatePostNotices.rewriting_notice = ' . \wp_json_encode( $notice ) . ';',
'before'
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/watchers/original-post-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ public function add_block_editor_notice() {
if ( $this->permissions_helper->has_original_changed( $post ) ) {

$notice = [
'text' => \wp_slash( $this->get_notice_text() ),
'text' => $this->get_notice_text(),
'status' => 'warning',
'isDismissible' => true,
];

\wp_add_inline_script(
'duplicate_post_edit_script',
"duplicatePostNotices.has_original_changed_notice = '" . \wp_json_encode( $notice ) . "';",
'duplicatePostNotices.has_original_changed_notice = ' . \wp_json_encode( $notice ) . ';',
'before'
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/watchers/republished-post-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function register_hooks() {
/**
* Adds vars to the removable query args.
*
* @param array $removable_query_args Array of query args keys.
* @param array<string> $removable_query_args Array of query args keys.
*
* @return array The updated array of query args keys.
* @return array<string> The updated array of query args keys.
*/
public function add_removable_query_args( $removable_query_args ) {
if ( \is_array( $removable_query_args ) ) {
Expand Down Expand Up @@ -93,14 +93,14 @@ public function add_admin_notice() {
public function add_block_editor_notice() {
if ( ! empty( $_REQUEST['dprepublished'] ) ) {
$notice = [
'text' => \wp_slash( $this->get_notice_text() ),
'text' => $this->get_notice_text(),
'status' => 'success',
'isDismissible' => true,
];

\wp_add_inline_script(
'duplicate_post_edit_script',
"duplicatePostNotices.republished_notice = '" . \wp_json_encode( $notice ) . "';",
'duplicatePostNotices.republished_notice = ' . \wp_json_encode( $notice ) . ';',
'before'
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Watchers/Copied_Post_Watcher_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function test_add_block_editor_notice() {
Monkey\Functions\expect( '\wp_add_inline_script' )
->with(
'duplicate_post_edit_script',
"duplicatePostNotices.has_rewrite_and_republish_notice = '{\"text\":\"notice\",\"status\":\"warning\",\"isDismissible\":true}';",
'duplicatePostNotices.has_rewrite_and_republish_notice = {"text":"notice","status":"warning","isDismissible":true};',
'before'
);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Watchers/Link_Actions_Watcher_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function test_add_rewrite_and_republish_block_editor_notice() {
Monkey\Functions\expect( '\wp_add_inline_script' )
->with(
'duplicate_post_edit_script',
"duplicatePostNotices.rewriting_notice = '{\"text\":\"You can now start rewriting your post in this duplicate of the original post. If you click \\\"Republish\\\", this rewritten post will replace the original post.\",\"status\":\"warning\",\"isDismissible\":true}';",
'duplicatePostNotices.rewriting_notice = {"text":"You can now start rewriting your post in this duplicate of the original post. If you click \"Republish\", this rewritten post will replace the original post.","status":"warning","isDismissible":true};',
'before'
);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Watchers/Original_Post_Watcher_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function test_add_block_editor_notice() {
Monkey\Functions\expect( '\wp_add_inline_script' )
->with(
'duplicate_post_edit_script',
"duplicatePostNotices.has_original_changed_notice = '{\"text\":\"notice\",\"status\":\"warning\",\"isDismissible\":true}';",
'duplicatePostNotices.has_original_changed_notice = {"text":"notice","status":"warning","isDismissible":true};',
'before'
);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Watchers/Republished_Post_Watcher_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function test_add_block_editor_notice() {
Monkey\Functions\expect( '\wp_add_inline_script' )
->with(
'duplicate_post_edit_script',
"duplicatePostNotices.republished_notice = '{\"text\":\"notice\",\"status\":\"success\",\"isDismissible\":true}';",
'duplicatePostNotices.republished_notice = {"text":"notice","status":"success","isDismissible":true};',
'before'
);

Expand Down