Skip to content

Commit

Permalink
Add: Footnotes support in core.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Feb 1, 2024
1 parent 5b46851 commit f7aa6fb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/wp-includes/class-wp-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,9 @@ public function add_supports() {
add_post_type_support( $this->name, $args );
}
}
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' ) ) {
add_post_type_support( $this->name, 'footnotes' );
}
unset( $this->supports );
} elseif ( false !== $this->supports ) {
// Add default features.
Expand Down
3 changes: 3 additions & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,9 @@
// 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 );

Expand Down
35 changes: 35 additions & 0 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8150,3 +8150,38 @@ function wp_create_initial_post_meta() {
)
);
}

/**
* Registers the footnotes meta field for post types that support it.
*

Check failure on line 8156 in src/wp-includes/post.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
* @internal
* @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,
'public' => true,
)
);
foreach ( $post_types as $post_type ) {
// Only register the meta field if the post type supports the editor, custom fields, and revisions.
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' ) ) {
$post_type_meta_keys = get_registered_meta_keys( 'post', $post_type );
if ( ! isset( $post_type_meta_keys['footnotes'] ) ) {
register_post_meta(
$post_type,
'footnotes',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'revisions_enabled' => true,
)
);
}
}
}
}

Check failure on line 8187 in src/wp-includes/post.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 newline at end of file; 0 found

0 comments on commit f7aa6fb

Please sign in to comment.