add_option

do_action( 'add_option', string $option, mixed $value )

动作钩子::在添加选项之前触发。
Action Hook: Fires before an option is added.
目录锚点:#参数#源码

参数(Parameters)

参数类型说明
$option (string) 要添加的选项的名称。
$value (mixed) 期权的价值。

源码(Source)

/**
 * Add a new option.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is inserted into the database. Remember,
 * resources can not be serialized or added as an option.
 *
 * You can create options without values and then update the values later.
 * Existing options will not be updated and checks are performed to ensure that you
 * aren't adding a protected WordPress option. Care should be taken to not name
 * options the same as the ones which are protected.
 *
 * @since 1.0.0
 *
 * @global wpdb $wpdb
 *
 * @param string         $option      Name of option to add. Expected to not be SQL-escaped.
 * @param mixed          $value       Optional. Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
 * @param string         $deprecated  Optional. Description. Not used anymore.
 * @param string|bool    $autoload    Optional. Whether to load the option when WordPress starts up.
 *                                    Default is enabled. Accepts 'no' to disable for legacy reasons.
 * @return bool False if option was not added and true if option was added.
 */
function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
	global $wpdb;

	if ( !empty( $deprecated ) )
		_deprecated_argument( __FUNCTION__, '2.3' );

	$option = trim($option);
	if ( empty($option) )
		return false;

	wp_protect_special_option( $option );

	if ( is_object($value) )
		$value = clone $value;

	$value = sanitize_option( $option, $value );

	// Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
	$notoptions = wp_cache_get( 'notoptions', 'options' );
	if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) )
		/** This filter is documented in wp-includes/option.php */
		if ( apply_filters( 'default_option_' . $option, false ) !== get_option( $option ) )
			return false;

	$serialized_value = maybe_serialize( $value );
	$autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';

	/**
	 * Fires before an option is added.
	 *
	 * @since 2.9.0
	 *
	 * @param string $option Name of the option to add.
	 * @param mixed  $value  Value of the option.
	 */
	do_action( 'add_option', $option, $value );

	$result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) );
	if ( ! $result )
		return false;

	if ( ! defined( 'WP_INSTALLING' ) ) {
		if ( 'yes' == $autoload ) {
			$alloptions = wp_load_alloptions();
			$alloptions[ $option ] = $serialized_value;
			wp_cache_set( 'alloptions', $alloptions, 'options' );
		} else {
			wp_cache_set( $option, $serialized_value, 'options' );
		}
	}

	// This option exists now
	$notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
	if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
		unset( $notoptions[$option] );
		wp_cache_set( 'notoptions', $notoptions, 'options' );
	}

	/**
	 * Fires after a specific option has been added.
	 *
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
	 *
	 * @since 2.5.0 As "add_option_{$name}"
	 * @since 3.0.0
	 *
	 * @param string $option Name of the option to add.
	 * @param mixed  $value  Value of the option.
	 */
	do_action( "add_option_{$option}", $option, $value );

	/**
	 * Fires after an option has been added.
	 *
	 * @since 2.9.0
	 *
	 * @param string $option Name of the added option.
	 * @param mixed  $value  Value of the option.
	 */
	do_action( 'added_option', $option, $value );
	return true;
}
更新版本 源码位置 使用 被使用
2.9.0 wp-includes/option.php:502 1 0

activated_plugin

do_action( 'activated_plugin', string $plugin, bool $network_wide )动作钩子::插件激活后激发。Action Hook: Fires after a plugin has been activated.目录锚点:#说明#参数#源码#笔记说明(Description)如果插件被静默激活(例如在更新期间),则不会触发此挂钩。参数(Parameters)参数类型说明 $plugin ...

日期:2020-07-26 13:19:04 浏览:530

activate_blog

do_action( 'activate_blog', string $id )动作钩子::在网络站点激活后激发。Action Hook: Fires after a network site is activated.目录锚点:#参数#源码参数(Parameters)参数类型说明 $id (string) 激活站点的ID。 源码(Source)更新版本源码位置使用被使用MU (3.0.0) w...

日期:2020-07-26 13:19:03 浏览:781

activate_header

do_action( 'activate_header' )操作挂钩:在加载网站激活页之前激发。Action Hook: Fires before the Site Activation page is loaded.目录锚点:#源码#笔记源码(Source)更新版本源码位置使用被使用3.0.0 wp-activate.php:7900笔记(Notes)在wp中定义了activate_header hook-激活.php包含主题的文件header.php文件但不是函数.php文件。因此,如果在主题的函数.p...

日期:2020-07-26 13:19:04 浏览:724

activate_wp_head

do_action( 'activate_wp_head' )操作挂钩:在加载网站激活页之前激发。Action Hook: Fires before the Site Activation page is loaded.目录锚点:#说明#源码说明(Description)对“wp_head”动作开火。源码(Source)更新版本源码位置使用被使用3.0.0 wp-activate.php:9610...

日期:2020-07-26 13:19:04 浏览:931

activate_{$plugin}

do_action( "activate_{$plugin}", bool $network_wide )动作钩子::当一个特定的插件被激活时触发。Action Hook: Fires as a specific plugin is being activated.目录锚点:#说明#参数#源码说明(Description)这个钩子是register_activation_hook()内部使用的“activation”钩子。钩子名$plugin的动态部分引用了plugin basename。参数(Param...

日期:2020-07-26 13:19:03 浏览:881

activity_box_end

do_action( 'activity_box_end' )动作钩子::在“一目了然”仪表板小部件的末尾触发。Action Hook: Fires at the end of the ‘At a Glance’ dashboard widget.目录锚点:#说明#源码说明(Description)在3.8.0之前,小部件被命名为“立即”。源码(Source)更新版本源码位置使用被使用2.0.0 wp-admin/includes/dashboard.php:40110...

日期:2020-07-26 13:19:04 浏览:498

added_existing_user

do_action( 'added_existing_user', int $user_id, true|WP_Error $result )操作挂钩:在现有用户添加到站点后立即激发。Action Hook: Fires immediately after an existing user is added to a site.目录锚点:#参数#源码参数(Parameters)参数类型说明 $user_id (int) ...

日期:2020-09-02 17:44:23 浏览:507

added_option

do_action( 'added_option', string $option, mixed $value )动作钩子::在添加选项后激发。Action Hook: Fires after an option has been added.目录锚点:#参数#源码参数(Parameters)参数类型说明 $option (string) 添加的选项的名称。 ...

日期:2020-08-29 11:56:53 浏览:690

added_term_relationship

do_action( 'added_term_relationship', int $object_id, int $tt_id, string $taxonomy )动作钩子::在添加对象项关系后立即激发。Action Hook: Fires immediately after an object-term relationship is added.目录锚点:#参数#源码参数(Parameters)参数类型说明 $object_id ...

日期:2020-09-02 17:44:14 浏览:707

added_usermeta

do_action( 'added_usermeta' )动作钩:Action Hook: 目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/deprecated.php:240800...

日期:2020-09-02 17:44:27 浏览:723