From 8a169dee79b6c5980f9181ad5da3261569070850 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 26 Jul 2023 09:58:23 -0600 Subject: [PATCH 01/26] =?UTF-8?q?Footnotes:=20use=20core=E2=80=99s=20meta?= =?UTF-8?q?=20revisioning=20if=20available?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block-library/src/footnotes/index.php | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index 9815033820406b..cb3b3c51d50570 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -68,9 +68,10 @@ function register_block_core_footnotes() { $post_type, 'footnotes', array( - 'show_in_rest' => true, - 'single' => true, - 'type' => 'string', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + 'revisions_enabled' => true, ) ); } @@ -102,7 +103,9 @@ function wp_save_footnotes_meta( $revision_id ) { } } } -add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ); +if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ); +} /** * Keeps track of the revision ID for "rest_after_insert_{$post_type}". @@ -117,7 +120,9 @@ function wp_keep_footnotes_revision_id( $revision_id ) { global $wp_temporary_footnote_revision_id; $wp_temporary_footnote_revision_id = $revision_id; } -add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); +if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); +} /** * This is a specific fix for the REST API. The REST API doesn't update @@ -159,11 +164,11 @@ function wp_add_footnotes_revisions_to_post_meta( $post ) { } } } - -foreach ( array( 'post', 'page' ) as $post_type ) { - add_action( "rest_after_insert_{$post_type}", 'wp_add_footnotes_revisions_to_post_meta' ); +if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + foreach ( array( 'post', 'page' ) as $post_type ) { + add_action( "rest_after_insert_{$post_type}", 'wp_add_footnotes_revisions_to_post_meta' ); + } } - /** * Restores the footnotes meta value from the revision. * @@ -181,7 +186,9 @@ function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { delete_post_meta( $post_id, 'footnotes' ); } } -add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 ); +if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 ); +} /** * Adds the footnotes field to the revision. From 59bc54fe7c2ae347e55a5589fb9c3b82af1a27cb Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 8 Sep 2023 13:51:37 -0600 Subject: [PATCH 02/26] Ensure preview menu is closed after opening preview --- test/e2e/specs/editor/various/footnotes.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index e024964831dfe7..2a24336ef841e5 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -348,6 +348,7 @@ test.describe( 'Footnotes', () => { await previewPage.close(); await editorPage.bringToFront(); + await editor.canvas.click( 'p:text("first paragraph")' ); // Open revisions. await editor.openDocumentSettingsSidebar(); From fd9d4a000d1aca780e3d56b757aa5f75881d528d Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Sat, 9 Sep 2023 09:52:25 -0600 Subject: [PATCH 03/26] Improve docs and add some new conditionals --- .../block-library/src/footnotes/index.php | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index bf1580b73ea2a2..4d32e98f13379d 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -9,6 +9,7 @@ * Renders the `core/footnotes` block on the server. * * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @param array $attributes Block attributes. * @param string $content Block default content. @@ -88,6 +89,7 @@ function register_block_core_footnotes() { * Saves the footnotes meta value to the revision. * * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @param int $revision_id The revision ID. */ @@ -111,6 +113,7 @@ function wp_save_footnotes_meta( $revision_id ) { * Keeps track of the revision ID for "rest_after_insert_{$post_type}". * * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @global int $wp_temporary_footnote_revision_id The footnote revision ID. * @@ -136,6 +139,7 @@ function wp_keep_footnotes_revision_id( $revision_id ) { * `"rest_after_insert_{$post_type}"` action. * * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @global int $wp_temporary_footnote_revision_id The footnote revision ID. * @@ -174,6 +178,7 @@ function wp_add_footnotes_revisions_to_post_meta( $post ) { * Restores the footnotes meta value from the revision. * * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @param int $post_id The post ID. * @param int $revision_id The revision ID. @@ -192,7 +197,7 @@ function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { } /** - * Adds the footnotes field to the revision. + * Adds the footnotes field to the revisions display. * * @since 6.3.0 * @@ -206,7 +211,7 @@ function wp_add_footnotes_to_revision( $fields ) { add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' ); /** - * Gets the footnotes field from the revision. + * Gets the footnotes field from the revision for the revisions screen. * * @since 6.3.0 * @@ -227,6 +232,7 @@ function wp_get_footnotes_from_revision( $revision_field, $field, $revision ) { * `_wp_put_post_revision` when it creates a new autosave. * * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @param int|array $autosave The autosave ID or array. */ @@ -253,11 +259,14 @@ function _wp_rest_api_autosave_meta( $autosave ) { update_post_meta( $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) ); } -// See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1. -add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); -// See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398. -// Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367. -add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); + +if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1. + add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); + // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398. + // Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367. + add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); +} /** * This is a workaround for the autosave endpoint returning early if the @@ -270,6 +279,7 @@ function _wp_rest_api_autosave_meta( $autosave ) { * course, this is temporary fix. * * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @param WP_Post $prepared_post The prepared post object. * @param WP_REST_Request $request The request object. @@ -291,5 +301,6 @@ function _wp_rest_api_force_autosave_difference( $prepared_post, $request ) { $prepared_post->footnotes = '[]'; return $prepared_post; } - -add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 ); +if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 ); +} From c18cae0fa6c8d5e72cf05ad15802aa64ddc0e0aa Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Sat, 9 Sep 2023 13:51:10 -0600 Subject: [PATCH 04/26] Add test to verify published post meta is unchanged when previewing meta changes --- test/e2e/specs/editor/various/footnotes.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index 2a24336ef841e5..bbcb1b4e73c9ba 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -422,5 +422,21 @@ test.describe( 'Footnotes', () => { await expect( previewPage2.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( '123″ ↩︎' ); + + // Verify that the published post is unchanged. + // Navigate to the published post. + await previewPage2.close(); + await editorPage.bringToFront(); + await editor.openDocumentSettingsSidebar(); + await page + .getByRole( 'region', { name: 'Editor settings' } ) + .getByRole( 'button', { name: 'Post' } ) + .click(); + await page.locator( 'a:text("View Post")' ).click(); + + // Verify that the published post footnote still says "1". + await expect( page.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( + '1 ↩︎' + ); } ); } ); From 7d944d28fe73b5fe080de9b4ff06cf4a035f0d16 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Sat, 9 Sep 2023 14:57:17 -0600 Subject: [PATCH 05/26] Correct overwriting of live published post meta when previewing --- packages/block-library/src/footnotes/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index 4d32e98f13379d..58f1e86468fb1b 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -257,7 +257,8 @@ function _wp_rest_api_autosave_meta( $autosave ) { return; } - update_post_meta( $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) ); + // Can't use update_post_meta() because it doesn't allow revisions. + update_metadata( 'post', $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) ); } if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { From fb6d61ee0cb7b65ad559df536c5f2dd17b6b77a1 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Mon, 11 Sep 2023 11:40:44 -0600 Subject: [PATCH 06/26] Comment out tests that require core changes to pass --- test/e2e/specs/editor/various/footnotes.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index bbcb1b4e73c9ba..f19c90f05b6f63 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -422,7 +422,8 @@ test.describe( 'Footnotes', () => { await expect( previewPage2.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( '123″ ↩︎' ); - + /* + These tests won't pass until https://core.trac.wordpress.org/ticket/20564 is committed // Verify that the published post is unchanged. // Navigate to the published post. await previewPage2.close(); @@ -438,5 +439,6 @@ test.describe( 'Footnotes', () => { await expect( page.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( '1 ↩︎' ); + */ } ); } ); From d7a96e13e3d0cd6d06bb5b83987c2398520ad67b Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 26 Sep 2023 10:13:26 -0600 Subject: [PATCH 07/26] Include test to verify published post uneffected when previewing meta changes --- test/e2e/specs/editor/various/footnotes.spec.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index f19c90f05b6f63..eaeafc2c58438c 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -392,9 +392,10 @@ test.describe( 'Footnotes', () => { await page.keyboard.type( '1' ); - // Publish post. + // Publish post with the footnote set to "1". await editor.publishPost(); + // Test previewing changes to meta. await editor.canvas.click( 'ol.wp-block-footnotes li span' ); await page.keyboard.press( 'End' ); await page.keyboard.type( '2' ); @@ -409,8 +410,7 @@ test.describe( 'Footnotes', () => { await previewPage.close(); await editorPage.bringToFront(); - // Test again, this time with an existing revision (different code - // path). + // Test again, this time with an existing revision (different code path). await editor.canvas.click( 'ol.wp-block-footnotes li span' ); await page.keyboard.press( 'End' ); // Test slashing. @@ -422,10 +422,8 @@ test.describe( 'Footnotes', () => { await expect( previewPage2.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( '123″ ↩︎' ); - /* - These tests won't pass until https://core.trac.wordpress.org/ticket/20564 is committed - // Verify that the published post is unchanged. - // Navigate to the published post. + + // Verify that the published post is unchanged after previewing changes to meta. await previewPage2.close(); await editorPage.bringToFront(); await editor.openDocumentSettingsSidebar(); @@ -439,6 +437,5 @@ test.describe( 'Footnotes', () => { await expect( page.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( '1 ↩︎' ); - */ } ); } ); From a67bc451b2433407e9b4366beb3e3c374a74b000 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 26 Sep 2023 10:56:21 -0600 Subject: [PATCH 08/26] Global styles tests: fire hooks when updating post --- ...tenberg-rest-global-styles-revisions-controller-test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpunit/class-gutenberg-rest-global-styles-revisions-controller-test.php b/phpunit/class-gutenberg-rest-global-styles-revisions-controller-test.php index 77f95b2385a4ae..1b8e672fa78199 100644 --- a/phpunit/class-gutenberg-rest-global-styles-revisions-controller-test.php +++ b/phpunit/class-gutenberg-rest-global-styles-revisions-controller-test.php @@ -130,7 +130,7 @@ public static function wpSetupBeforeClass( $factory ) { ), ); - wp_update_post( $new_styles_post, true, false ); + wp_update_post( $new_styles_post, true, true ); $new_styles_post = array( 'ID' => self::$global_styles_id, @@ -160,7 +160,7 @@ public static function wpSetupBeforeClass( $factory ) { ), ); - wp_update_post( $new_styles_post, true, false ); + wp_update_post( $new_styles_post, true, true ); $new_styles_post = array( 'ID' => self::$global_styles_id, @@ -190,7 +190,7 @@ public static function wpSetupBeforeClass( $factory ) { ), ); - wp_update_post( $new_styles_post, true, false ); + wp_update_post( $new_styles_post, true, true ); wp_set_current_user( 0 ); } From 9b1115d61b90765d5158ca962d356c1e4479d918 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 26 Sep 2023 14:53:10 -0600 Subject: [PATCH 09/26] Improve published post navigation in test --- test/e2e/specs/editor/various/footnotes.spec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index eaeafc2c58438c..e3aa17c5a101cb 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -393,7 +393,7 @@ test.describe( 'Footnotes', () => { await page.keyboard.type( '1' ); // Publish post with the footnote set to "1". - await editor.publishPost(); + const postId = await editor.publishPost(); // Test previewing changes to meta. await editor.canvas.click( 'ol.wp-block-footnotes li span' ); @@ -431,7 +431,9 @@ test.describe( 'Footnotes', () => { .getByRole( 'region', { name: 'Editor settings' } ) .getByRole( 'button', { name: 'Post' } ) .click(); - await page.locator( 'a:text("View Post")' ).click(); + + // Visit the published post. + await page.goto( `/?p=${ postId }` ); // Verify that the published post footnote still says "1". await expect( page.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( From 037eb5af6fa1aa72766c6f8d75502e8cc51f803e Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 26 Sep 2023 15:18:26 -0600 Subject: [PATCH 10/26] Comment out failing test for published post --- test/e2e/specs/editor/various/footnotes.spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index e3aa17c5a101cb..97954f2a4b3010 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -393,7 +393,8 @@ test.describe( 'Footnotes', () => { await page.keyboard.type( '1' ); // Publish post with the footnote set to "1". - const postId = await editor.publishPost(); + // const postId = await editor.publishPost(); + await editor.publishPost(); // Test previewing changes to meta. await editor.canvas.click( 'ol.wp-block-footnotes li span' ); @@ -423,6 +424,8 @@ test.describe( 'Footnotes', () => { previewPage2.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( '123″ ↩︎' ); + // This section only passes when previewing doesn't overwrite published meta. + /* // Verify that the published post is unchanged after previewing changes to meta. await previewPage2.close(); await editorPage.bringToFront(); @@ -439,5 +442,6 @@ test.describe( 'Footnotes', () => { await expect( page.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( '1 ↩︎' ); + */ } ); } ); From 766a77744b5ac8055d0cd6cc18abc6b4953f9313 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 26 Sep 2023 15:35:27 -0600 Subject: [PATCH 11/26] Remove incorrect comment line --- packages/block-library/src/footnotes/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index 58f1e86468fb1b..f06a411571f2bb 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -9,7 +9,6 @@ * Renders the `core/footnotes` block on the server. * * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @param array $attributes Block attributes. * @param string $content Block default content. From cb37c4870827f17deb91b8964100cda679022483 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 27 Sep 2023 08:00:48 -0600 Subject: [PATCH 12/26] Try: remove filters present in core already --- .../block-library/src/footnotes/index.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index f06a411571f2bb..17121427e753e1 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -106,8 +106,13 @@ function wp_save_footnotes_meta( $revision_id ) { } if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ); +} else { + if ( has_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ) ) { + remove_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ); + } } + /** * Keeps track of the revision ID for "rest_after_insert_{$post_type}". * @@ -124,6 +129,10 @@ function wp_keep_footnotes_revision_id( $revision_id ) { } if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); +} else { + if ( has_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ) ) { + remove_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); + } } /** @@ -171,6 +180,13 @@ function wp_add_footnotes_revisions_to_post_meta( $post ) { if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ); add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' ); +} else { + if ( has_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ) ) { + remove_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ); + } + if ( has_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' ) ) { + remove_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' ); + } } /** @@ -193,6 +209,10 @@ function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { } if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 ); +} else { + if ( has_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision' ) ) { + remove_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision' ); + } } /** @@ -266,6 +286,13 @@ function _wp_rest_api_autosave_meta( $autosave ) { // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398. // Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367. add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); +} else { + if ( has_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ) ) { + remove_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); + } + if ( has_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ) ) { + remove_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); + } } /** @@ -303,4 +330,8 @@ function _wp_rest_api_force_autosave_difference( $prepared_post, $request ) { } if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 ); +} else { + if ( has_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ) ) { + remove_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ); + } } From c580c7946b3f14b0f376d47ee4aa7957b6c4fa6b Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 27 Sep 2023 10:39:14 -0600 Subject: [PATCH 13/26] Move footnote filter shim to an external compat file --- lib/compat/plugin/footnotes.php | 34 +++++++++++++++++++ lib/load.php | 1 + .../block-library/src/footnotes/index.php | 30 ---------------- 3 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 lib/compat/plugin/footnotes.php diff --git a/lib/compat/plugin/footnotes.php b/lib/compat/plugin/footnotes.php new file mode 100644 index 00000000000000..3b1d5a69960d63 --- /dev/null +++ b/lib/compat/plugin/footnotes.php @@ -0,0 +1,34 @@ + Date: Wed, 27 Sep 2023 16:30:38 -0600 Subject: [PATCH 14/26] phpcbf --- lib/compat/plugin/footnotes.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/compat/plugin/footnotes.php b/lib/compat/plugin/footnotes.php index 3b1d5a69960d63..7699f3112560c4 100644 --- a/lib/compat/plugin/footnotes.php +++ b/lib/compat/plugin/footnotes.php @@ -5,7 +5,10 @@ * See https://github.com/WordPress/gutenberg/pull/52988. * * Once merged, this shim can be removed. + * + * @package gutenberg */ + if ( function_exists( 'wp_post_revision_meta_keys' ) ) { if ( has_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ) ) { remove_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ); @@ -31,4 +34,4 @@ if ( has_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ) ) { remove_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ); } -} \ No newline at end of file +} From 9d2f1200f8b9030581e89904dfcf084dfe251d29 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 27 Sep 2023 17:14:37 -0600 Subject: [PATCH 15/26] Remove remaining hooks from footnotes that are causing issues --- lib/compat/plugin/footnotes.php | 6 ++++++ packages/block-library/src/footnotes/index.php | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/compat/plugin/footnotes.php b/lib/compat/plugin/footnotes.php index 7699f3112560c4..915e554cea7ae2 100644 --- a/lib/compat/plugin/footnotes.php +++ b/lib/compat/plugin/footnotes.php @@ -34,4 +34,10 @@ if ( has_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ) ) { remove_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ); } + if ( has_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision' ) ) { + remove_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision' ); + } + if ( has_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' ) ) { + remove_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' ); + } } diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index dfe6336b0929d2..f8b5f6248a4d46 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -200,6 +200,7 @@ function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { * Adds the footnotes field to the revisions display. * * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @param array $fields The revision fields. * @return array The revision fields. @@ -208,12 +209,15 @@ function wp_add_footnotes_to_revision( $fields ) { $fields['footnotes'] = __( 'Footnotes' ); return $fields; } -add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' ); +if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' ); +} /** * Gets the footnotes field from the revision for the revisions screen. * * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @param string $revision_field The field value, but $revision->$field * (footnotes) does not exist. @@ -224,7 +228,9 @@ function wp_add_footnotes_to_revision( $fields ) { function wp_get_footnotes_from_revision( $revision_field, $field, $revision ) { return get_metadata( 'post', $revision->ID, $field, true ); } -add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 ); +if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 ); +} /** * The REST API autosave endpoint doesn't save meta, so we can use the From 1109df25763c6e65545c37eddae06aa555ea36ce Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 28 Sep 2023 07:53:57 -0600 Subject: [PATCH 16/26] Revert "Remove remaining hooks from footnotes that are causing issues" This reverts commit 9d2f1200f8b9030581e89904dfcf084dfe251d29. --- lib/compat/plugin/footnotes.php | 6 ------ packages/block-library/src/footnotes/index.php | 10 ++-------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/compat/plugin/footnotes.php b/lib/compat/plugin/footnotes.php index 915e554cea7ae2..7699f3112560c4 100644 --- a/lib/compat/plugin/footnotes.php +++ b/lib/compat/plugin/footnotes.php @@ -34,10 +34,4 @@ if ( has_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ) ) { remove_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ); } - if ( has_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision' ) ) { - remove_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision' ); - } - if ( has_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' ) ) { - remove_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' ); - } } diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index f8b5f6248a4d46..dfe6336b0929d2 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -200,7 +200,6 @@ function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { * Adds the footnotes field to the revisions display. * * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @param array $fields The revision fields. * @return array The revision fields. @@ -209,15 +208,12 @@ function wp_add_footnotes_to_revision( $fields ) { $fields['footnotes'] = __( 'Footnotes' ); return $fields; } -if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' ); -} +add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' ); /** * Gets the footnotes field from the revision for the revisions screen. * * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. * * @param string $revision_field The field value, but $revision->$field * (footnotes) does not exist. @@ -228,9 +224,7 @@ function wp_add_footnotes_to_revision( $fields ) { function wp_get_footnotes_from_revision( $revision_field, $field, $revision ) { return get_metadata( 'post', $revision->ID, $field, true ); } -if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 ); -} +add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 ); /** * The REST API autosave endpoint doesn't save meta, so we can use the From 7fee4f57a752fa4af44eda471a2027b927196106 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 28 Sep 2023 10:45:51 -0600 Subject: [PATCH 17/26] Temporarily disable slashing test --- test/e2e/specs/editor/various/footnotes.spec.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index 97954f2a4b3010..48f9f1eee1df7e 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -415,14 +415,20 @@ test.describe( 'Footnotes', () => { await editor.canvas.click( 'ol.wp-block-footnotes li span' ); await page.keyboard.press( 'End' ); // Test slashing. - await page.keyboard.type( '3"' ); + // await page.keyboard.type( '3"' ); + // await page.keyboard.type( '3' ); const previewPage2 = await editor.openPreviewPage(); // Note: quote will get curled by wptexturize. + /* await expect( previewPage2.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( '123″ ↩︎' ); + */ + await expect( + previewPage2.locator( 'ol.wp-block-footnotes li' ) + ).toHaveText( '123 ↩︎' ); // This section only passes when previewing doesn't overwrite published meta. /* From 2a550846b6ba601d1a0554c8e15ee8c4dfe84e9e Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 28 Sep 2023 10:46:57 -0600 Subject: [PATCH 18/26] Restore test to verify that the published post is unchanged after previewing changes to meta. --- test/e2e/specs/editor/various/footnotes.spec.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index 48f9f1eee1df7e..acb8e7848bdeec 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -393,8 +393,7 @@ test.describe( 'Footnotes', () => { await page.keyboard.type( '1' ); // Publish post with the footnote set to "1". - // const postId = await editor.publishPost(); - await editor.publishPost(); + const postId = await editor.publishPost(); // Test previewing changes to meta. await editor.canvas.click( 'ol.wp-block-footnotes li span' ); @@ -431,7 +430,6 @@ test.describe( 'Footnotes', () => { ).toHaveText( '123 ↩︎' ); // This section only passes when previewing doesn't overwrite published meta. - /* // Verify that the published post is unchanged after previewing changes to meta. await previewPage2.close(); await editorPage.bringToFront(); @@ -448,6 +446,5 @@ test.describe( 'Footnotes', () => { await expect( page.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( '1 ↩︎' ); - */ } ); } ); From 352bba54e473c9e4ad832d41a0eb6696ca770ccd Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 28 Sep 2023 10:52:12 -0600 Subject: [PATCH 19/26] Move the meta revision compat code to the footnotes shim file This preveents the code from being included in core. This code can be removed once GB no longer supports core < 6.4. --- lib/compat/plugin/footnotes.php | 199 ++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/lib/compat/plugin/footnotes.php b/lib/compat/plugin/footnotes.php index 7699f3112560c4..7e26ca11a52702 100644 --- a/lib/compat/plugin/footnotes.php +++ b/lib/compat/plugin/footnotes.php @@ -9,6 +9,9 @@ * @package gutenberg */ +/** + * Remove footnote revision hooks when plugin is running on a version of core that already supports meta revisions. + */ if ( function_exists( 'wp_post_revision_meta_keys' ) ) { if ( has_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ) ) { remove_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ); @@ -34,4 +37,200 @@ if ( has_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ) ) { remove_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ); } +} else { + /** + * For versions of core that don't support meta revisions, use hooks to add. + */ + + /** + * Saves the footnotes meta value to the revision. + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @param int $revision_id The revision ID. + */ + function wp_save_footnotes_meta( $revision_id ) { + $post_id = wp_is_post_revision( $revision_id ); + + if ( $post_id ) { + $footnotes = get_post_meta( $post_id, 'footnotes', true ); + + if ( $footnotes ) { + // Can't use update_post_meta() because it doesn't allow revisions. + update_metadata( 'post', $revision_id, 'footnotes', wp_slash( $footnotes ) ); + } + } + } + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ); + } + + + /** + * Keeps track of the revision ID for "rest_after_insert_{$post_type}". + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @global int $wp_temporary_footnote_revision_id The footnote revision ID. + * + * @param int $revision_id The revision ID. + */ + function wp_keep_footnotes_revision_id( $revision_id ) { + global $wp_temporary_footnote_revision_id; + $wp_temporary_footnote_revision_id = $revision_id; + } + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); + } + + /** + * This is a specific fix for the REST API. The REST API doesn't update + * the post and post meta in one go (through `meta_input`). While it + * does fix the `wp_after_insert_post` hook to be called correctly after + * updating meta, it does NOT fix hooks such as post_updated and + * save_post, which are normally also fired after post meta is updated + * in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is + * added to the `post_updated` action, which means the meta is not + * available at the time, so we have to add it afterwards through the + * `"rest_after_insert_{$post_type}"` action. + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @global int $wp_temporary_footnote_revision_id The footnote revision ID. + * + * @param WP_Post $post The post object. + */ + function wp_add_footnotes_revisions_to_post_meta( $post ) { + global $wp_temporary_footnote_revision_id; + + if ( $wp_temporary_footnote_revision_id ) { + $revision = get_post( $wp_temporary_footnote_revision_id ); + + if ( ! $revision ) { + return; + } + + $post_id = $revision->post_parent; + + // Just making sure we're updating the right revision. + if ( $post->ID === $post_id ) { + $footnotes = get_post_meta( $post_id, 'footnotes', true ); + + if ( $footnotes ) { + // Can't use update_post_meta() because it doesn't allow revisions. + update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', wp_slash( $footnotes ) ); + } + } + } + } + + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ); + add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' ); + } + + /** + * Restores the footnotes meta value from the revision. + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @param int $post_id The post ID. + * @param int $revision_id The revision ID. + */ + function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { + $footnotes = get_post_meta( $revision_id, 'footnotes', true ); + + if ( $footnotes ) { + update_post_meta( $post_id, 'footnotes', wp_slash( $footnotes ) ); + } else { + delete_post_meta( $post_id, 'footnotes' ); + } + } + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 ); + } + + /** + * The REST API autosave endpoint doesn't save meta, so we can use the + * `wp_creating_autosave` when it updates an exiting autosave, and + * `_wp_put_post_revision` when it creates a new autosave. + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @param int|array $autosave The autosave ID or array. + */ + function _wp_rest_api_autosave_meta( $autosave ) { + // Ensure it's a REST API request. + if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) { + return; + } + + $body = rest_get_server()->get_raw_data(); + $body = json_decode( $body, true ); + + if ( ! isset( $body['meta']['footnotes'] ) ) { + return; + } + + // `wp_creating_autosave` passes the array, + // `_wp_put_post_revision` passes the ID. + $id = is_int( $autosave ) ? $autosave : $autosave['ID']; + + if ( ! $id ) { + return; + } + + // Can't use update_post_meta() because it doesn't allow revisions. + update_metadata( 'post', $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) ); + } + + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1. + add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); + // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398. + // Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367. + add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); + } + + /** + * This is a workaround for the autosave endpoint returning early if the + * revision field are equal. The problem is that "footnotes" is not real + * revision post field, so there's nothing to compare against. + * + * This trick sets the "footnotes" field (value doesn't matter), which will + * cause the autosave endpoint to always update the latest revision. That should + * be fine, it should be ok to update the revision even if nothing changed. Of + * course, this is temporary fix. + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @param WP_Post $prepared_post The prepared post object. + * @param WP_REST_Request $request The request object. + * + * See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L365-L384. + * See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L219. + */ + function _wp_rest_api_force_autosave_difference( $prepared_post, $request ) { + // We only want to be altering POST requests. + if ( $request->get_method() !== 'POST' ) { + return $prepared_post; + } + + // Only alter requests for the '/autosaves' route. + if ( substr( $request->get_route(), -strlen( '/autosaves' ) ) !== '/autosaves' ) { + return $prepared_post; + } + + $prepared_post->footnotes = '[]'; + return $prepared_post; + } + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 ); + } } From de6882c218d00ef99b2888d5cbeb51f9a7e6a4d0 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 28 Sep 2023 11:16:03 -0600 Subject: [PATCH 20/26] remove hooks from footnotes file --- .../block-library/src/footnotes/index.php | 190 ------------------ 1 file changed, 190 deletions(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index dfe6336b0929d2..1d5d16ebb8f2b0 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -84,118 +84,6 @@ function register_block_core_footnotes() { } add_action( 'init', 'register_block_core_footnotes' ); -/** - * Saves the footnotes meta value to the revision. - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @param int $revision_id The revision ID. - */ -function wp_save_footnotes_meta( $revision_id ) { - $post_id = wp_is_post_revision( $revision_id ); - - if ( $post_id ) { - $footnotes = get_post_meta( $post_id, 'footnotes', true ); - - if ( $footnotes ) { - // Can't use update_post_meta() because it doesn't allow revisions. - update_metadata( 'post', $revision_id, 'footnotes', wp_slash( $footnotes ) ); - } - } -} -if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ); -} - - -/** - * Keeps track of the revision ID for "rest_after_insert_{$post_type}". - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @global int $wp_temporary_footnote_revision_id The footnote revision ID. - * - * @param int $revision_id The revision ID. - */ -function wp_keep_footnotes_revision_id( $revision_id ) { - global $wp_temporary_footnote_revision_id; - $wp_temporary_footnote_revision_id = $revision_id; -} -if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); -} - -/** - * This is a specific fix for the REST API. The REST API doesn't update - * the post and post meta in one go (through `meta_input`). While it - * does fix the `wp_after_insert_post` hook to be called correctly after - * updating meta, it does NOT fix hooks such as post_updated and - * save_post, which are normally also fired after post meta is updated - * in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is - * added to the `post_updated` action, which means the meta is not - * available at the time, so we have to add it afterwards through the - * `"rest_after_insert_{$post_type}"` action. - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @global int $wp_temporary_footnote_revision_id The footnote revision ID. - * - * @param WP_Post $post The post object. - */ -function wp_add_footnotes_revisions_to_post_meta( $post ) { - global $wp_temporary_footnote_revision_id; - - if ( $wp_temporary_footnote_revision_id ) { - $revision = get_post( $wp_temporary_footnote_revision_id ); - - if ( ! $revision ) { - return; - } - - $post_id = $revision->post_parent; - - // Just making sure we're updating the right revision. - if ( $post->ID === $post_id ) { - $footnotes = get_post_meta( $post_id, 'footnotes', true ); - - if ( $footnotes ) { - // Can't use update_post_meta() because it doesn't allow revisions. - update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', wp_slash( $footnotes ) ); - } - } - } -} - -if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ); - add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' ); -} - -/** - * Restores the footnotes meta value from the revision. - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @param int $post_id The post ID. - * @param int $revision_id The revision ID. - */ -function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { - $footnotes = get_post_meta( $revision_id, 'footnotes', true ); - - if ( $footnotes ) { - update_post_meta( $post_id, 'footnotes', wp_slash( $footnotes ) ); - } else { - delete_post_meta( $post_id, 'footnotes' ); - } -} -if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 ); -} - /** * Adds the footnotes field to the revisions display. * @@ -226,82 +114,4 @@ function wp_get_footnotes_from_revision( $revision_field, $field, $revision ) { } add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 ); -/** - * The REST API autosave endpoint doesn't save meta, so we can use the - * `wp_creating_autosave` when it updates an exiting autosave, and - * `_wp_put_post_revision` when it creates a new autosave. - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @param int|array $autosave The autosave ID or array. - */ -function _wp_rest_api_autosave_meta( $autosave ) { - // Ensure it's a REST API request. - if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) { - return; - } - - $body = rest_get_server()->get_raw_data(); - $body = json_decode( $body, true ); - if ( ! isset( $body['meta']['footnotes'] ) ) { - return; - } - - // `wp_creating_autosave` passes the array, - // `_wp_put_post_revision` passes the ID. - $id = is_int( $autosave ) ? $autosave : $autosave['ID']; - - if ( ! $id ) { - return; - } - - // Can't use update_post_meta() because it doesn't allow revisions. - update_metadata( 'post', $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) ); -} - -if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1. - add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); - // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398. - // Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367. - add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); -} - -/** - * This is a workaround for the autosave endpoint returning early if the - * revision field are equal. The problem is that "footnotes" is not real - * revision post field, so there's nothing to compare against. - * - * This trick sets the "footnotes" field (value doesn't matter), which will - * cause the autosave endpoint to always update the latest revision. That should - * be fine, it should be ok to update the revision even if nothing changed. Of - * course, this is temporary fix. - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @param WP_Post $prepared_post The prepared post object. - * @param WP_REST_Request $request The request object. - * - * See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L365-L384. - * See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L219. - */ -function _wp_rest_api_force_autosave_difference( $prepared_post, $request ) { - // We only want to be altering POST requests. - if ( $request->get_method() !== 'POST' ) { - return $prepared_post; - } - - // Only alter requests for the '/autosaves' route. - if ( substr( $request->get_route(), -strlen( '/autosaves' ) ) !== '/autosaves' ) { - return $prepared_post; - } - - $prepared_post->footnotes = '[]'; - return $prepared_post; -} -if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 ); -} From 95f6b424e67450ad2c86009619d907c6cfdb38b6 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 28 Sep 2023 11:18:53 -0600 Subject: [PATCH 21/26] Ensure functions are guarded against redeclaration. --- lib/compat/plugin/footnotes.php | 332 +++++++++++++++++--------------- 1 file changed, 173 insertions(+), 159 deletions(-) diff --git a/lib/compat/plugin/footnotes.php b/lib/compat/plugin/footnotes.php index 7e26ca11a52702..b5c13f562b1eba 100644 --- a/lib/compat/plugin/footnotes.php +++ b/lib/compat/plugin/footnotes.php @@ -41,196 +41,210 @@ /** * For versions of core that don't support meta revisions, use hooks to add. */ + if ( ! function_exists( 'wp_save_footnotes_meta' ) ) { + /** + * Saves the footnotes meta value to the revision. + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @param int $revision_id The revision ID. + */ + function wp_save_footnotes_meta( $revision_id ) { + $post_id = wp_is_post_revision( $revision_id ); + + if ( $post_id ) { + $footnotes = get_post_meta( $post_id, 'footnotes', true ); - /** - * Saves the footnotes meta value to the revision. - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @param int $revision_id The revision ID. - */ - function wp_save_footnotes_meta( $revision_id ) { - $post_id = wp_is_post_revision( $revision_id ); - - if ( $post_id ) { - $footnotes = get_post_meta( $post_id, 'footnotes', true ); - - if ( $footnotes ) { - // Can't use update_post_meta() because it doesn't allow revisions. - update_metadata( 'post', $revision_id, 'footnotes', wp_slash( $footnotes ) ); + if ( $footnotes ) { + // Can't use update_post_meta() because it doesn't allow revisions. + update_metadata( 'post', $revision_id, 'footnotes', wp_slash( $footnotes ) ); + } } } + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ); + } } - if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ); - } - - /** - * Keeps track of the revision ID for "rest_after_insert_{$post_type}". - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @global int $wp_temporary_footnote_revision_id The footnote revision ID. - * - * @param int $revision_id The revision ID. - */ - function wp_keep_footnotes_revision_id( $revision_id ) { - global $wp_temporary_footnote_revision_id; - $wp_temporary_footnote_revision_id = $revision_id; - } - if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); + if ( ! function_exists( 'wp_keep_footnotes_revision_id' ) ) { + /** + * Keeps track of the revision ID for "rest_after_insert_{$post_type}". + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @global int $wp_temporary_footnote_revision_id The footnote revision ID. + * + * @param int $revision_id The revision ID. + */ + function wp_keep_footnotes_revision_id( $revision_id ) { + global $wp_temporary_footnote_revision_id; + $wp_temporary_footnote_revision_id = $revision_id; + } + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); + } } - /** - * This is a specific fix for the REST API. The REST API doesn't update - * the post and post meta in one go (through `meta_input`). While it - * does fix the `wp_after_insert_post` hook to be called correctly after - * updating meta, it does NOT fix hooks such as post_updated and - * save_post, which are normally also fired after post meta is updated - * in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is - * added to the `post_updated` action, which means the meta is not - * available at the time, so we have to add it afterwards through the - * `"rest_after_insert_{$post_type}"` action. - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @global int $wp_temporary_footnote_revision_id The footnote revision ID. - * - * @param WP_Post $post The post object. - */ - function wp_add_footnotes_revisions_to_post_meta( $post ) { - global $wp_temporary_footnote_revision_id; - - if ( $wp_temporary_footnote_revision_id ) { - $revision = get_post( $wp_temporary_footnote_revision_id ); - - if ( ! $revision ) { - return; - } + if ( ! function_exists( 'wp_add_footnotes_revisions_to_post_meta' ) { + + /** + * This is a specific fix for the REST API. The REST API doesn't update + * the post and post meta in one go (through `meta_input`). While it + * does fix the `wp_after_insert_post` hook to be called correctly after + * updating meta, it does NOT fix hooks such as post_updated and + * save_post, which are normally also fired after post meta is updated + * in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is + * added to the `post_updated` action, which means the meta is not + * available at the time, so we have to add it afterwards through the + * `"rest_after_insert_{$post_type}"` action. + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @global int $wp_temporary_footnote_revision_id The footnote revision ID. + * + * @param WP_Post $post The post object. + */ + function wp_add_footnotes_revisions_to_post_meta( $post ) { + global $wp_temporary_footnote_revision_id; + + if ( $wp_temporary_footnote_revision_id ) { + $revision = get_post( $wp_temporary_footnote_revision_id ); + + if ( ! $revision ) { + return; + } - $post_id = $revision->post_parent; + $post_id = $revision->post_parent; - // Just making sure we're updating the right revision. - if ( $post->ID === $post_id ) { - $footnotes = get_post_meta( $post_id, 'footnotes', true ); + // Just making sure we're updating the right revision. + if ( $post->ID === $post_id ) { + $footnotes = get_post_meta( $post_id, 'footnotes', true ); - if ( $footnotes ) { - // Can't use update_post_meta() because it doesn't allow revisions. - update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', wp_slash( $footnotes ) ); + if ( $footnotes ) { + // Can't use update_post_meta() because it doesn't allow revisions. + update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', wp_slash( $footnotes ) ); + } } } } - } - if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ); - add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' ); + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ); + add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' ); + } } - /** - * Restores the footnotes meta value from the revision. - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @param int $post_id The post ID. - * @param int $revision_id The revision ID. - */ - function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { - $footnotes = get_post_meta( $revision_id, 'footnotes', true ); + if ( ! function_exists( 'wp_restore_footnotes_from_revision' ) { - if ( $footnotes ) { - update_post_meta( $post_id, 'footnotes', wp_slash( $footnotes ) ); - } else { - delete_post_meta( $post_id, 'footnotes' ); + /** + * Restores the footnotes meta value from the revision. + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @param int $post_id The post ID. + * @param int $revision_id The revision ID. + */ + function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { + $footnotes = get_post_meta( $revision_id, 'footnotes', true ); + + if ( $footnotes ) { + update_post_meta( $post_id, 'footnotes', wp_slash( $footnotes ) ); + } else { + delete_post_meta( $post_id, 'footnotes' ); + } + } + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 ); } - } - if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 ); } - /** - * The REST API autosave endpoint doesn't save meta, so we can use the - * `wp_creating_autosave` when it updates an exiting autosave, and - * `_wp_put_post_revision` when it creates a new autosave. - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @param int|array $autosave The autosave ID or array. - */ - function _wp_rest_api_autosave_meta( $autosave ) { - // Ensure it's a REST API request. - if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) { - return; - } + if ( ! function_exists( '_wp_rest_api_autosave_meta' ) ) { + + /** + * The REST API autosave endpoint doesn't save meta, so we can use the + * `wp_creating_autosave` when it updates an exiting autosave, and + * `_wp_put_post_revision` when it creates a new autosave. + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @param int|array $autosave The autosave ID or array. + */ + function _wp_rest_api_autosave_meta( $autosave ) { + // Ensure it's a REST API request. + if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) { + return; + } - $body = rest_get_server()->get_raw_data(); - $body = json_decode( $body, true ); + $body = rest_get_server()->get_raw_data(); + $body = json_decode( $body, true ); - if ( ! isset( $body['meta']['footnotes'] ) ) { - return; - } + if ( ! isset( $body['meta']['footnotes'] ) ) { + return; + } - // `wp_creating_autosave` passes the array, - // `_wp_put_post_revision` passes the ID. - $id = is_int( $autosave ) ? $autosave : $autosave['ID']; + // `wp_creating_autosave` passes the array, + // `_wp_put_post_revision` passes the ID. + $id = is_int( $autosave ) ? $autosave : $autosave['ID']; - if ( ! $id ) { - return; + if ( ! $id ) { + return; + } + + // Can't use update_post_meta() because it doesn't allow revisions. + update_metadata( 'post', $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) ); } - // Can't use update_post_meta() because it doesn't allow revisions. - update_metadata( 'post', $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) ); + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1. + add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); + // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398. + // Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367. + add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); + } } - if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1. - add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); - // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398. - // Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367. - add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); - } + if ( ! function_exists( '_wp_rest_api_force_autosave_difference' ) ) { + + /** + * This is a workaround for the autosave endpoint returning early if the + * revision field are equal. The problem is that "footnotes" is not real + * revision post field, so there's nothing to compare against. + * + * This trick sets the "footnotes" field (value doesn't matter), which will + * cause the autosave endpoint to always update the latest revision. That should + * be fine, it should be ok to update the revision even if nothing changed. Of + * course, this is temporary fix. + * + * @since 6.3.0 + * @since 6.4.0 Core added post meta revisions, so this is no longer needed. + * + * @param WP_Post $prepared_post The prepared post object. + * @param WP_REST_Request $request The request object. + * + * See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L365-L384. + * See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L219. + */ + function _wp_rest_api_force_autosave_difference( $prepared_post, $request ) { + // We only want to be altering POST requests. + if ( $request->get_method() !== 'POST' ) { + return $prepared_post; + } - /** - * This is a workaround for the autosave endpoint returning early if the - * revision field are equal. The problem is that "footnotes" is not real - * revision post field, so there's nothing to compare against. - * - * This trick sets the "footnotes" field (value doesn't matter), which will - * cause the autosave endpoint to always update the latest revision. That should - * be fine, it should be ok to update the revision even if nothing changed. Of - * course, this is temporary fix. - * - * @since 6.3.0 - * @since 6.4.0 Core added post meta revisions, so this is no longer needed. - * - * @param WP_Post $prepared_post The prepared post object. - * @param WP_REST_Request $request The request object. - * - * See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L365-L384. - * See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L219. - */ - function _wp_rest_api_force_autosave_difference( $prepared_post, $request ) { - // We only want to be altering POST requests. - if ( $request->get_method() !== 'POST' ) { - return $prepared_post; - } + // Only alter requests for the '/autosaves' route. + if ( substr( $request->get_route(), -strlen( '/autosaves' ) ) !== '/autosaves' ) { + return $prepared_post; + } - // Only alter requests for the '/autosaves' route. - if ( substr( $request->get_route(), -strlen( '/autosaves' ) ) !== '/autosaves' ) { + $prepared_post->footnotes = '[]'; return $prepared_post; } - - $prepared_post->footnotes = '[]'; - return $prepared_post; - } - if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { - add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 ); + if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { + add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 ); + } } } From a8e98f6f751f63a64874dc85173b761557c1a1c9 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 28 Sep 2023 11:35:47 -0600 Subject: [PATCH 22/26] phpcbf --- lib/compat/plugin/footnotes.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compat/plugin/footnotes.php b/lib/compat/plugin/footnotes.php index b5c13f562b1eba..a31a3d8e111e2c 100644 --- a/lib/compat/plugin/footnotes.php +++ b/lib/compat/plugin/footnotes.php @@ -87,7 +87,7 @@ function wp_keep_footnotes_revision_id( $revision_id ) { } } - if ( ! function_exists( 'wp_add_footnotes_revisions_to_post_meta' ) { + if ( ! function_exists( 'wp_add_footnotes_revisions_to_post_meta' ) ) { /** * This is a specific fix for the REST API. The REST API doesn't update @@ -137,7 +137,7 @@ function wp_add_footnotes_revisions_to_post_meta( $post ) { } } - if ( ! function_exists( 'wp_restore_footnotes_from_revision' ) { + if ( ! function_exists( 'wp_restore_footnotes_from_revision' ) ) { /** * Restores the footnotes meta value from the revision. @@ -162,7 +162,7 @@ function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { } } - if ( ! function_exists( '_wp_rest_api_autosave_meta' ) ) { + if ( ! function_exists( '_wp_rest_api_autosave_meta' ) ) { /** * The REST API autosave endpoint doesn't save meta, so we can use the From 90057fcbdf17e1dee706be5d2f4a092f8d799aea Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 28 Sep 2023 11:45:21 -0600 Subject: [PATCH 23/26] phpcbf2 --- lib/compat/plugin/footnotes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/plugin/footnotes.php b/lib/compat/plugin/footnotes.php index a31a3d8e111e2c..a14a7922b24a10 100644 --- a/lib/compat/plugin/footnotes.php +++ b/lib/compat/plugin/footnotes.php @@ -137,7 +137,7 @@ function wp_add_footnotes_revisions_to_post_meta( $post ) { } } - if ( ! function_exists( 'wp_restore_footnotes_from_revision' ) ) { + if ( ! function_exists( 'wp_restore_footnotes_from_revision' ) ) { /** * Restores the footnotes meta value from the revision. From c614958532786a416e4aa4cd7f59f8b6d5041286 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 28 Sep 2023 12:58:38 -0600 Subject: [PATCH 24/26] =?UTF-8?q?restore=20typing=20=E2=80=9C3=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/e2e/specs/editor/various/footnotes.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index acb8e7848bdeec..79c127e96b4c7f 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -415,7 +415,7 @@ test.describe( 'Footnotes', () => { await page.keyboard.press( 'End' ); // Test slashing. // await page.keyboard.type( '3"' ); - // await page.keyboard.type( '3' ); + await page.keyboard.type( '3' ); const previewPage2 = await editor.openPreviewPage(); From 90d747236ae3cd8f8c3b9c4257b2dbd907a40574 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 28 Sep 2023 13:01:16 -0600 Subject: [PATCH 25/26] remove extra space --- packages/block-library/src/footnotes/index.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index 1d5d16ebb8f2b0..84f8767fda5cfc 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -113,5 +113,3 @@ function wp_get_footnotes_from_revision( $revision_field, $field, $revision ) { return get_metadata( 'post', $revision->ID, $field, true ); } add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 ); - - From 6a4f28b89402798530d8224a1656774658a3d729 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 29 Sep 2023 09:10:45 -0600 Subject: [PATCH 26/26] Restore slashed data test --- test/e2e/specs/editor/various/footnotes.spec.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index 79c127e96b4c7f..e3aa17c5a101cb 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -414,22 +414,15 @@ test.describe( 'Footnotes', () => { await editor.canvas.click( 'ol.wp-block-footnotes li span' ); await page.keyboard.press( 'End' ); // Test slashing. - // await page.keyboard.type( '3"' ); - await page.keyboard.type( '3' ); + await page.keyboard.type( '3"' ); const previewPage2 = await editor.openPreviewPage(); // Note: quote will get curled by wptexturize. - /* await expect( previewPage2.locator( 'ol.wp-block-footnotes li' ) ).toHaveText( '123″ ↩︎' ); - */ - await expect( - previewPage2.locator( 'ol.wp-block-footnotes li' ) - ).toHaveText( '123 ↩︎' ); - // This section only passes when previewing doesn't overwrite published meta. // Verify that the published post is unchanged after previewing changes to meta. await previewPage2.close(); await editorPage.bringToFront();