Skip to content

Commit f7aa6fb

Browse files
Add: Footnotes support in core.
1 parent 5b46851 commit f7aa6fb

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/wp-includes/class-wp-post-type.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@ public function add_supports() {
669669
add_post_type_support( $this->name, $args );
670670
}
671671
}
672+
if ( post_type_supports( $this->name, 'editor' ) && post_type_supports( $this->name, 'custom-fields' ) && post_type_supports( $this->name, 'revisions' ) && ! post_type_supports( $this->name, 'footnotes' ) ) {
673+
add_post_type_support( $this->name, 'footnotes' );
674+
}
672675
unset( $this->supports );
673676
} elseif ( false !== $this->supports ) {
674677
// Add default features.

src/wp-includes/default-filters.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,9 @@
734734
// CPT wp_block custom postmeta field.
735735
add_action( 'init', 'wp_create_initial_post_meta' );
736736

737+
// Registers the footnotes meta field for post types that support it.
738+
add_action( 'init', '_wp_register_footnotes_meta_field', 100 );
739+
737740
// Include revisioned meta when considering whether a post revision has changed.
738741
add_filter( 'wp_save_post_revision_post_has_changed', 'wp_check_revisioned_meta_fields_have_changed', 10, 3 );
739742

src/wp-includes/post.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8150,3 +8150,38 @@ function wp_create_initial_post_meta() {
81508150
)
81518151
);
81528152
}
8153+
8154+
/**
8155+
* Registers the footnotes meta field for post types that support it.
8156+
*
8157+
* @internal
8158+
* @since 6.5.0
8159+
*
8160+
* @link https://github.com/WordPress/gutenberg/pull/57353
8161+
*/
8162+
function _wp_register_footnotes_meta_field() {
8163+
$post_types = get_post_types(
8164+
array(
8165+
'show_in_rest' => true,
8166+
'public' => true,
8167+
)
8168+
);
8169+
foreach ( $post_types as $post_type ) {
8170+
// Only register the meta field if the post type supports the editor, custom fields, and revisions.
8171+
if ( post_type_supports( $post_type, 'editor' ) && post_type_supports( $post_type, 'custom-fields' ) && post_type_supports( $post_type, 'revisions' ) && post_type_supports( $post_type, 'footnotes' ) ) {
8172+
$post_type_meta_keys = get_registered_meta_keys( 'post', $post_type );
8173+
if ( ! isset( $post_type_meta_keys['footnotes'] ) ) {
8174+
register_post_meta(
8175+
$post_type,
8176+
'footnotes',
8177+
array(
8178+
'show_in_rest' => true,
8179+
'single' => true,
8180+
'type' => 'string',
8181+
'revisions_enabled' => true,
8182+
)
8183+
);
8184+
}
8185+
}
8186+
}
8187+
}

0 commit comments

Comments
 (0)