Make WordPress Core

Ticket #50550: 50550-doing-it-wrong.patch

File 50550-doing-it-wrong.patch, 1.4 KB (added by poena, 5 years ago)

Require the title and content properties, add doing it wrong message.

  • src/wp-includes/class-wp-block-patterns-registry.php

     
    3333         * @since 5.5.0
    3434         *
    3535         * @param string $pattern_name       Pattern name including namespace.
    36          * @param array  $pattern_properties Array containing the properties of the pattern: label, content.
     36         * @param array  $pattern_properties Array containing the properties of the pattern: Title, content, description, viewportWidth, categories, keywords.
    3737         * @return bool True if the pattern was registered with success and false otherwise.
    3838         */
    3939        public function register( $pattern_name, $pattern_properties ) {
     
    4242                        return false;
    4343                }
    4444
     45                if ( ! isset( $pattern_properties['title'] ) || ! is_string( $pattern_properties['title'] ) ) {
     46                        _doing_it_wrong( __METHOD__, __( 'Pattern title must be a string.' ), '5.5.0' );
     47                        return false;
     48                }
     49
     50                if ( ! isset( $pattern_properties['content'] ) || ! is_string( $pattern_properties['content'] ) ) {
     51                        _doing_it_wrong( __METHOD__, __( 'Pattern content must be a string.' ), '5.5.0' );
     52                        return false;
     53                }
     54
    4555                $this->registered_patterns[ $pattern_name ] = array_merge(
    4656                        $pattern_properties,
    4757                        array( 'name' => $pattern_name )