From 5f2e2f85f792272041327a7b9f36847e620fed07 Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Tue, 27 Feb 2024 21:05:11 +0000 Subject: [PATCH] Docs: Improve docblock for `WP_Block_Patterns_Registry::register`. This documents the new `filePath` property supported by `WP_Block_Patterns_Registry::register` and also updates the property name to camel case formatting to be consistent with other block pattern properties. Props thekt12, spacedmonkey, joemcgill. See #59532. Built from https://develop.svn.wordpress.org/trunk@57731 git-svn-id: http://core.svn.wordpress.org/trunk@57232 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-patterns.php | 2 +- wp-includes/class-wp-block-patterns-registry.php | 14 +++++++++----- wp-includes/version.php | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/wp-includes/block-patterns.php b/wp-includes/block-patterns.php index cb58d9842c..d672ffd900 100644 --- a/wp-includes/block-patterns.php +++ b/wp-includes/block-patterns.php @@ -391,7 +391,7 @@ function _register_theme_block_patterns() { continue; } - $pattern_data['file_path'] = $file_path; + $pattern_data['filePath'] = $file_path; // Translate the pattern metadata. // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain,WordPress.WP.I18n.LowLevelTranslationFunction diff --git a/wp-includes/class-wp-block-patterns-registry.php b/wp-includes/class-wp-block-patterns-registry.php index 1402819c84..bee9746da3 100644 --- a/wp-includes/class-wp-block-patterns-registry.php +++ b/wp-includes/class-wp-block-patterns-registry.php @@ -45,13 +45,16 @@ final class WP_Block_Patterns_Registry { * @since 5.8.0 Added support for the `blockTypes` property. * @since 6.1.0 Added support for the `postTypes` property. * @since 6.2.0 Added support for the `templateTypes` property. + * @since 6.5.0 Added support for the `filePath` property. * * @param string $pattern_name Block pattern name including namespace. * @param array $pattern_properties { * List of properties for the block pattern. * * @type string $title Required. A human-readable title for the pattern. - * @type string $content Required. Block HTML markup for the pattern. + * @type string $content Optional. Block HTML markup for the pattern. + * If not provided, the content will be retrieved from the `filePath` if set. + * If both `content` and `filePath` are not set, the pattern will not be registered. * @type string $description Optional. Visually hidden text used to describe the pattern * in the inserter. A description is optional, but is strongly * encouraged when the title does not fully describe what the @@ -79,6 +82,7 @@ final class WP_Block_Patterns_Registry { * of the post types passed on the array. For all the other post types * not part of the array the pattern is not available at all. * @type string[] $templateTypes Optional. An array of template types where the pattern fits. + * @type string $filePath Optional. The full path to the file containing the block pattern content. * } * @return bool True if the pattern was registered with success and false otherwise. */ @@ -101,7 +105,7 @@ final class WP_Block_Patterns_Registry { return false; } - if ( ! isset( $pattern_properties['file_path'] ) ) { + if ( ! isset( $pattern_properties['filePath'] ) ) { if ( ! isset( $pattern_properties['content'] ) || ! is_string( $pattern_properties['content'] ) ) { _doing_it_wrong( __METHOD__, @@ -194,11 +198,11 @@ final class WP_Block_Patterns_Registry { } else { $patterns = &$this->registered_patterns; } - if ( ! isset( $patterns[ $pattern_name ]['content'] ) && isset( $patterns[ $pattern_name ]['file_path'] ) ) { + if ( ! isset( $patterns[ $pattern_name ]['content'] ) && isset( $patterns[ $pattern_name ]['filePath'] ) ) { ob_start(); - include $patterns[ $pattern_name ]['file_path']; + include $patterns[ $pattern_name ]['filePath']; $patterns[ $pattern_name ]['content'] = ob_get_clean(); - unset( $patterns[ $pattern_name ]['file_path'] ); + unset( $patterns[ $pattern_name ]['filePath'] ); } return $patterns[ $pattern_name ]['content']; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 2316ed0a25..44892913b1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-beta3-57730'; +$wp_version = '6.5-beta3-57731'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.