FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix incorrect usage of badge colors in all Site Health checks by felixarntz · Pull Request #472 · WordPress/performance · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .php  (6) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ function perflab_oc_health_persistent_object_cache() {
*/
$notes = apply_filters( 'perflab_oc_site_status_persistent_object_cache_notes', $notes, $available_services );

$result['status'] = 'recommended';
$result['label'] = __( 'You should use a persistent object cache', 'performance-lab' );
$result['badge']['color'] = 'orange';
$result['description'] .= sprintf(
$result['status'] = 'recommended';
$result['label'] = __( 'You should use a persistent object cache', 'performance-lab' );
$result['description'] .= sprintf(
'<p>%s</p>',
wp_kses(
$notes,
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ function perflab_aao_autoloaded_options_test() {
$base_description = __( 'Autoloaded options are configuration settings for plugins and themes that are automatically loaded with every page load in WordPress. Having too many autoloaded options can slow down your site.', 'performance-lab' );

$result = array(
'label' => esc_html__( 'Autoloaded options are acceptable', 'performance-lab' ),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I noticed we are applying esc_html__ inconsistently to translations and that you removed a bunch in this PR.

For core, we don't escape translations, however for plugins I generally recommend escaping (as 10up recommends).

Maybe rather than changing here we can open a follow issue to use a uniform approach and change throughout the plugin?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

While escaping is recommended for plugins more than core, the rules also say that escaping should happen at the output level. In all the places here though, we're only writing data into an array, so per those guidelines escaping here would not follow the best practice.

All escaping for Site Health check content should happen in WordPress core per that definition, since that's where the data is being output.

'label' => __( 'Autoloaded options are acceptable', 'performance-lab' ),
'status' => 'good',
'badge' => array(
'label' => esc_html__( 'Performance', 'performance-lab' ),
'label' => __( 'Performance', 'performance-lab' ),
'color' => 'blue',
),
'description' => sprintf(
/* translators: 1. Number of autoloaded options. 2. Autoloaded options size. */
'<p>' . esc_html( $base_description ) . ' ' . esc_html__( 'Your site has %1$s autoloaded options (size: %2$s) in the options table, which is acceptable.', 'performance-lab' ) . '</p>',
'<p>' . esc_html( $base_description ) . ' ' . __( 'Your site has %1$s autoloaded options (size: %2$s) in the options table, which is acceptable.', 'performance-lab' ) . '</p>',
$autoloaded_options_count,
size_format( $autoloaded_options_size )
),
Expand All @@ -69,12 +69,11 @@ function perflab_aao_autoloaded_options_test() {
return $result;
}

$result['status'] = 'critical';
$result['badge']['color'] = 'red';
$result['label'] = esc_html__( 'Autoloaded options could affect performance', 'performance-lab' );
$result['description'] = sprintf(
$result['status'] = 'critical';
$result['label'] = __( 'Autoloaded options could affect performance', 'performance-lab' );
$result['description'] = sprintf(
/* translators: 1. Number of autoloaded options. 2. Autoloaded options size. */
'<p>' . esc_html( $base_description ) . ' ' . esc_html__( 'Your site has %1$s autoloaded options (size: %2$s) in the options table, which could cause your site to be slow. You can reduce the number of autoloaded options by cleaning up your site\'s options table.', 'performance-lab' ) . '</p>',
'<p>' . esc_html( $base_description ) . ' ' . __( 'Your site has %1$s autoloaded options (size: %2$s) in the options table, which could cause your site to be slow. You can reduce the number of autoloaded options by cleaning up your site\'s options table.', 'performance-lab' ) . '</p>',
$autoloaded_options_count,
size_format( $autoloaded_options_size )
);
Expand All @@ -92,7 +91,7 @@ function perflab_aao_autoloaded_options_test() {
/* translators: 1: HelpHub URL. 2: Link description. */
'<p><a target="_blank" href="%1$s">%2$s</a></p>',
esc_url( __( 'https://wordpress.org/support/article/optimization/#autoloaded-options', 'performance-lab' ) ),
esc_html__( 'More info about performance optimization', 'performance-lab' )
__( 'More info about performance optimization', 'performance-lab' )
);

/**
Expand Down
22 changes: 10 additions & 12 deletions modules/site-health/audit-enqueued-assets/load.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ function perflab_aea_enqueued_js_assets_test() {
}

$result = array(
'label' => esc_html__( 'Enqueued scripts', 'performance-lab' ),
'label' => __( 'Enqueued scripts', 'performance-lab' ),
'status' => 'good',
'badge' => array(
'label' => esc_html__( 'Performance', 'performance-lab' ),
'label' => __( 'Performance', 'performance-lab' ),
'color' => 'blue',
),
'description' => sprintf(
Expand Down Expand Up @@ -186,8 +186,7 @@ function perflab_aea_enqueued_js_assets_test() {
$scripts_size_treshold = apply_filters( 'perflab_aea_enqueued_scripts_byte_size_threshold', 300000 );

if ( $enqueued_scripts > $scripts_treshold || perflab_aea_get_total_size_bytes_enqueued_scripts() > $scripts_size_treshold ) {
$result['status'] = 'recommended';
$result['badge']['color'] = 'orange';
$result['status'] = 'recommended';

$result['description'] = sprintf(
'<p>%s</p>',
Expand All @@ -210,9 +209,9 @@ function perflab_aea_enqueued_js_assets_test() {
/* translators: 1: HelpHub URL. 2: Link description. 3.URL to clean cache. 4. Clean Cache text. */
'<p><a target="_blank" href="%1$s">%2$s</a></p><p><a href="%3$s">%4$s</a></p>',
esc_url( __( 'https://wordpress.org/support/article/optimization/', 'performance-lab' ) ),
esc_html__( 'More info about performance optimization', 'performance-lab' ),
__( 'More info about performance optimization', 'performance-lab' ),
esc_url( add_query_arg( 'action', 'clean_aea_audit', wp_nonce_url( admin_url( 'site-health.php' ), 'clean_aea_audit' ) ) ),
esc_html__( 'Clean Test Cache', 'performance-lab' )
__( 'Clean Test Cache', 'performance-lab' )
);
}

Expand All @@ -235,10 +234,10 @@ function perflab_aea_enqueued_css_assets_test() {
return array();
}
$result = array(
'label' => esc_html__( 'Enqueued styles', 'performance-lab' ),
'label' => __( 'Enqueued styles', 'performance-lab' ),
'status' => 'good',
'badge' => array(
'label' => esc_html__( 'Performance', 'performance-lab' ),
'label' => __( 'Performance', 'performance-lab' ),
'color' => 'blue',
),
'description' => sprintf(
Expand Down Expand Up @@ -279,8 +278,7 @@ function perflab_aea_enqueued_css_assets_test() {
*/
$styles_size_threshold = apply_filters( 'perflab_aea_enqueued_styles_byte_size_threshold', 100000 );
if ( $enqueued_styles > $styles_threshold || perflab_aea_get_total_size_bytes_enqueued_styles() > $styles_size_threshold ) {
$result['status'] = 'recommended';
$result['badge']['color'] = 'orange';
$result['status'] = 'recommended';

$result['description'] = sprintf(
'<p>%s</p>',
Expand All @@ -303,9 +301,9 @@ function perflab_aea_enqueued_css_assets_test() {
/* translators: 1: HelpHub URL. 2: Link description. 3.URL to clean cache. 4. Clean Cache text. */
'<p><a target="_blank" href="%1$s">%2$s</a></p><p><a href="%3$s">%4$s</a></p>',
esc_url( __( 'https://wordpress.org/support/article/optimization/', 'performance-lab' ) ),
esc_html__( 'More info about performance optimization', 'performance-lab' ),
__( 'More info about performance optimization', 'performance-lab' ),
esc_url( add_query_arg( 'action', 'clean_aea_audit', wp_nonce_url( admin_url( 'site-health.php' ), 'clean_aea_audit' ) ) ),
esc_html__( 'Clean Test Cache', 'performance-lab' )
__( 'Clean Test Cache', 'performance-lab' )
);
}

Expand Down
16 changes: 6 additions & 10 deletions modules/site-health/audit-full-page-cache/load.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function perflab_afpc_page_cache_test() {
$result = array(
'badge' => array(
'label' => __( 'Performance', 'performance-lab' ),
'color' => 'green',
'color' => 'blue',
),
'description' => wp_kses_post( $description ),
'test' => 'perflab_page_cache',
Expand All @@ -65,10 +65,9 @@ function perflab_afpc_page_cache_test() {
$page_cache_detail = perflab_afpc_get_page_cache_detail();

if ( is_wp_error( $page_cache_detail ) ) {
$result['badge']['color'] = 'orange';
$result['label'] = __( 'Unable to detect the presence of page caching', 'performance-lab' );
$result['status'] = 'recommended';
$error_info = sprintf(
$result['label'] = __( 'Unable to detect the presence of page caching', 'performance-lab' );
$result['status'] = 'recommended';
$error_info = sprintf(
/* translators: 1 is error message, 2 is error code */
__( 'Unable to detect page caching due to possible loopback request problem. Please verify that the loopback request test is passing. Error: %1$s (Code: %2$s)', 'performance-lab' ),
$page_cache_detail->get_error_message(),
Expand All @@ -82,15 +81,12 @@ function perflab_afpc_page_cache_test() {

switch ( $page_cache_detail['status'] ) {
case 'recommended':
$result['badge']['color'] = 'orange';
$result['label'] = __( 'Page caching is not detected but the server response time is OK', 'performance-lab' );
$result['label'] = __( 'Page caching is not detected but the server response time is OK', 'performance-lab' );
break;
case 'good':
$result['badge']['color'] = 'green';
$result['label'] = __( 'Page caching is detected and the server response time is good', 'performance-lab' );
$result['label'] = __( 'Page caching is detected and the server response time is good', 'performance-lab' );
break;
default:
$result['badge']['color'] = 'red';
if ( empty( $page_cache_detail['headers'] ) && ! $page_cache_detail['advanced_cache_present'] ) {
$result['label'] = __( 'Page caching is not detected and the server response time is slow', 'performance-lab' );
} else {
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,10 @@ public function test_perflab_afpc_add_full_page_cache_test() {
* @covers ::perflab_afpc_check_for_page_caching()
*/
public function test_perflab_afpc_page_cache_test( $responses, $expected_status, $expected_label, $good_basic_auth = null, $delay_the_response = false ) {
$badge_color = array(
'critical' => 'red',
'recommended' => 'orange',
'good' => 'green',
);

$expected_props = array(
'badge' => array(
'label' => __( 'Performance', 'performance-lab' ),
'color' => $badge_color[ $expected_status ],
'color' => 'blue',
),
'test' => 'perflab_page_cache',
'status' => $expected_status,
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ public static function return_aea_enqueued_js_assets_test_callback_less_than_thr
* @return array
*/
public static function return_aea_enqueued_js_assets_test_callback_more_than_threshold( $enqueued_scripts ) {
$result = self::return_aea_enqueued_js_assets_test_callback_less_than_threshold();
$result['status'] = 'recommended';
$result['badge']['color'] = 'orange';
$result['description'] = sprintf(
$result = self::return_aea_enqueued_js_assets_test_callback_less_than_threshold();
$result['status'] = 'recommended';
$result['description'] = sprintf(
'<p>%s</p>',
esc_html(
sprintf(
Expand Down Expand Up @@ -149,10 +148,9 @@ public static function return_aea_enqueued_css_assets_test_callback_less_than_th
* @return array
*/
public static function return_aea_enqueued_css_assets_test_callback_more_than_threshold( $enqueued_styles ) {
$result = self::return_aea_enqueued_css_assets_test_callback_less_than_threshold();
$result['status'] = 'recommended';
$result['badge']['color'] = 'orange';
$result['description'] = sprintf(
$result = self::return_aea_enqueued_css_assets_test_callback_less_than_threshold();
$result['status'] = 'recommended';
$result['description'] = sprintf(
'<p>%s</p>',
esc_html(
sprintf(
Expand Down

Back | FazBrowse Home | New Git URL