Skip to content

Commit

Permalink
Coding Standards: Remove a one-time $message variable in some `_doi…
Browse files Browse the repository at this point in the history
…ng_it_wrong()` calls.

This brings some consistency with most other calls.

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

See #52627.

git-svn-id: https://develop.svn.wordpress.org/trunk@51154 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jun 15, 2021
1 parent 8490fcb commit f04ebe2
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 62 deletions.
15 changes: 11 additions & 4 deletions src/wp-includes/class-wp-block-pattern-categories-registry.php
Expand Up @@ -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;
}

Expand All @@ -60,9 +64,12 @@ public function register( $category_name, $category_properties ) {
*/
public function unregister( $category_name ) {
if ( ! $this->is_registered( $category_name ) ) {
/* translators: %s: Block pattern name. */
$message = sprintf( __( 'Block pattern category "%s" not found.' ), $category_name );
_doing_it_wrong( __METHOD__, $message, '5.5.0' );
_doing_it_wrong(
__METHOD__,
/* translators: %s: Block pattern name. */
sprintf( __( 'Block pattern category "%s" not found.' ), $category_name ),
'5.5.0'
);
return false;
}

Expand Down
27 changes: 21 additions & 6 deletions src/wp-includes/class-wp-block-patterns-registry.php
Expand Up @@ -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;
}

Expand All @@ -73,9 +85,12 @@ public function register( $pattern_name, $pattern_properties ) {
*/
public function unregister( $pattern_name ) {
if ( ! $this->is_registered( $pattern_name ) ) {
/* translators: %s: Pattern name. */
$message = sprintf( __( 'Pattern "%s" not found.' ), $pattern_name );
_doing_it_wrong( __METHOD__, $message, '5.5.0' );
_doing_it_wrong(
__METHOD__,
/* translators: %s: Pattern name. */
sprintf( __( 'Pattern "%s" not found.' ), $pattern_name ),
'5.5.0'
);
return false;
}

Expand Down
23 changes: 16 additions & 7 deletions src/wp-includes/class-wp-block-styles-registry.php
Expand Up @@ -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;
}

Expand All @@ -73,9 +79,12 @@ public function register( $block_name, $style_properties ) {
*/
public function unregister( $block_name, $block_style_name ) {
if ( ! $this->is_registered( $block_name, $block_style_name ) ) {
/* 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' );
_doing_it_wrong(
__METHOD__,
/* translators: 1: Block name, 2: Block style name. */
sprintf( __( 'Block "%1$s" does not contain a style named "%2$s".' ), $block_name, $block_style_name ),
'5.3.0'
);
return false;
}

Expand Down
39 changes: 27 additions & 12 deletions src/wp-includes/class-wp-block-type-registry.php
Expand Up @@ -52,28 +52,40 @@ public function register( $name, $args = array() ) {
}

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 ) ) {
/* translators: %s: Block name. */
$message = sprintf( __( 'Block type "%s" is already registered.' ), $name );
_doing_it_wrong( __METHOD__, $message, '5.0.0' );
_doing_it_wrong(
__METHOD__,
/* translators: %s: Block name. */
sprintf( __( 'Block type "%s" is already registered.' ), $name ),
'5.0.0'
);
return false;
}

Expand Down Expand Up @@ -101,9 +113,12 @@ public function unregister( $name ) {
}

if ( ! $this->is_registered( $name ) ) {
/* translators: %s: Block name. */
$message = sprintf( __( 'Block type "%s" is not registered.' ), $name );
_doing_it_wrong( __METHOD__, $message, '5.0.0' );
_doing_it_wrong(
__METHOD__,
/* translators: %s: Block name. */
sprintf( __( 'Block type "%s" is not registered.' ), $name ),
'5.0.0'
);
return false;
}

Expand Down
22 changes: 12 additions & 10 deletions src/wp-includes/class-wp-customize-manager.php
Expand Up @@ -3907,18 +3907,20 @@ public function get_panel( $id ) {
public function remove_panel( $id ) {
// Removing core components this way is _doing_it_wrong().
if ( in_array( $id, $this->components, true ) ) {
$message = 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,
_doing_it_wrong(
__METHOD__,
sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( 'https://developer.wordpress.org/reference/hooks/customize_loaded_components/' ),
'<code>customize_loaded_components</code>'
)
/* 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,
sprintf(
'<a href="%1$s">%2$s</a>',
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 ] );
}
Expand Down
15 changes: 9 additions & 6 deletions src/wp-includes/functions.wp-scripts.php
Expand Up @@ -304,13 +304,16 @@ function wp_deregister_script( $handle ) {
);

if ( in_array( $handle, $not_allowed, true ) ) {
$message = 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>'
_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;
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/wp-includes/query.php
Expand Up @@ -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(
/* 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/' )
_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();
}

Expand Down
29 changes: 21 additions & 8 deletions src/wp-includes/shortcodes.php
Expand Up @@ -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 ) ) {
/* 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' );
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: Shortcode name, 2: Space-separated list of reserved characters. */
__( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ),
$tag,
'& / < > [ ] ='
),
'4.4.0'
);
return;
}

Expand Down Expand Up @@ -314,9 +324,12 @@ function do_shortcode_tag( $m ) {
$attr = shortcode_parse_atts( $m[3] );

if ( ! is_callable( $shortcode_tags[ $tag ] ) ) {
/* 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' );
_doing_it_wrong(
__FUNCTION__,
/* translators: %s: Shortcode tag. */
sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag ),
'4.3.0'
);
return $m[0];
}

Expand Down

0 comments on commit f04ebe2

Please sign in to comment.