Themes: Add a filter to short-circuit `wp_prepare_themes_for_js()`.

props mattwiebe, DrewAPicture.
fixes #31789.

git-svn-id: https://develop.svn.wordpress.org/trunk@31943 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2015-03-31 20:03:55 +00:00
parent dcc75b1202
commit 78469b71b0
1 changed files with 19 additions and 1 deletions

View File

@ -409,8 +409,26 @@ function themes_api( $action, $args = null ) {
function wp_prepare_themes_for_js( $themes = null ) { function wp_prepare_themes_for_js( $themes = null ) {
$current_theme = get_stylesheet(); $current_theme = get_stylesheet();
/**
* Filter theme data before it is prepared for JavaScript.
*
* Passing a non-empty array will result in wp_prepare_themes_for_js() returning
* early with that value instead.
*
* @since 4.2.0
*
* @param array $prepared_themes An associative array of theme data. Default empty array.
* @param null|array $themes An array of WP_Theme objects to prepare, if any.
* @param string $current_theme The current theme slug.
*/
$prepared_themes = (array) apply_filters( 'pre_wp_prepare_themes_for_js', array(), $themes, $current_theme );
if ( ! empty( $prepared_themes ) ) {
return $prepared_themes;
}
// Make sure the current theme is listed first. // Make sure the current theme is listed first.
$prepared_themes = array( $current_theme => array() ); $prepared_themes[ $current_theme ] = array();
if ( null === $themes ) { if ( null === $themes ) {
$themes = wp_get_themes( array( 'allowed' => true ) ); $themes = wp_get_themes( array( 'allowed' => true ) );