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.
Built from https://develop.svn.wordpress.org/trunk@51154


git-svn-id: http://core.svn.wordpress.org/trunk@50763 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-06-15 15:22:58 +00:00
parent 4d3ddd056f
commit e05ffb46a5
9 changed files with 131 additions and 63 deletions

View File

@ -38,7 +38,11 @@ final class WP_Block_Pattern_Categories_Registry {
*/
public function register( $category_name, $category_properties ) {
if ( ! isset( $category_name ) || ! is_string( $category_name ) ) {
_doing_it_wrong( __METHOD__, __( 'Block pattern category name must be a string.' ), '5.5.0' );
_doing_it_wrong(
__METHOD__,
__( 'Block pattern category name must be a string.' ),
'5.5.0'
);
return false;
}
@ -60,9 +64,12 @@ final class WP_Block_Pattern_Categories_Registry {
*/
public function unregister( $category_name ) {
if ( ! $this->is_registered( $category_name ) ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: Block pattern name. */
$message = sprintf( __( 'Block pattern category "%s" not found.' ), $category_name );
_doing_it_wrong( __METHOD__, $message, '5.5.0' );
sprintf( __( 'Block pattern category "%s" not found.' ), $category_name ),
'5.5.0'
);
return false;
}

View File

@ -41,17 +41,29 @@ final class WP_Block_Patterns_Registry {
*/
public function register( $pattern_name, $pattern_properties ) {
if ( ! isset( $pattern_name ) || ! is_string( $pattern_name ) ) {
_doing_it_wrong( __METHOD__, __( 'Pattern name must be a string.' ), '5.5.0' );
_doing_it_wrong(
__METHOD__,
__( 'Pattern name must be a string.' ),
'5.5.0'
);
return false;
}
if ( ! isset( $pattern_properties['title'] ) || ! is_string( $pattern_properties['title'] ) ) {
_doing_it_wrong( __METHOD__, __( 'Pattern title must be a string.' ), '5.5.0' );
_doing_it_wrong(
__METHOD__,
__( 'Pattern title must be a string.' ),
'5.5.0'
);
return false;
}
if ( ! isset( $pattern_properties['content'] ) || ! is_string( $pattern_properties['content'] ) ) {
_doing_it_wrong( __METHOD__, __( 'Pattern content must be a string.' ), '5.5.0' );
_doing_it_wrong(
__METHOD__,
__( 'Pattern content must be a string.' ),
'5.5.0'
);
return false;
}
@ -73,9 +85,12 @@ final class WP_Block_Patterns_Registry {
*/
public function unregister( $pattern_name ) {
if ( ! $this->is_registered( $pattern_name ) ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: Pattern name. */
$message = sprintf( __( 'Pattern "%s" not found.' ), $pattern_name );
_doing_it_wrong( __METHOD__, $message, '5.5.0' );
sprintf( __( 'Pattern "%s" not found.' ), $pattern_name ),
'5.5.0'
);
return false;
}

View File

@ -43,14 +43,20 @@ final class WP_Block_Styles_Registry {
public function register( $block_name, $style_properties ) {
if ( ! isset( $block_name ) || ! is_string( $block_name ) ) {
$message = __( 'Block name must be a string.' );
_doing_it_wrong( __METHOD__, $message, '5.3.0' );
_doing_it_wrong(
__METHOD__,
__( 'Block name must be a string.' ),
'5.3.0'
);
return false;
}
if ( ! isset( $style_properties['name'] ) || ! is_string( $style_properties['name'] ) ) {
$message = __( 'Block style name must be a string.' );
_doing_it_wrong( __METHOD__, $message, '5.3.0' );
_doing_it_wrong(
__METHOD__,
__( 'Block style name must be a string.' ),
'5.3.0'
);
return false;
}
@ -73,9 +79,12 @@ final class WP_Block_Styles_Registry {
*/
public function unregister( $block_name, $block_style_name ) {
if ( ! $this->is_registered( $block_name, $block_style_name ) ) {
_doing_it_wrong(
__METHOD__,
/* translators: 1: Block name, 2: Block style name. */
$message = sprintf( __( 'Block "%1$s" does not contain a style named "%2$s".' ), $block_name, $block_style_name );
_doing_it_wrong( __METHOD__, $message, '5.3.0' );
sprintf( __( 'Block "%1$s" does not contain a style named "%2$s".' ), $block_name, $block_style_name ),
'5.3.0'
);
return false;
}

View File

@ -52,28 +52,40 @@ final class WP_Block_Type_Registry {
}
if ( ! is_string( $name ) ) {
$message = __( 'Block type names must be strings.' );
_doing_it_wrong( __METHOD__, $message, '5.0.0' );
_doing_it_wrong(
__METHOD__,
__( 'Block type names must be strings.' ),
'5.0.0'
);
return false;
}
if ( preg_match( '/[A-Z]+/', $name ) ) {
$message = __( 'Block type names must not contain uppercase characters.' );
_doing_it_wrong( __METHOD__, $message, '5.0.0' );
_doing_it_wrong(
__METHOD__,
__( 'Block type names must not contain uppercase characters.' ),
'5.0.0'
);
return false;
}
$name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/';
if ( ! preg_match( $name_matcher, $name ) ) {
$message = __( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type' );
_doing_it_wrong( __METHOD__, $message, '5.0.0' );
_doing_it_wrong(
__METHOD__,
__( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type' ),
'5.0.0'
);
return false;
}
if ( $this->is_registered( $name ) ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: Block name. */
$message = sprintf( __( 'Block type "%s" is already registered.' ), $name );
_doing_it_wrong( __METHOD__, $message, '5.0.0' );
sprintf( __( 'Block type "%s" is already registered.' ), $name ),
'5.0.0'
);
return false;
}
@ -101,9 +113,12 @@ final class WP_Block_Type_Registry {
}
if ( ! $this->is_registered( $name ) ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: Block name. */
$message = sprintf( __( 'Block type "%s" is not registered.' ), $name );
_doing_it_wrong( __METHOD__, $message, '5.0.0' );
sprintf( __( 'Block type "%s" is not registered.' ), $name ),
'5.0.0'
);
return false;
}

View File

@ -3907,7 +3907,9 @@ final class WP_Customize_Manager {
public function remove_panel( $id ) {
// Removing core components this way is _doing_it_wrong().
if ( in_array( $id, $this->components, true ) ) {
$message = sprintf(
_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: 1: Panel ID, 2: Link to 'customize_loaded_components' filter reference. */
__( 'Removing %1$s manually will cause PHP warnings. Use the %2$s filter instead.' ),
$id,
@ -3916,9 +3918,9 @@ final class WP_Customize_Manager {
esc_url( 'https://developer.wordpress.org/reference/hooks/customize_loaded_components/' ),
'<code>customize_loaded_components</code>'
)
),
'4.5.0'
);
_doing_it_wrong( __METHOD__, $message, '4.5.0' );
}
unset( $this->panels[ $id ] );
}

View File

@ -304,13 +304,16 @@ function wp_deregister_script( $handle ) {
);
if ( in_array( $handle, $not_allowed, true ) ) {
$message = sprintf(
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: Script name, 2: wp_enqueue_scripts */
__( 'Do not deregister the %1$s script in the administration area. To target the front-end theme, use the %2$s hook.' ),
"<code>$handle</code>",
'<code>wp_enqueue_scripts</code>'
),
'3.6.0'
);
_doing_it_wrong( __FUNCTION__, $message, '3.6.0' );
return;
}
}

View File

@ -899,19 +899,23 @@ function is_embed() {
* @return bool Whether the query is the main query.
*/
function is_main_query() {
global $wp_query;
if ( 'pre_get_posts' === current_filter() ) {
$message = sprintf(
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: pre_get_posts, 2: WP_Query->is_main_query(), 3: is_main_query(), 4: Documentation URL. */
__( 'In %1$s, use the %2$s method, not the %3$s function. See %4$s.' ),
'<code>pre_get_posts</code>',
'<code>WP_Query->is_main_query()</code>',
'<code>is_main_query()</code>',
__( 'https://developer.wordpress.org/reference/functions/is_main_query/' )
),
'3.7.0'
);
_doing_it_wrong( __FUNCTION__, $message, '3.7.0' );
}
global $wp_query;
return $wp_query->is_main_query();
}

View File

@ -64,15 +64,25 @@ function add_shortcode( $tag, $callback ) {
global $shortcode_tags;
if ( '' === trim( $tag ) ) {
$message = __( 'Invalid shortcode name: Empty name given.' );
_doing_it_wrong( __FUNCTION__, $message, '4.4.0' );
_doing_it_wrong(
__FUNCTION__,
__( 'Invalid shortcode name: Empty name given.' ),
'4.4.0'
);
return;
}
if ( 0 !== preg_match( '@[<>&/\[\]\x00-\x20=]@', $tag ) ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: Shortcode name, 2: Space-separated list of reserved characters. */
$message = sprintf( __( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ), $tag, '& / < > [ ] =' );
_doing_it_wrong( __FUNCTION__, $message, '4.4.0' );
__( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ),
$tag,
'& / < > [ ] ='
),
'4.4.0'
);
return;
}
@ -314,9 +324,12 @@ function do_shortcode_tag( $m ) {
$attr = shortcode_parse_atts( $m[3] );
if ( ! is_callable( $shortcode_tags[ $tag ] ) ) {
_doing_it_wrong(
__FUNCTION__,
/* translators: %s: Shortcode tag. */
$message = sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag );
_doing_it_wrong( __FUNCTION__, $message, '4.3.0' );
sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag ),
'4.3.0'
);
return $m[0];
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.8-beta1-51153';
$wp_version = '5.8-beta1-51154';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.