Make WordPress Core

Ticket #54221: 54221.diff

File 54221.diff, 1.7 KB (added by wpgurudev, 3 years ago)
  • src/wp-includes/option.php

    diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php
    index b902aee87e..8b247cdadb 100644
    a b function wp_load_alloptions( $force_cache = false ) { 
    344344        return apply_filters( 'alloptions', $alloptions );
    345345}
    346346
     347/**
     348 * Filters autoloaded options.
     349 * This is particularly useful when option is set to be autoloaded in DB,
     350 * but has a large size and causing performance impact.
     351 *
     352 * @param string $query Query being executed.
     353 *
     354 * @return string Filtered query to exclude certain options from autoloading.
     355 */
     356function wp_filter_autoloaded_options( $query ) {
     357    global $wpdb;
     358
     359    $alloptions_query = "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'";
     360
     361    // If this is not the alloptions query, return the original query.
     362    if ( $query !== $alloptions_query ) {
     363        return $query;
     364    }
     365
     366        /**
     367         * Filters the options which needs exclusion from autoloading.
     368         *
     369         * @since 6.1.2
     370         *
     371         * @return array List of options to exlude from autoloading.
     372         */
     373    $exclude_autoload_options = apply_filters( 'exlude_autoloaded_options', array( '_transient_dirsize_cache' ) );
     374    $not_in_query             = implode( ', ', array_fill( 0, count( $exclude_autoload_options ), '%s' ) );
     375    $alloptions_query         = $wpdb->prepare( $alloptions_query . " AND option_name NOT IN ( $not_in_query )", $exclude_autoload_options );
     376
     377    return $alloptions_query;
     378}
     379add_filter( 'query', 'wp_filter_autoloaded_options' );
     380
    347381/**
    348382 * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
    349383 *