get_theme_mods() WP 3.1.0
Получает все настройки (опции) темы. Тут сохраняются настройки Кастомайзера.
Также, вызов этой функции обновит название опции в таблице wp_options со старого "mods_{$theme_name}" (если оно есть) на новое "theme_mods_{$theme_slug}".
Используйте get_theme_mod(), чтобы получить отдельную настройку темы.
Работает на основе: get_option()
1 раз — 0.001737 сек (очень медленно) | 50000 раз — 2.25 сек (быстро) | PHP 7.0.32, WP 5.0.3
Хуков нет.
Возвращает
Массив/false. Настройки темы. Если настроек у темы нет, то вернет false.
Использование
get_theme_mods();
Примеры
#1 Получим все настройки темы
Этот пример показывает как получить все настройки темы в виде массива.
$mods = get_theme_mods(); print_r( $mods ); /* Array ( [0] => [nav_menu_locations] => Array [header] => 2 [footer_credit] => 3 [footer_left] => 4 [footer_right] => 5 [custom_css_post_id] => -1 [custom_logo] => 7 [sidebars_widgets] => Array [time] => 1550171673 [data] => Array [wp_inactive_widgets] => Array [0] => search-2 [1] => recent-posts-2 [2] => recent-comments-2 [3] => archives-2 [4] => categories-2 [5] => meta-2 [footer_bg_image] => http://dh5.com/content/uploads/2019/02/bg-footer.jpg ) */ echo $mods['header_textcolor']; // > 333
Список изменений
С версии 3.1.0 | Введена. |
Код get_theme_mods() get theme mods WP 5.6.2
function get_theme_mods() {
$theme_slug = get_option( 'stylesheet' );
$mods = get_option( "theme_mods_$theme_slug" );
if ( false === $mods ) {
$theme_name = get_option( 'current_theme' );
if ( false === $theme_name ) {
$theme_name = wp_get_theme()->get( 'Name' );
}
$mods = get_option( "mods_$theme_name" ); // Deprecated location.
if ( is_admin() && false !== $mods ) {
update_option( "theme_mods_$theme_slug", $mods );
delete_option( "mods_$theme_name" );
}
}
return $mods;
}