wp_prepare_themes_for_js │ filter-hook │ WP 3.8.0

Allows you to change theme data on the themes.php admin page and in the Customizer.

It also lets you sort, modify, or remove themes displayed on the Themes page.

Usage

add_filter( 'wp_prepare_themes_for_js', 'wp_kama_prepare_themes_for_js_filter' );

/**
 * Function for `wp_prepare_themes_for_js` filter-hook.
 * 
 * @param array $prepared_themes Array of theme data.
 *
 * @return array
 */
function wp_kama_prepare_themes_for_js_filter( $prepared_themes ){
	// filter...
	return $prepared_themes;
}
$prepared_themes(array)
Array of themes.

Examples

#1 Remove a theme from the admin theme list

# Prevent the base theme from appearing on the themes.php admin page.
add_filter( 'wp_prepare_themes_for_js', function( $themes ){
	unset( $themes['dh5'] );
	return $themes;
} );

#2 Contents of each theme array element

add_filter( 'wp_prepare_themes_for_js', function( $themes ){
	print_r( $themes );
} );

/*
Array (

	[twentynineteen] => Array(

			[id]   => twentynineteen
			[name] => Twenty Nineteen
			[screenshot] => Array (
				[0] => https://dh5.com/content/themes/twentynineteen/screenshot.png
			)

			[description] => Our 2019 default theme is designed to show off the power of the block editor. It features custom styles for all the default blocks, and is built so that what you see in the editor looks like what you’ll see on your website. Twenty Nineteen is designed to be adaptable to a wide range of websites, whether you’re running a photo blog, launching a new business, or supporting a non-profit. Featuring ample whitespace and modern sans-serif headlines paired with classic serif body text, it’s built to be beautiful on all screen sizes.
			[author] => the WordPress team
			[authorAndUri] => <a href="https://wordpress.org/">the WordPress team</a>
			[version]    => 1.4
			[tags]       => One Column, flexible-header, Accessibility Ready, Custom Colors, custom-menu, Custom Logo, Editor Style, Featured Images, Footer Widgets, rtl-language-support, Sticky Post, threaded-comments, translation-ready
			[parent]     =>
			[active]     =>
			[hasUpdate]  =>
			[hasPackage] =>
			[update]     =>
			[actions] => Array
				(
					[activate] => https://dh5.com/core/wp-admin/themes.php?action=activate&stylesheet=twentynineteen&_wpnonce=9296974cb0
					[customize] => https://dh5.com/core/wp-admin/customize.php?theme=twentynineteen&return=%2Fcore%2Fwp-admin%2Fthemes.php
					[delete] => https://dh5.com/core/wp-admin/themes.php?action=delete&stylesheet=twentynineteen&_wpnonce=ac50870200
				)

		),
	[dh5] => array( ... ),
	[dh5-child] => array( ... ),

)

#3 Keep only the current theme in the list

add_filter( 'wp_prepare_themes_for_js', 'show_only_current_theme' );

/**
 * Keeps only the current theme in the theme list.
 *
 * @param array $themes
 *
 * @return array
 */
function show_only_current_theme( $themes ) {
	// Current theme.
	$theme = get_stylesheet();

	// Or any theme, for example Twenty Twenty.
	// $theme = 'twentytwenty';

	if ( isset( $themes[ $theme ] ) ) {
		$themes = [ $theme => $themes[ $theme ] ];
	}

	return $themes;
}

Changelog

Since 3.8.0 Introduced.

Where the hook is called

wp_prepare_themes_for_js()
wp_prepare_themes_for_js
wp-admin/includes/theme.php 812
$prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );

Where the hook is used in WordPress

Usage not found.