diff --git a/src/wp-includes/blocks/footnotes.php b/src/wp-includes/blocks/footnotes.php
index 5924db3a19..58f1e86468 100644
|
a
|
b
|
|
| 9 | 9 | * Renders the `core/footnotes` block on the server. |
| 10 | 10 | * |
| 11 | 11 | * @since 6.3.0 |
| | 12 | * @since 6.4.0 Core added post meta revisions, so this is no longer needed. |
| 12 | 13 | * |
| 13 | 14 | * @param array $attributes Block attributes. |
| 14 | 15 | * @param string $content Block default content. |
| … |
… |
function register_block_core_footnotes() { |
| 68 | 69 | $post_type, |
| 69 | 70 | 'footnotes', |
| 70 | 71 | array( |
| 71 | | 'show_in_rest' => true, |
| 72 | | 'single' => true, |
| 73 | | 'type' => 'string', |
| | 72 | 'show_in_rest' => true, |
| | 73 | 'single' => true, |
| | 74 | 'type' => 'string', |
| | 75 | 'revisions_enabled' => true, |
| 74 | 76 | ) |
| 75 | 77 | ); |
| 76 | 78 | } |
| … |
… |
add_action( 'init', 'register_block_core_footnotes' ); |
| 87 | 89 | * Saves the footnotes meta value to the revision. |
| 88 | 90 | * |
| 89 | 91 | * @since 6.3.0 |
| | 92 | * @since 6.4.0 Core added post meta revisions, so this is no longer needed. |
| 90 | 93 | * |
| 91 | 94 | * @param int $revision_id The revision ID. |
| 92 | 95 | */ |
| … |
… |
function wp_save_footnotes_meta( $revision_id ) { |
| 102 | 105 | } |
| 103 | 106 | } |
| 104 | 107 | } |
| 105 | | add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ); |
| | 108 | if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { |
| | 109 | add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ); |
| | 110 | } |
| 106 | 111 | |
| 107 | 112 | /** |
| 108 | 113 | * Keeps track of the revision ID for "rest_after_insert_{$post_type}". |
| 109 | 114 | * |
| 110 | 115 | * @since 6.3.0 |
| | 116 | * @since 6.4.0 Core added post meta revisions, so this is no longer needed. |
| 111 | 117 | * |
| 112 | 118 | * @global int $wp_temporary_footnote_revision_id The footnote revision ID. |
| 113 | 119 | * |
| … |
… |
function wp_keep_footnotes_revision_id( $revision_id ) { |
| 117 | 123 | global $wp_temporary_footnote_revision_id; |
| 118 | 124 | $wp_temporary_footnote_revision_id = $revision_id; |
| 119 | 125 | } |
| 120 | | add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); |
| | 126 | if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { |
| | 127 | add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); |
| | 128 | } |
| 121 | 129 | |
| 122 | 130 | /** |
| 123 | 131 | * This is a specific fix for the REST API. The REST API doesn't update |
| … |
… |
add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); |
| 131 | 139 | * `"rest_after_insert_{$post_type}"` action. |
| 132 | 140 | * |
| 133 | 141 | * @since 6.3.0 |
| | 142 | * @since 6.4.0 Core added post meta revisions, so this is no longer needed. |
| 134 | 143 | * |
| 135 | 144 | * @global int $wp_temporary_footnote_revision_id The footnote revision ID. |
| 136 | 145 | * |
| … |
… |
function wp_add_footnotes_revisions_to_post_meta( $post ) { |
| 160 | 169 | } |
| 161 | 170 | } |
| 162 | 171 | |
| 163 | | add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ); |
| 164 | | add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' ); |
| | 172 | if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { |
| | 173 | add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ); |
| | 174 | add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' ); |
| | 175 | } |
| 165 | 176 | |
| 166 | 177 | /** |
| 167 | 178 | * Restores the footnotes meta value from the revision. |
| 168 | 179 | * |
| 169 | 180 | * @since 6.3.0 |
| | 181 | * @since 6.4.0 Core added post meta revisions, so this is no longer needed. |
| 170 | 182 | * |
| 171 | 183 | * @param int $post_id The post ID. |
| 172 | 184 | * @param int $revision_id The revision ID. |
| … |
… |
function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { |
| 180 | 192 | delete_post_meta( $post_id, 'footnotes' ); |
| 181 | 193 | } |
| 182 | 194 | } |
| 183 | | add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 ); |
| | 195 | if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { |
| | 196 | add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 ); |
| | 197 | } |
| 184 | 198 | |
| 185 | 199 | /** |
| 186 | | * Adds the footnotes field to the revision. |
| | 200 | * Adds the footnotes field to the revisions display. |
| 187 | 201 | * |
| 188 | 202 | * @since 6.3.0 |
| 189 | 203 | * |
| … |
… |
function wp_add_footnotes_to_revision( $fields ) { |
| 197 | 211 | add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' ); |
| 198 | 212 | |
| 199 | 213 | /** |
| 200 | | * Gets the footnotes field from the revision. |
| | 214 | * Gets the footnotes field from the revision for the revisions screen. |
| 201 | 215 | * |
| 202 | 216 | * @since 6.3.0 |
| 203 | 217 | * |
| … |
… |
add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision |
| 218 | 232 | * `_wp_put_post_revision` when it creates a new autosave. |
| 219 | 233 | * |
| 220 | 234 | * @since 6.3.0 |
| | 235 | * @since 6.4.0 Core added post meta revisions, so this is no longer needed. |
| 221 | 236 | * |
| 222 | 237 | * @param int|array $autosave The autosave ID or array. |
| 223 | 238 | */ |
| … |
… |
function _wp_rest_api_autosave_meta( $autosave ) { |
| 242 | 257 | return; |
| 243 | 258 | } |
| 244 | 259 | |
| 245 | | update_post_meta( $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) ); |
| | 260 | // Can't use update_post_meta() because it doesn't allow revisions. |
| | 261 | update_metadata( 'post', $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) ); |
| | 262 | } |
| | 263 | |
| | 264 | if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { |
| | 265 | // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1. |
| | 266 | add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); |
| | 267 | // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398. |
| | 268 | // Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367. |
| | 269 | add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); |
| 246 | 270 | } |
| 247 | | // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1. |
| 248 | | add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); |
| 249 | | // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398. |
| 250 | | // Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367. |
| 251 | | add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); |
| 252 | 271 | |
| 253 | 272 | /** |
| 254 | 273 | * This is a workaround for the autosave endpoint returning early if the |
| … |
… |
add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); |
| 261 | 280 | * course, this is temporary fix. |
| 262 | 281 | * |
| 263 | 282 | * @since 6.3.0 |
| | 283 | * @since 6.4.0 Core added post meta revisions, so this is no longer needed. |
| 264 | 284 | * |
| 265 | 285 | * @param WP_Post $prepared_post The prepared post object. |
| 266 | 286 | * @param WP_REST_Request $request The request object. |
| … |
… |
function _wp_rest_api_force_autosave_difference( $prepared_post, $request ) { |
| 282 | 302 | $prepared_post->footnotes = '[]'; |
| 283 | 303 | return $prepared_post; |
| 284 | 304 | } |
| 285 | | |
| 286 | | add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 ); |
| | 305 | if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) { |
| | 306 | add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 ); |
| | 307 | } |