From 2b017fcb4c158c6c8d12f119d7d4230cf2b51c83 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Fri, 9 Feb 2024 11:59:11 +0000 Subject: [PATCH 1/4] Update: Increate footnotes meta priority and separate footnotes meta registration from the block registration. --- .../block-library/src/footnotes/index.php | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index 0cd2ad73ef3d42..aa035215153cfa 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -68,6 +68,22 @@ function render_block_core_footnotes( $attributes, $content, $block ) { * @since 6.3.0 */ function register_block_core_footnotes() { + register_block_type_from_metadata( + __DIR__ . '/footnotes', + array( + 'render_callback' => 'render_block_core_footnotes', + ) + ); +} +add_action( 'init', 'register_block_core_footnotes' ); + + +/** + * Registers the footnotes meta field required for footnotes to work. + * + * @since 6.5.0 + */ +function wp_register_footnotes_post_meta() { $post_types = get_post_types( array( 'show_in_rest' => true, @@ -76,7 +92,11 @@ function register_block_core_footnotes() { ); 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' ) ) { + if ( + post_type_supports( $post_type, 'editor' ) && + post_type_supports( $post_type, 'custom-fields' ) && + post_type_supports( $post_type, 'revisions' ) + ) { register_post_meta( $post_type, 'footnotes', @@ -89,14 +109,9 @@ function register_block_core_footnotes() { ); } } - register_block_type_from_metadata( - __DIR__ . '/footnotes', - array( - 'render_callback' => 'render_block_core_footnotes', - ) - ); } -add_action( 'init', 'register_block_core_footnotes' ); +// Use a priority of 20 to be higher than the default of 10 the priority with which most post types are registered. +add_action( 'init', 'wp_register_footnotes_post_meta', 20 ); /** * Adds the footnotes field to the revisions display. From 6b0efec842962571a7340a1981c17e6db826b0a9 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Mon, 12 Feb 2024 21:15:07 +0000 Subject: [PATCH 2/4] Include footnotes on non public cpts --- packages/block-library/src/footnotes/index.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index aa035215153cfa..d287fc2ddb11fe 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -83,13 +83,8 @@ function register_block_core_footnotes() { * * @since 6.5.0 */ -function wp_register_footnotes_post_meta() { - $post_types = get_post_types( - array( - 'show_in_rest' => true, - 'public' => true, - ) - ); +function register_block_core_footnotes_post_meta() { + $post_types = get_post_types( array( 'show_in_rest' => true ) ); foreach ( $post_types as $post_type ) { // Only register the meta field if the post type supports the editor, custom fields, and revisions. if ( @@ -111,7 +106,7 @@ function wp_register_footnotes_post_meta() { } } // Use a priority of 20 to be higher than the default of 10 the priority with which most post types are registered. -add_action( 'init', 'wp_register_footnotes_post_meta', 20 ); +add_action( 'init', 'register_block_core_footnotes_post_meta', 20 ); /** * Adds the footnotes field to the revisions display. From 11f145a8fab40f882249a2f1bd78ca75da5b15cc Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Fri, 16 Feb 2024 10:59:55 +0000 Subject: [PATCH 3/4] Update packages/block-library/src/footnotes/index.php Co-authored-by: Miguel Fonseca <150562+mcsf@users.noreply.github.com> --- packages/block-library/src/footnotes/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index d287fc2ddb11fe..d5d95073a968ed 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -105,7 +105,8 @@ function register_block_core_footnotes_post_meta() { } } } -// Use a priority of 20 to be higher than the default of 10 the priority with which most post types are registered. +// Most post types are registered at priority 10, so use priority 20 here in +// order to catch them. add_action( 'init', 'register_block_core_footnotes_post_meta', 20 ); /** From a1973835f0683b241c5bfb9bc432e1bb15a3a880 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Fri, 16 Feb 2024 16:51:34 +0000 Subject: [PATCH 4/4] Update to use WordPress multiline comments. --- packages/block-library/src/footnotes/index.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index d5d95073a968ed..86eaf694add4ca 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -105,8 +105,10 @@ function register_block_core_footnotes_post_meta() { } } } -// Most post types are registered at priority 10, so use priority 20 here in -// order to catch them. +/** + * Most post types are registered at priority 10, so use priority 20 here in + * order to catch them. +*/ add_action( 'init', 'register_block_core_footnotes_post_meta', 20 ); /**