Make WordPress Core

10/10/2017 07:08:51 AM (7 years ago)

Customize: Improve behavior and extensibility of theme loading and searching.

  • Introduce WP_Customize_Themes_Section::$filter_type, which has built-in functionality for local and remote filtering. When this set to local, all themes are assumed to be loaded from Ajax when the section is first loaded, and subsequent searching/filtering is applied to the loaded collection of themes within the section. This is how the core "Installed" section behaves - third-party sources with limited numbers of themes may consider leveraging this implementation. When this is set to remote, searching and filtering always triggers a new remote query via Ajax. The core "" section uses this approach, as it has over 5000 themes to search.
  • Refactor filterSearch() to accept a raw term string as input. This enables a feature filter to be used on a section where filter_type is local.
  • Refactor filter() on a theme control to check for an array of terms. Also sort the results by the number of matches. Rather than searching for an exact match, this will now search for each word in a search distinctly, allowing things like tags to rank in search results more accurately.
  • Split loadControls() into two functions for themes section JS: loadThemes() to initiate and manage an Ajax request and loadControls() to create theme controls based on the results of the Ajax call. If third-party sections need to change the way controls are loaded, such as by using a custom control subclass of WP_Customize_Theme_Control, this allows them to use the core logic for managing the Ajax call and only override the actual control-creation process.
  • Introduce customize_load_themes filter to facilitate loading themes from third-party sources (or modifying the results of the core sections).
  • Bring significant improvements to the installed themes search filter.

Props celloexpressions.
Amends [41648].
See #37661.
Fixes #42049.

1 edited


  • trunk/src/wp-includes/customize/class-wp-customize-themes-section.php

    r41709 r41807  
    3939    /**
     40     * Theme section filter type.
     41     *
     42     * Determines whether filters are applied to loaded (local) themes or by initiating a new remote query (remote).
     43     * When filtering is local, the initial themes query is not paginated by default.
     44     *
     45     * @since 4.9.0
     46     * @var string
     47     */
     48    public $filter_type = 'local';
     50    /**
    4051     * Get section parameters for JS.
    4152     *
    4657        $exported = parent::json();
    4758        $exported['action'] = $this->action;
     59        $exported['filter_type'] = $this->filter_type;
    4961        return $exported;
Note: See TracChangeset for help on using the changeset viewer.