set_theme_mod()更新当前主题的自定义修改值

目录

描述

译文

更新当前主题的主题修改值

原文

Creates or updates a modification setting for the current theme. Along with get_theme_mod() this function sometimes offers theme developers a simpler alternative to the Settings API when there is a need to handle basic theme-specific settings.

set_theme_mod() 描述

用法

<?php set_theme_mod$name$value ); ?>

set_theme_mod() 用法

参数

$name

(string) (必填) Theme modification name.

默认值: None

$value

(string) (必填) Theme modification value.

默认值: None

set_theme_mod() 参数

返回值

(void) 

This function does not return a value.

set_theme_mod() 返回值

注意

set_theme_mod() 注意

历史

添加于 版本: 2.1.0

set_theme_mod() 历史

源文件

set_theme_mod() 函数的代码位于 wp-includes/theme.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Update theme modification value for the current theme.
 *
 * @since 2.1.0
 *
 * @param string $name  Theme modification name.
 * @param mixed  $value Theme modification value.
 */
function set_theme_mod( $name, $value ) {
	$mods = get_theme_mods();
	$old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false;

	/**
	 * Filter 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 );
}

set_theme_mod() 源文件

相关