Make WordPress Core

Changeset 57731


Ignore:
Timestamp:
02/27/2024 09:03:54 PM (3 months ago)
Author:
joemcgill
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-patterns.php

    r57683 r57731  
    392392            }
    393393
    394             $pattern_data['file_path'] = $file_path;
     394            $pattern_data['filePath'] = $file_path;
    395395
    396396            // Translate the pattern metadata.
  • trunk/src/wp-includes/class-wp-block-patterns-registry.php

    r57683 r57731  
    4646     * @since 6.1.0 Added support for the `postTypes` property.
    4747     * @since 6.2.0 Added support for the `templateTypes` property.
     48     * @since 6.5.0 Added support for the `filePath` property.
    4849     *
    4950     * @param string $pattern_name       Block pattern name including namespace.
     
    5253     *
    5354     *     @type string   $title         Required. A human-readable title for the pattern.
    54      *     @type string   $content       Required. Block HTML markup for the pattern.
     55     *     @type string   $content       Optional. Block HTML markup for the pattern.
     56     *                                   If not provided, the content will be retrieved from the `filePath` if set.
     57     *                                   If both `content` and `filePath` are not set, the pattern will not be registered.
    5558     *     @type string   $description   Optional. Visually hidden text used to describe the pattern
    5659     *                                   in the inserter. A description is optional, but is strongly
     
    8083     *                                   not part of the array the pattern is not available at all.
    8184     *     @type string[] $templateTypes Optional. An array of template types where the pattern fits.
     85     *     @type string   $filePath      Optional. The full path to the file containing the block pattern content.
    8286     * }
    8387     * @return bool True if the pattern was registered with success and false otherwise.
     
    102106        }
    103107
    104         if ( ! isset( $pattern_properties['file_path'] ) ) {
     108        if ( ! isset( $pattern_properties['filePath'] ) ) {
    105109            if ( ! isset( $pattern_properties['content'] ) || ! is_string( $pattern_properties['content'] ) ) {
    106110                _doing_it_wrong(
     
    195199            $patterns = &$this->registered_patterns;
    196200        }
    197         if ( ! isset( $patterns[ $pattern_name ]['content'] ) && isset( $patterns[ $pattern_name ]['file_path'] ) ) {
     201        if ( ! isset( $patterns[ $pattern_name ]['content'] ) && isset( $patterns[ $pattern_name ]['filePath'] ) ) {
    198202            ob_start();
    199             include $patterns[ $pattern_name ]['file_path'];
     203            include $patterns[ $pattern_name ]['filePath'];
    200204            $patterns[ $pattern_name ]['content'] = ob_get_clean();
    201             unset( $patterns[ $pattern_name ]['file_path'] );
     205            unset( $patterns[ $pattern_name ]['filePath'] );
    202206        }
    203207        return $patterns[ $pattern_name ]['content'];
  • trunk/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php

    r57703 r57731  
    580580
    581581        $this->assertTrue(
    582             isset( $registered_patterns[ $pattern_name ]['file_path'] ) &&
     582            isset( $registered_patterns[ $pattern_name ]['filePath'] ) &&
    583583            ! isset( $registered_patterns[ $pattern_name ]['content'] ),
    584584            'Pattern was not lazy loaded.'
     
    634634
    635635        $this->assertTrue(
    636             isset( $registered_patterns[ $pattern_name ]['file_path'] ) &&
     636            isset( $registered_patterns[ $pattern_name ]['filePath'] ) &&
    637637            ! isset( $registered_patterns[ $pattern_name ]['content'] ),
    638638            'Pattern was not lazy loaded.'
Note: See TracChangeset for help on using the changeset viewer.