wp_prepare_themes_for_js
Дозволяє змінити дані тем на сторінці адмінки 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
(масив) - Масив тем.
Приклади
#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;
} );#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 позначте тему, яка була розроблена для show of power of the block editor. Це особливості стилів для всіх додаткових блоків, і є так, що ви збираєтеся в editor editors як те, що ви збираєтеся на свій веб-сайт. Twenty Nineteen є розроблений для адаптивного до широкого діапазону веб-сайтів, де ви збираєтеся на фото blog, повідомляючи про новий бізнес, або підтримуючи неможливість. Відображаючи величезний білий простір і сучасні sans-serif headlines paired with classic serif body тексту, це побудови для 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 Залишимо у списку тем лише поточну тему
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-admin/includes/theme.php 803
$prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
Де використовується хук у WordPress
Використання не знайдено.