Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
nitpicks
  • Loading branch information
manuelRod committed Mar 11, 2022
commit a1ebb71b7e3ca7680f45e796df08e298d2003c8d
67 changes: 34 additions & 33 deletions modules/site-health/audit-autoloaded-options/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,43 @@ function perflab_aao_autoloaded_options_test() {
*/
$limit = apply_filters( 'perflab_aao_autoloaded_options_limit_size_in_bytes', 800000 );

if ( $autoloaded_options_size > $limit ) {
$result['status'] = 'critical';
$result['badge']['color'] = 'red';
$result['description'] = sprintf(
/* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */
'<p>' . esc_html__( 'Your website uses %1$s autoloaded options (size: %2$s). Try to reduce the number of autoloaded options or performance will be affected.', 'performance-lab' ) . '</p>',
$autoloaded_options_count,
size_format( $autoloaded_options_size )
);
if ( $autoloaded_options_size < $limit ) {
return $result;
}

/**
* Hostings can modify description to be shown on site health screen.
*
* @since 1.0.0
*
* @param string $description Description message when autoloaded options bigger than treshold.
*/
$result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] );
$result['status'] = 'critical';
$result['badge']['color'] = 'red';
$result['description'] = sprintf(
/* translators: 1: Number of autoloaded options. 2.Autoloaded options size. */
'<p>' . esc_html__( 'Your website uses %1$s autoloaded options (size: %2$s). Try to reduce the number of autoloaded options or performance will be affected.', 'performance-lab' ) . '</p>',
$autoloaded_options_count,
size_format( $autoloaded_options_size )
);

$result['actions'] = sprintf(
/* 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/', 'performance-lab' ) ),
esc_html__( 'More info about performance optimization', 'performance-lab' )
);
/**
* Hostings can modify description to be shown on site health screen.
*
* @since 1.0.0
*
* @param string $description Description message when autoloaded options bigger than treshold.
*/
$result['description'] = apply_filters( 'perflab_aao_autoloaded_options_limit_description', $result['description'] );

/**
* Hostings can add actions to take to reduce size of autoloaded options linking to their own guides.
*
* @since 1.0.0
*
* @param string $actions Call to Action to be used to point to the right direction to solve the issue.
*/
$result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', $result['actions'] );
}
$result['actions'] = sprintf(
/* 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/', 'performance-lab' ) ),
Copy link
Member

Choose a reason for hiding this comment

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

this link should go right to a support section explaining how to optimize autoload options, eg https://wordpress.org/support/article/optimization/#autoload. The link as is is not helpful to users - especially since the page doesn't even mention autoload options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with this, https://wordpress.org/support/article/optimization/#autoload should be written and we can link in there.

esc_html__( 'More info about performance optimization', 'performance-lab' )
);

/**
* Hostings can add actions to take to reduce size of autoloaded options linking to their own guides.
*
* @since 1.0.0
*
* @param string $actions Call to Action to be used to point to the right direction to solve the issue.
*/
$result['actions'] = apply_filters( 'perflab_aao_autoloaded_options_action_to_perform', $result['actions'] );
return $result;
}

Expand All @@ -111,5 +112,5 @@ function perflab_aao_autoloaded_options_test() {
*/
function perflab_aao_autoloaded_options_size() {
global $wpdb;
return $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' );
return (int) $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' );
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function test_perflab_aao_autoloaded_options_size() {
$test_option_string = 'test';
$test_option_string_bytes = mb_strlen( $test_option_string, '8bit' );
self::set_autoloaded_option( $test_option_string_bytes );
$this->assertEquals( $autoloaded_options_size + $test_option_string_bytes, perflab_aao_autoloaded_options_size() );
$this->assertSame( $autoloaded_options_size + $test_option_string_bytes, perflab_aao_autoloaded_options_size() );
}

/**
Expand All @@ -76,7 +76,7 @@ public static function set_autoloaded_option( $bytes = 800000 ) {
/**
* Generate random string with certain $length.
*
* @param int $length Length of string to create.
* @param int $length Length ( in bytes ) of string to create.
* @return string
*/
protected static function random_string_generator( $length ) {
Expand Down