From a1f1611372a09bcdf1c66b468077d3582454784e Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:26:18 +1100 Subject: [PATCH] Register footnotes related meta data. --- src/wp-includes/default-filters.php | 2 ++ src/wp-includes/post.php | 33 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 19a9285ed2fec..7b02e9b6305c0 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -733,6 +733,8 @@ // CPT wp_block custom postmeta field. add_action( 'init', 'wp_create_initial_post_meta' ); +// Registers the footnotes meta field for post types that support it. +add_action( 'init', 'wp_register_footnotes_meta_field', 100 ); // Include revisioned meta when considering whether a post revision has changed. add_filter( 'wp_save_post_revision_post_has_changed', 'wp_check_revisioned_meta_fields_have_changed', 10, 3 ); diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 21ebdef5c1f6f..21d6e54452bbd 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8252,3 +8252,36 @@ function wp_create_initial_post_meta() { ) ); } + +/** + * Registers the footnotes meta field for post types that support it. + * + * @since 6.5.0 + * + * @link https://github.com/WordPress/gutenberg/pull/57353 + */ +function wp_register_footnotes_meta_field() { + $post_types = get_post_types( array( 'show_in_rest' => true ) ); + $post_types = array_filter( $post_types, 'is_post_type_viewable' ); + foreach ( $post_types as $post_type ) { + if ( ! post_type_supports( $post_type, 'footnotes' ) ) { + // Post type does not support footnotes, continue. + continue; + } + $post_type_meta_keys = get_registered_meta_keys( 'post', $post_type ); + if ( isset( $post_type_meta_keys['footnotes'] ) ) { + // Footnotes meta key is already registered, continue. + continue; + } + register_post_meta( + $post_type, + 'footnotes', + array( + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + 'revisions_enabled' => true, + ) + ); + } +}