Skip to content

Commit d814c85

Browse files
committed
Merge branch 'release/3.0.0' into add/1045-experimental-plugin-annotations
2 parents 6c51a4b + 5b9d0ba commit d814c85

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed
File renamed without changes.

.github/workflows/spell-check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ jobs:
1010
- uses: actions/checkout@v3
1111
- name: Search for misspellings
1212
uses: crate-ci/typos@master
13+
with:
14+
config: ./.github/typos.toml

includes/site-health/audit-autoloaded-options/helper.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,18 @@ function perflab_aao_autoloaded_options_test() {
101101
*/
102102
function perflab_aao_autoloaded_options_size() {
103103
global $wpdb;
104-
return (int) $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' );
104+
105+
$autoload_values = perflab_aao_get_autoload_values_to_autoload();
106+
107+
return (int) $wpdb->get_var(
108+
$wpdb->prepare(
109+
sprintf(
110+
"SELECT SUM(LENGTH(option_value)) FROM $wpdb->options WHERE autoload IN (%s)",
111+
implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) )
112+
),
113+
$autoload_values
114+
)
115+
);
105116
}
106117

107118
/**
@@ -130,7 +141,17 @@ function perflab_aao_query_autoloaded_options() {
130141
*/
131142
$option_threshold = apply_filters( 'perflab_aao_autoloaded_options_table_threshold', 100 );
132143

133-
return $wpdb->get_results( $wpdb->prepare( "SELECT option_name, LENGTH(option_value) AS option_value_length FROM {$wpdb->options} WHERE autoload='yes' AND LENGTH(option_value) > %d ORDER BY option_value_length DESC LIMIT 20", $option_threshold ) );
144+
$autoload_values = perflab_aao_get_autoload_values_to_autoload();
145+
146+
return $wpdb->get_results(
147+
$wpdb->prepare(
148+
sprintf(
149+
"SELECT option_name, LENGTH(option_value) AS option_value_length FROM {$wpdb->options} WHERE autoload IN (%s)",
150+
implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) )
151+
) . ' AND LENGTH(option_value) > %d ORDER BY option_value_length DESC LIMIT 20',
152+
array_merge( $autoload_values, array( $option_threshold ) )
153+
)
154+
);
134155
}
135156

136157
/**
@@ -227,3 +248,18 @@ function perflab_aao_get_disabled_autoloaded_options_table() {
227248

228249
return $html_table;
229250
}
251+
252+
/**
253+
* Gets the autoload values in the database that should trigger their option to be autoloaded.
254+
*
255+
* @since n.e.x.t
256+
*
257+
* @return array List of autoload values.
258+
*/
259+
function perflab_aao_get_autoload_values_to_autoload() {
260+
if ( function_exists( 'wp_autoload_values_to_autoload' ) ) {
261+
return wp_autoload_values_to_autoload();
262+
}
263+
264+
return array( 'yes' );
265+
}

tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,18 @@ public function test_perflab_aao_autoloaded_options_test_warning() {
5959
*/
6060
public function test_perflab_aao_autoloaded_options_size() {
6161
global $wpdb;
62-
$autoloaded_options_size = $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' );
62+
63+
$autoload_values = perflab_aao_get_autoload_values_to_autoload();
64+
65+
$autoloaded_options_size = $wpdb->get_var(
66+
$wpdb->prepare(
67+
sprintf(
68+
"SELECT SUM(LENGTH(option_value)) FROM $wpdb->options WHERE autoload IN (%s)",
69+
implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) )
70+
),
71+
$autoload_values
72+
)
73+
);
6374
$this->assertEquals( $autoloaded_options_size, perflab_aao_autoloaded_options_size() );
6475

6576
// Add autoload option.
@@ -148,7 +159,9 @@ static function () {
148159
*/
149160
public static function set_autoloaded_option( $bytes = 800000 ) {
150161
$heavy_option_string = wp_generate_password( $bytes );
151-
add_option( self::AUTOLOADED_OPTION_KEY, $heavy_option_string );
162+
163+
// Force autoloading so that WordPress core does not override it. See https://core.trac.wordpress.org/changeset/57920.
164+
add_option( self::AUTOLOADED_OPTION_KEY, $heavy_option_string, '', true );
152165
}
153166

154167
/**

0 commit comments

Comments
 (0)