Skip to content

Commit 31a1cf7

Browse files
committed
Apply suggestion from @retlehs
Prefer fewer else statements and early returns. See: #1 (comment)
1 parent 3cd1ede commit 31a1cf7

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

bedrock-disallow-indexing.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,34 @@
2222
}
2323

2424
add_action('admin_notices', function () {
25-
if (defined('WP_ENV') && WP_ENV) {
26-
$wp_env = WP_ENV;
27-
} else if (function_exists('wp_get_environment_type')) {
28-
$wp_env = wp_get_environment_type();
29-
} else {
30-
$wp_env = null;
25+
$env = defined('WP_ENV') && WP_ENV ? WP_ENV : null;
26+
27+
if (!$env && function_exists('wp_get_environment_type')) {
28+
$env = wp_get_environment_type();
3129
}
3230

33-
$wp_env = apply_filters('roots/bedrock/disallow_indexing_environment_type', $wp_env);
34-
if ($wp_env) {
35-
$message = sprintf(
36-
__('%1$s Search engine indexing has been discouraged because the current environment is %2$s.', 'roots'),
37-
'<strong>Bedrock:</strong>',
38-
'<code>'.$wp_env.'</code>'
39-
);
40-
} else {
41-
$message = sprintf(
42-
__('%1$s Search engine indexing has been discouraged.', 'roots'),
43-
'<strong>Bedrock:</strong>'
31+
$env = apply_filters('roots/bedrock/disallow_indexing_environment_type', $env);
32+
33+
if (!$env) {
34+
printf(
35+
'<div class="notice notice-warning"><p>%s</p></div>',
36+
sprintf(
37+
/* translators: %s: Bedrock prefix. */
38+
__('%s Search engine indexing has been discouraged.', 'roots'),
39+
'<strong>Bedrock:</strong>'
40+
)
4441
);
42+
return;
4543
}
4644

47-
echo "<div class='notice notice-warning'><p>{$message}</p></div>";
45+
printf(
46+
'<div class="notice notice-warning"><p>%s</p></div>',
47+
sprintf(
48+
/* translators: 1: Bedrock prefix, 2: Environment type. */
49+
__('%1$s Search engine indexing has been discouraged because the current environment is %2$s.', 'roots'),
50+
'<strong>Bedrock:</strong>',
51+
'<code>' . $env . '</code>'
52+
)
53+
);
4854
});
4955
});

0 commit comments

Comments
 (0)