From 78469b71b04610a26f8274e8fec5e75518187704 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 31 Mar 2015 20:03:55 +0000 Subject: [PATCH] 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 --- src/wp-admin/includes/theme.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index 2427bb400d..0d5c0beea1 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -409,8 +409,26 @@ function themes_api( $action, $args = null ) { function wp_prepare_themes_for_js( $themes = null ) { $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. - $prepared_themes = array( $current_theme => array() ); + $prepared_themes[ $current_theme ] = array(); if ( null === $themes ) { $themes = wp_get_themes( array( 'allowed' => true ) );