diff --git a/composer.json b/composer.json index 88d0e8d58..a4dd940cd 100644 --- a/composer.json +++ b/composer.json @@ -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" ], diff --git a/js/src/duplicate-post-edit-script.js b/js/src/duplicate-post-edit-script.js index ccbb7645e..6d289f0f6 100644 --- a/js/src/duplicate-post-edit-script.js +++ b/js/src/duplicate-post-edit-script.js @@ -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, } ); } diff --git a/src/watchers/copied-post-watcher.php b/src/watchers/copied-post-watcher.php index 86550b482..bd79131a9 100644 --- a/src/watchers/copied-post-watcher.php +++ b/src/watchers/copied-post-watcher.php @@ -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' ); } diff --git a/src/watchers/link-actions-watcher.php b/src/watchers/link-actions-watcher.php index d19b4dd69..94a2a24af 100644 --- a/src/watchers/link-actions-watcher.php +++ b/src/watchers/link-actions-watcher.php @@ -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 $removable_query_args Array of query args keys. * - * @return array The updated array of query args keys. + * @return array The updated array of query args keys. */ public function add_removable_query_args( $removable_query_args ) { if ( \is_array( $removable_query_args ) ) { @@ -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' ); } diff --git a/src/watchers/original-post-watcher.php b/src/watchers/original-post-watcher.php index 7bba2cc97..d1293923b 100644 --- a/src/watchers/original-post-watcher.php +++ b/src/watchers/original-post-watcher.php @@ -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' ); } diff --git a/src/watchers/republished-post-watcher.php b/src/watchers/republished-post-watcher.php index 64908518c..41e0e3230 100644 --- a/src/watchers/republished-post-watcher.php +++ b/src/watchers/republished-post-watcher.php @@ -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 $removable_query_args Array of query args keys. * - * @return array The updated array of query args keys. + * @return array The updated array of query args keys. */ public function add_removable_query_args( $removable_query_args ) { if ( \is_array( $removable_query_args ) ) { @@ -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' ); } diff --git a/tests/Unit/Watchers/Copied_Post_Watcher_Test.php b/tests/Unit/Watchers/Copied_Post_Watcher_Test.php index 7dae09e6b..273ee3ecf 100644 --- a/tests/Unit/Watchers/Copied_Post_Watcher_Test.php +++ b/tests/Unit/Watchers/Copied_Post_Watcher_Test.php @@ -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' ); diff --git a/tests/Unit/Watchers/Link_Actions_Watcher_Test.php b/tests/Unit/Watchers/Link_Actions_Watcher_Test.php index 7229185ed..bffcdae76 100644 --- a/tests/Unit/Watchers/Link_Actions_Watcher_Test.php +++ b/tests/Unit/Watchers/Link_Actions_Watcher_Test.php @@ -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' ); diff --git a/tests/Unit/Watchers/Original_Post_Watcher_Test.php b/tests/Unit/Watchers/Original_Post_Watcher_Test.php index d9a35eba4..a5a3236ca 100644 --- a/tests/Unit/Watchers/Original_Post_Watcher_Test.php +++ b/tests/Unit/Watchers/Original_Post_Watcher_Test.php @@ -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' ); diff --git a/tests/Unit/Watchers/Republished_Post_Watcher_Test.php b/tests/Unit/Watchers/Republished_Post_Watcher_Test.php index 19b2a8a96..998de62b2 100644 --- a/tests/Unit/Watchers/Republished_Post_Watcher_Test.php +++ b/tests/Unit/Watchers/Republished_Post_Watcher_Test.php @@ -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' );