Skip to content
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

Add: Footnotes support in core. #6003

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Feb 1, 2024

Core version of WordPress/gutenberg#58573.

Adds footnote support for custom post types in the core. Creates a new footnotes support key.
By default, every post that meets footnotes requirements has support for footnotes.
Developers can now remove footnotes support with:

remove_post_type_support( 'my_type', 'footnotes' );

Testing

Added the following post type:


function cptui_register_my_cpts_testfootnotes() {

	/**
	 * Post Type: Test foot notes.
	 */

	$labels = [
		"name" => esc_html__( "Test foot notes", "twentytwentyfour" ),
		"singular_name" => esc_html__( "Test foot note", "twentytwentyfour" ),
	];

	$args = [
		"label" => esc_html__( "Test foot notes", "twentytwentyfour" ),
		"labels" => $labels,
		"description" => "",
		"public" => true,
		"publicly_queryable" => true,
		"show_ui" => true,
		"show_in_rest" => true,
		"rest_base" => "",
		"rest_controller_class" => "WP_REST_Posts_Controller",
		"rest_namespace" => "wp/v2",
		"has_archive" => false,
		"show_in_menu" => true,
		"show_in_nav_menus" => true,
		"delete_with_user" => false,
		"exclude_from_search" => false,
		"capability_type" => "post",
		"map_meta_cap" => true,
		"hierarchical" => false,
		"can_export" => false,
		"rewrite" => [ "slug" => "testfootnotes", "with_front" => true ],
		"query_var" => true,
		"supports" => [ "title", "editor", "thumbnail", "custom-fields", "revisions" ],
		"show_in_graphql" => false,
	];

	register_post_type( "testfootnotes", $args );
}

add_action( 'init', 'cptui_register_my_cpts_testfootnotes' );

I have confirmed that the footnotes are functioning correctly on the specified post type.

Furthermore, I have removed the "custom-fields" support from the post type and confirmed that the footnotes are no longer available on the post type.

In addition, I have verified that remove_post_type_support( 'page', 'footnotes' ); successfully removes footnotes support from pages.

Copy link

github-actions bot commented Feb 1, 2024

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

);
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.

@@ -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.

@peterwilsoncc
Copy link
Contributor

Cross posting my change request from the Gutenberg PR WordPress/gutenberg#58573 (review) that I think it's best to make the footnotes opt in for CPTs.

Let's finalise the approach in the upstream repo rather than discussing in two PRs.

Copy link

github-actions bot commented Feb 2, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core SVN

If you're a Core Committer, use this list when committing to wordpress-develop in SVN:

Props: jorgefilipecosta, mukesh27, peterwilsoncc.

GitHub Merge commits

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: mukeshpanchal27 <mukesh27@git.wordpress.org>
Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@jorgefilipecosta
Copy link
Member Author

Closing this PR following @ellatrix suggestion at WordPress/gutenberg#58573 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants