Skip to content

Footnotes not detected on CPTs registered by plugins (in WordPress 6.5 wp-dev PR) #58341

Closed

Description

Description

The register_block_core_footnotes is currently hooked on the init action to run at the default priority of 10.

  1. This will miss CPTs registered late in the init action at priority 11 or higher
  2. In WordPress Core this will miss Custom Post Types (CPTs) registered by plugins using the default init priority as register_block_core_footnotes() runs before the action registered by the plugins.

When two actions are registered at the same priority, WordPress runs the actions in the order in which they are registered as each subsequent action is appended to the array.

In the released version of WordPress, the blocks are registered prior to plugins so the relevant portion of the WP_Hook instance is:

$GLOBALS['wp_filter']['init']['callbacks'][10] = [
    'register_block_core_footnotes',
    'my_plugin_register_cpts'  
]

Note

This portion of the bug may be suppressed when running the Gutenberg plugin due to the hook being registered by a plugin. Please check out WordPress/wordpress-develop#5922 to test the second part of this issue.

Suggested resolution

Run the register_block_core_footnotes later on the init action, I suggest at a priority of about 100 but that's pretty much a random number.

To maintain backward compatibility for plugins deactivating the footnotes block by running remove_action( 'init', 'register_block_core_footnotes' ); some juggling will be required.

Follow up to #57353.

cc @youknowriad @ellatrix @jorgefilipecosta

Step-by-step reproduction instructions

  1. Check out Editor: Initial WordPress package updates for 6.5 wordpress-develop#5922
  2. Ensure the Gutenberg plugin is disabled
  3. Activate the plugin in the code snippet below
  4. Visit Dashboard > CPT Supporting Footnotes > Add New Post
  5. Write some content and attempt to insert a footnote, they will be unavailable.

The same result will occur for Late CPT Supporting Footnotes

Screenshots, screen recording, code snippet

Plugin for testing

<?php
/**
 * Plugin Name: Testing CPT Footnotes
 */

namespace PWCC\TestingCptFootnotes;

add_action( 'init', __NAMESPACE__ . '\\register_cpts' );
add_action( 'init', __NAMESPACE__ . '\\late_register_cpts', 20 );

function register_cpts() {
	register_post_type(
		'cpt-with-footnotes',
		[
			'public' => true,
			'show_in_rest' => true,
			'labels' => [
				'name'          => 'CPT Supporting Footnotes',
				'singular_name' => 'CPT Supporting Footnote',
				'plural_name'   => 'CPTs Supporting Footnotes',
			],
			'supports' => [
				'title',
				'editor',
				'revisions',
				'custom-fields',
			],
		]
	);
}

function late_register_cpts() {
	register_post_type(
		'late-cpt-with-fns',
		[
			'public' => true,
			'show_in_rest' => true,
			'labels' => [
				'name'          => 'Late CPT Supporting Footnotes',
				'singular_name' => 'Late CPT Supporting Footnote',
				'plural_name'   => 'Late CPTs Supporting Footnotes',
			],
			'supports' => [
				'title',
				'editor',
				'revisions',
				'custom-fields',
			],
		]
	);
}

Environment info

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

[Block] FootnotesAffects the Footnotes Block[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions