Skip to content

Add: Footnotes support in core. #6003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For multiple conditions i personally follow.

Suggested change
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' ) ) {
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' )
) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion 👍 I'm applying it at WordPress/gutenberg#58882.

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.
*
* @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' ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In src/wp-includes/class-wp-post-type.php, we have already added support for a specific post type. Why are we checking a similar condition here again?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for the check was that meanwhile, a plugin may have removed a support after the code in src/wp-includes/class-wp-post-type.php executed.

$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,
)
);
}
}
}
}