wp_prepare_themes_for_jsхук-фильтрWP 3.8.0

Позволяет изменить данные тем на странице админки themes.php и кастомайзере.

Также позволяет отсортировать/изменить/удалить темы отображаемые на странице тем.

Использование

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(массив)
Массив тем.

Примеры

0

#1 Удалим тему из списка тем на странице админки

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

#2 Что содержит каждый элемент массива тем

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( ... ),

)
0

#3 Оставим в списке тем только текущую тему

add_filter( 'wp_prepare_themes_for_js', 'show_only_current_theme' );

/**
 * Оставим в списке тем только текущую тему.
 *
 * @param array $themes
 *
 * @return array
 */
function show_only_current_theme( $themes ) {
	// Текущая тема
	$theme = get_stylesheet();

	// Или любая тема, например Twenty Twenty
	// $theme = 'twentytwenty';

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

	return $themes;
}

Список изменений

С версии 3.8.0 Введена.

Где вызывается хук

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

Где используется хук в WordPress

Использование не найдено.