返回介绍

set_theme_mod()

发布于 2017-09-11 10:22:30 字数 3589 浏览 1020 评论 0 收藏 0

set_theme_mod( string $name,  mixed $value )

Update theme modification value for the current theme.


description


参数

$name

(string) (Required) Theme modification name.

$value

(mixed) (Required) Theme modification value.


源代码

File: wp-includes/theme.php

function set_theme_mod( $name, $value ) {
	$mods = get_theme_mods();
	$old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false;

	/**
	 * Filters the theme mod value on save.
	 *
	 * The dynamic portion of the hook name, `$name`, refers to the key name of
	 * the modification array. For example, 'header_textcolor', 'header_image',
	 * and so on depending on the theme options.
	 *
	 * @since 3.9.0
	 *
	 * @param string $value     The new value of the theme mod.
	 * @param string $old_value The current value of the theme mod.
	 */
	$mods[ $name ] = apply_filters( "pre_set_theme_mod_{$name}", $value, $old_value );

	$theme = get_option( 'stylesheet' );
	update_option( "theme_mods_$theme", $mods );
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: pre_set_theme_mod_{$name}
  • wp-includes/theme.php: get_theme_mods()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/option.php: update_option()
  • wp-includes/option.php: get_option()

Used By

  • wp-includes/theme.php: wp_update_custom_css_post()
  • wp-includes/theme.php: wp_get_custom_css_post()
  • wp-includes/customize/class-wp-customize-custom-css-setting.php: WP_Customize_Custom_CSS_Setting::update()
  • wp-includes/class-wp-customize-setting.php: WP_Customize_Setting::set_root_value()
  • wp-admin/includes/ajax-actions.php: wp_ajax_menu_locations_save()
  • wp-admin/custom-header.php: Custom_Image_Header::set_header_image()
  • wp-admin/custom-header.php: Custom_Image_Header::reset_header_image()
  • wp-admin/custom-header.php: Custom_Image_Header::take_action()
  • wp-admin/custom-background.php: Custom_Background::wp_set_background_image()
  • wp-admin/custom-background.php: Custom_Background::take_action()
  • wp-admin/custom-background.php: Custom_Background::handle_upload()
  • wp-includes/theme.php: switch_theme()
  • wp-includes/nav-menu.php: wp_delete_nav_menu()
  • Show 8 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note Contributed by Bican Marian Valeriu

    Sample usage, hooking into ‘init’

    function wecodeart_theme_mods() {
    	set_theme_mod('my_mod_one', 'new_mode_one_value');
    }
    
    add_action( 'init', 'wecodeart_theme_mods' );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文