Make WordPress Core

Changeset 60904


Ignore:
Timestamp:
10/06/2025 11:29:14 AM (4 months ago)
Author:
swissspidy
Message:

Code Modernization: Fix instances of using null as an array offset.

Addresses a new deprecation in PHP 8.5 in several block-related registry classes.

Follow-up to [60809].

Props mukesh27, swissspidy.
Fixes #63957.

Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-bindings-registry.php

    r60804 r60904  
    250250     * @since 6.5.0
    251251     *
    252      * @param string $source_name The name of the source.
     252     * @param string|null $source_name The name of the source.
    253253     * @return bool `true` if the block bindings source is registered, `false` otherwise.
    254254     */
    255255    public function is_registered( $source_name ) {
    256         return isset( $this->sources[ $source_name ] );
     256        return isset( $source_name, $this->sources[ $source_name ] );
    257257    }
    258258
  • trunk/src/wp-includes/class-wp-block-pattern-categories-registry.php

    r60275 r60904  
    139139     * @since 5.5.0
    140140     *
    141      * @param string $category_name Pattern category name including namespace.
     141     * @param string|null $category_name Pattern category name including namespace.
    142142     * @return bool True if the pattern category is registered, false otherwise.
    143143     */
    144144    public function is_registered( $category_name ) {
    145         return isset( $this->registered_categories[ $category_name ] );
     145        return isset( $category_name, $this->registered_categories[ $category_name ] );
    146146    }
    147147
  • trunk/src/wp-includes/class-wp-block-patterns-registry.php

    r60804 r60904  
    239239     * @since 5.5.0
    240240     *
    241      * @param string $pattern_name Block pattern name including namespace.
     241     * @param string|null $pattern_name Block pattern name including namespace.
    242242     * @return bool True if the pattern is registered, false otherwise.
    243243     */
    244244    public function is_registered( $pattern_name ) {
    245         return isset( $this->registered_patterns[ $pattern_name ] );
     245        return isset( $pattern_name, $this->registered_patterns[ $pattern_name ] );
    246246    }
    247247
  • trunk/src/wp-includes/class-wp-block-styles-registry.php

    r60275 r60904  
    182182     * @since 5.3.0
    183183     *
    184      * @param string $block_name       Block type name including namespace.
    185      * @param string $block_style_name Block style name.
     184     * @param string|null $block_name       Block type name including namespace.
     185     * @param string|null $block_style_name Block style name.
    186186     * @return bool True if the block style is registered, false otherwise.
    187187     */
    188188    public function is_registered( $block_name, $block_style_name ) {
    189         return isset( $this->registered_block_styles[ $block_name ][ $block_style_name ] );
     189        return isset( $block_name, $block_style_name, $this->registered_block_styles[ $block_name ][ $block_style_name ] );
    190190    }
    191191
  • trunk/src/wp-includes/class-wp-block-templates-registry.php

    r59742 r60904  
    205205     * @since 6.7.0
    206206     *
    207      * @param string $template_name Template name.
     207     * @param string|null $template_name Template name.
    208208     * @return bool True if the template is registered, false otherwise.
    209209     */
    210210    public function is_registered( $template_name ) {
    211         return isset( $this->registered_templates[ $template_name ] );
     211        return isset( $template_name, $this->registered_templates[ $template_name ] );
    212212    }
    213213
  • trunk/tests/phpunit/tests/block-bindings/wpBlockBindingsRegistry.php

    r59080 r60904  
    345345        $this->assertTrue( $result );
    346346    }
     347
     348    /**
     349     * Should return false when checking registration with a null source name.
     350     *
     351     * @ticket 63957
     352     *
     353     * @covers WP_Block_Bindings_Registry::is_registered
     354     */
     355    public function test_is_registered_with_null_source_name() {
     356        $result = $this->registry->is_registered( null );
     357        $this->assertFalse( $result );
     358    }
    347359}
  • trunk/tests/phpunit/tests/block-templates/WpBlockTemplatesRegistry.php

    r59742 r60904  
    246246
    247247        self::$registry->unregister( $template_name );
     248    }
     249
     250    /**
     251     * @ticket 63957
     252     *
     253     * @covers ::is_registered
     254     */
     255    public function test_is_registered_with_null_template_name() {
     256        $this->assertFalse( self::$registry->is_registered( null ) );
    248257    }
    249258
  • trunk/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php

    r60729 r60904  
    696696        }
    697697    }
     698
     699    /**
     700     * @ticket 63957
     701     */
     702    public function test_is_registered_with_null_pattern_name() {
     703        $this->assertFalse( $this->registry->is_registered( null ) );
     704    }
    698705}
  • trunk/tests/phpunit/tests/blocks/wpBlockStylesRegistry.php

    r58246 r60904  
    6767        $this->assertTrue( $this->registry->is_registered( 'core/group', 'plain' ) );
    6868    }
     69
     70    /**
     71     * @ticket 63957
     72     */
     73    public function test_is_registered_returns_false_for_null_block_name() {
     74        $style_name = 'fancy-style';
     75        $this->assertFalse(
     76            $this->registry->is_registered( null, $style_name ),
     77            'Empty block name should return false.'
     78        );
     79    }
     80
     81    /**
     82     * @ticket 63957
     83     */
     84    public function test_is_registered_returns_false_for_null_style_name() {
     85        $block_name = 'core/paragraph';
     86        $this->assertFalse(
     87            $this->registry->is_registered( $block_name, null ),
     88            'Empty style name should return false.'
     89        );
     90    }
     91
     92    /**
     93     * @ticket 63957
     94     */
     95    public function test_is_registered_returns_false_for_both_null_params() {
     96        $this->assertFalse(
     97            $this->registry->is_registered( null, null ),
     98            'Both empty block and style name should return false.'
     99        );
     100    }
    69101}
Note: See TracChangeset for help on using the changeset viewer.