Make WordPress Core

Changeset 51154


Ignore:
Timestamp:
06/15/2021 03:21:50 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Remove a one-time $message variable in some _doing_it_wrong() calls.

This brings some consistency with most other calls.

Follow-up to [23378], [25605], [34745], [36219], [44108], [46111], [48156].

See #52627.

Location:
trunk/src/wp-includes
Files:
8 edited

Legend:

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

    r50532 r51154  
    3939        public function register( $category_name, $category_properties ) {
    4040                if ( ! isset( $category_name ) || ! is_string( $category_name ) ) {
    41                         _doing_it_wrong( __METHOD__, __( 'Block pattern category name must be a string.' ), '5.5.0' );
     41                        _doing_it_wrong(
     42                                __METHOD__,
     43                                __( 'Block pattern category name must be a string.' ),
     44                                '5.5.0'
     45                        );
    4246                        return false;
    4347                }
     
    6165        public function unregister( $category_name ) {
    6266                if ( ! $this->is_registered( $category_name ) ) {
    63                         /* translators: %s: Block pattern name. */
    64                         $message = sprintf( __( 'Block pattern category "%s" not found.' ), $category_name );
    65                         _doing_it_wrong( __METHOD__, $message, '5.5.0' );
     67                        _doing_it_wrong(
     68                                __METHOD__,
     69                                /* translators: %s: Block pattern name. */
     70                                sprintf( __( 'Block pattern category "%s" not found.' ), $category_name ),
     71                                '5.5.0'
     72                        );
    6673                        return false;
    6774                }
  • trunk/src/wp-includes/class-wp-block-patterns-registry.php

    r50532 r51154  
    4242        public function register( $pattern_name, $pattern_properties ) {
    4343                if ( ! isset( $pattern_name ) || ! is_string( $pattern_name ) ) {
    44                         _doing_it_wrong( __METHOD__, __( 'Pattern name must be a string.' ), '5.5.0' );
     44                        _doing_it_wrong(
     45                                __METHOD__,
     46                                __( 'Pattern name must be a string.' ),
     47                                '5.5.0'
     48                        );
    4549                        return false;
    4650                }
    4751
    4852                if ( ! isset( $pattern_properties['title'] ) || ! is_string( $pattern_properties['title'] ) ) {
    49                         _doing_it_wrong( __METHOD__, __( 'Pattern title must be a string.' ), '5.5.0' );
     53                        _doing_it_wrong(
     54                                __METHOD__,
     55                                __( 'Pattern title must be a string.' ),
     56                                '5.5.0'
     57                        );
    5058                        return false;
    5159                }
    5260
    5361                if ( ! isset( $pattern_properties['content'] ) || ! is_string( $pattern_properties['content'] ) ) {
    54                         _doing_it_wrong( __METHOD__, __( 'Pattern content must be a string.' ), '5.5.0' );
     62                        _doing_it_wrong(
     63                                __METHOD__,
     64                                __( 'Pattern content must be a string.' ),
     65                                '5.5.0'
     66                        );
    5567                        return false;
    5668                }
     
    7486        public function unregister( $pattern_name ) {
    7587                if ( ! $this->is_registered( $pattern_name ) ) {
    76                         /* translators: %s: Pattern name. */
    77                         $message = sprintf( __( 'Pattern "%s" not found.' ), $pattern_name );
    78                         _doing_it_wrong( __METHOD__, $message, '5.5.0' );
     88                        _doing_it_wrong(
     89                                __METHOD__,
     90                                /* translators: %s: Pattern name. */
     91                                sprintf( __( 'Pattern "%s" not found.' ), $pattern_name ),
     92                                '5.5.0'
     93                        );
    7994                        return false;
    8095                }
  • trunk/src/wp-includes/class-wp-block-styles-registry.php

    r50703 r51154  
    4444
    4545                if ( ! isset( $block_name ) || ! is_string( $block_name ) ) {
    46                         $message = __( 'Block name must be a string.' );
    47                         _doing_it_wrong( __METHOD__, $message, '5.3.0' );
     46                        _doing_it_wrong(
     47                                __METHOD__,
     48                                __( 'Block name must be a string.' ),
     49                                '5.3.0'
     50                        );
    4851                        return false;
    4952                }
    5053
    5154                if ( ! isset( $style_properties['name'] ) || ! is_string( $style_properties['name'] ) ) {
    52                         $message = __( 'Block style name must be a string.' );
    53                         _doing_it_wrong( __METHOD__, $message, '5.3.0' );
     55                        _doing_it_wrong(
     56                                __METHOD__,
     57                                __( 'Block style name must be a string.' ),
     58                                '5.3.0'
     59                        );
    5460                        return false;
    5561                }
     
    7480        public function unregister( $block_name, $block_style_name ) {
    7581                if ( ! $this->is_registered( $block_name, $block_style_name ) ) {
    76                         /* translators: 1: Block name, 2: Block style name. */
    77                         $message = sprintf( __( 'Block "%1$s" does not contain a style named "%2$s".' ), $block_name, $block_style_name );
    78                         _doing_it_wrong( __METHOD__, $message, '5.3.0' );
     82                        _doing_it_wrong(
     83                                __METHOD__,
     84                                /* translators: 1: Block name, 2: Block style name. */
     85                                sprintf( __( 'Block "%1$s" does not contain a style named "%2$s".' ), $block_name, $block_style_name ),
     86                                '5.3.0'
     87                        );
    7988                        return false;
    8089                }
  • trunk/src/wp-includes/class-wp-block-type-registry.php

    r50419 r51154  
    5353
    5454                if ( ! is_string( $name ) ) {
    55                         $message = __( 'Block type names must be strings.' );
    56                         _doing_it_wrong( __METHOD__, $message, '5.0.0' );
     55                        _doing_it_wrong(
     56                                __METHOD__,
     57                                __( 'Block type names must be strings.' ),
     58                                '5.0.0'
     59                        );
    5760                        return false;
    5861                }
    5962
    6063                if ( preg_match( '/[A-Z]+/', $name ) ) {
    61                         $message = __( 'Block type names must not contain uppercase characters.' );
    62                         _doing_it_wrong( __METHOD__, $message, '5.0.0' );
     64                        _doing_it_wrong(
     65                                __METHOD__,
     66                                __( 'Block type names must not contain uppercase characters.' ),
     67                                '5.0.0'
     68                        );
    6369                        return false;
    6470                }
     
    6672                $name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/';
    6773                if ( ! preg_match( $name_matcher, $name ) ) {
    68                         $message = __( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type' );
    69                         _doing_it_wrong( __METHOD__, $message, '5.0.0' );
     74                        _doing_it_wrong(
     75                                __METHOD__,
     76                                __( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type' ),
     77                                '5.0.0'
     78                        );
    7079                        return false;
    7180                }
    7281
    7382                if ( $this->is_registered( $name ) ) {
    74                         /* translators: %s: Block name. */
    75                         $message = sprintf( __( 'Block type "%s" is already registered.' ), $name );
    76                         _doing_it_wrong( __METHOD__, $message, '5.0.0' );
     83                        _doing_it_wrong(
     84                                __METHOD__,
     85                                /* translators: %s: Block name. */
     86                                sprintf( __( 'Block type "%s" is already registered.' ), $name ),
     87                                '5.0.0'
     88                        );
    7789                        return false;
    7890                }
     
    102114
    103115                if ( ! $this->is_registered( $name ) ) {
    104                         /* translators: %s: Block name. */
    105                         $message = sprintf( __( 'Block type "%s" is not registered.' ), $name );
    106                         _doing_it_wrong( __METHOD__, $message, '5.0.0' );
     116                        _doing_it_wrong(
     117                                __METHOD__,
     118                                /* translators: %s: Block name. */
     119                                sprintf( __( 'Block type "%s" is not registered.' ), $name ),
     120                                '5.0.0'
     121                        );
    107122                        return false;
    108123                }
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r49992 r51154  
    39083908                // Removing core components this way is _doing_it_wrong().
    39093909                if ( in_array( $id, $this->components, true ) ) {
    3910                         $message = sprintf(
    3911                                 /* translators: 1: Panel ID, 2: Link to 'customize_loaded_components' filter reference. */
    3912                                 __( 'Removing %1$s manually will cause PHP warnings. Use the %2$s filter instead.' ),
    3913                                 $id,
     3910                        _doing_it_wrong(
     3911                                __METHOD__,
    39143912                                sprintf(
    3915                                         '<a href="%1$s">%2$s</a>',
    3916                                         esc_url( 'https://developer.wordpress.org/reference/hooks/customize_loaded_components/' ),
    3917                                         '<code>customize_loaded_components</code>'
    3918                                 )
     3913                                        /* translators: 1: Panel ID, 2: Link to 'customize_loaded_components' filter reference. */
     3914                                        __( 'Removing %1$s manually will cause PHP warnings. Use the %2$s filter instead.' ),
     3915                                        $id,
     3916                                        sprintf(
     3917                                                '<a href="%1$s">%2$s</a>',
     3918                                                esc_url( 'https://developer.wordpress.org/reference/hooks/customize_loaded_components/' ),
     3919                                                '<code>customize_loaded_components</code>'
     3920                                        )
     3921                                ),
     3922                                '4.5.0'
    39193923                        );
    3920 
    3921                         _doing_it_wrong( __METHOD__, $message, '4.5.0' );
    39223924                }
    39233925                unset( $this->panels[ $id ] );
  • trunk/src/wp-includes/functions.wp-scripts.php

    r50393 r51154  
    305305
    306306                if ( in_array( $handle, $not_allowed, true ) ) {
    307                         $message = sprintf(
    308                                 /* translators: 1: Script name, 2: wp_enqueue_scripts */
    309                                 __( 'Do not deregister the %1$s script in the administration area. To target the front-end theme, use the %2$s hook.' ),
    310                                 "<code>$handle</code>",
    311                                 '<code>wp_enqueue_scripts</code>'
     307                        _doing_it_wrong(
     308                                __FUNCTION__,
     309                                sprintf(
     310                                        /* translators: 1: Script name, 2: wp_enqueue_scripts */
     311                                        __( 'Do not deregister the %1$s script in the administration area. To target the front-end theme, use the %2$s hook.' ),
     312                                        "<code>$handle</code>",
     313                                        '<code>wp_enqueue_scripts</code>'
     314                                ),
     315                                '3.6.0'
    312316                        );
    313                         _doing_it_wrong( __FUNCTION__, $message, '3.6.0' );
    314317                        return;
    315318                }
  • trunk/src/wp-includes/query.php

    r49927 r51154  
    900900 */
    901901function is_main_query() {
     902        global $wp_query;
     903
    902904        if ( 'pre_get_posts' === current_filter() ) {
    903                 $message = sprintf(
    904                         /* translators: 1: pre_get_posts, 2: WP_Query->is_main_query(), 3: is_main_query(), 4: Documentation URL. */
    905                         __( 'In %1$s, use the %2$s method, not the %3$s function. See %4$s.' ),
    906                         '<code>pre_get_posts</code>',
    907                         '<code>WP_Query->is_main_query()</code>',
    908                         '<code>is_main_query()</code>',
    909                         __( 'https://developer.wordpress.org/reference/functions/is_main_query/' )
     905                _doing_it_wrong(
     906                        __FUNCTION__,
     907                        sprintf(
     908                                /* translators: 1: pre_get_posts, 2: WP_Query->is_main_query(), 3: is_main_query(), 4: Documentation URL. */
     909                                __( 'In %1$s, use the %2$s method, not the %3$s function. See %4$s.' ),
     910                                '<code>pre_get_posts</code>',
     911                                '<code>WP_Query->is_main_query()</code>',
     912                                '<code>is_main_query()</code>',
     913                                __( 'https://developer.wordpress.org/reference/functions/is_main_query/' )
     914                        ),
     915                        '3.7.0'
    910916                );
    911                 _doing_it_wrong( __FUNCTION__, $message, '3.7.0' );
    912         }
    913 
    914         global $wp_query;
     917        }
     918
    915919        return $wp_query->is_main_query();
    916920}
  • trunk/src/wp-includes/shortcodes.php

    r49963 r51154  
    6565
    6666        if ( '' === trim( $tag ) ) {
    67                 $message = __( 'Invalid shortcode name: Empty name given.' );
    68                 _doing_it_wrong( __FUNCTION__, $message, '4.4.0' );
     67                _doing_it_wrong(
     68                        __FUNCTION__,
     69                        __( 'Invalid shortcode name: Empty name given.' ),
     70                        '4.4.0'
     71                );
    6972                return;
    7073        }
    7174
    7275        if ( 0 !== preg_match( '@[<>&/\[\]\x00-\x20=]@', $tag ) ) {
    73                 /* translators: 1: Shortcode name, 2: Space-separated list of reserved characters. */
    74                 $message = sprintf( __( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ), $tag, '& / < > [ ] =' );
    75                 _doing_it_wrong( __FUNCTION__, $message, '4.4.0' );
     76                _doing_it_wrong(
     77                        __FUNCTION__,
     78                        sprintf(
     79                                /* translators: 1: Shortcode name, 2: Space-separated list of reserved characters. */
     80                                __( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ),
     81                                $tag,
     82                                '& / < > [ ] ='
     83                        ),
     84                        '4.4.0'
     85                );
    7686                return;
    7787        }
     
    315325
    316326        if ( ! is_callable( $shortcode_tags[ $tag ] ) ) {
    317                 /* translators: %s: Shortcode tag. */
    318                 $message = sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag );
    319                 _doing_it_wrong( __FUNCTION__, $message, '4.3.0' );
     327                _doing_it_wrong(
     328                        __FUNCTION__,
     329                        /* translators: %s: Shortcode tag. */
     330                        sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag ),
     331                        '4.3.0'
     332                );
    320333                return $m[0];
    321334        }
Note: See TracChangeset for help on using the changeset viewer.