返回介绍

delete_network_option()

发布于 2017-09-10 22:06:01 字数 3968 浏览 976 评论 0 收藏 0

delete_network_option( int $network_id,  string $option )

Removes a network option by name.


description


参数

$network_id

(int) (Required) ID of the network. Can be null to default to the current network ID.

$option

(string) (Required) Name of option to remove. Expected to not be SQL-escaped.


返回值

(bool) True, if succeed. False, if failure.


源代码

File: wp-includes/option.php

function delete_network_option( $network_id, $option ) {
	global $wpdb;

	if ( $network_id && ! is_numeric( $network_id ) ) {
		return false;
	}

	$network_id = (int) $network_id;

	// Fallback to the current network if a network ID is not specified.
	if ( ! $network_id ) {
		$network_id = get_current_network_id();
	}

	/**
	 * Fires immediately before a specific network option is deleted.
	 *
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
	 *
	 * @since 3.0.0
	 * @since 4.4.0 The `$option` parameter was added.
	 * @since 4.7.0 The `$network_id` parameter was added.
	 *
	 * @param string $option     Option name.
	 * @param int    $network_id ID of the network.
	 */
	do_action( "pre_delete_site_option_{$option}", $option, $network_id );

	if ( ! is_multisite() ) {
		$result = delete_option( $option );
	} else {
		$row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
		if ( is_null( $row ) || ! $row->meta_id ) {
			return false;
		}
		$cache_key = "$network_id:$option";
		wp_cache_delete( $cache_key, 'site-options' );

		$result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) );
	}

	if ( $result ) {

		/**
		 * Fires after a specific network option has been deleted.
		 *
		 * The dynamic portion of the hook name, `$option`, refers to the option name.
		 *
		 * @since 2.9.0 As "delete_site_option_{$key}"
		 * @since 3.0.0
		 * @since 4.7.0 The `$network_id` parameter was added.
		 *
		 * @param string $option     Name of the network option.
		 * @param int    $network_id ID of the network.
		 */
		do_action( "delete_site_option_{$option}", $option, $network_id );

		/**
		 * Fires after a network option has been deleted.
		 *
		 * @since 3.0.0
		 * @since 4.7.0 The `$network_id` parameter was added.
		 *
		 * @param string $option     Name of the network option.
		 * @param int    $network_id ID of the network.
		 */
		do_action( 'delete_site_option', $option, $network_id );

		return true;
	}

	return false;
}

更新日志

Versiondescription
4.4.0Introduced.

相关函数

Uses

  • wp-includes/load.php: get_current_network_id()
  • wp-includes/cache.php: wp_cache_delete()
  • wp-includes/load.php: is_multisite()
  • wp-includes/plugin.php: do_action()
  • wp-includes/option.php: pre_delete_site_option_{$option}
  • wp-includes/option.php: delete_site_option_{$option}
  • wp-includes/option.php: delete_site_option
  • wp-includes/option.php: delete_option()
  • wp-includes/wp-db.php: wpdb::get_row()
  • wp-includes/wp-db.php: wpdb::delete()
  • wp-includes/wp-db.php: wpdb::prepare()
  • Show 6 more uses Hide more uses

Used By

  • wp-includes/option.php: delete_site_option()

User Contributed Notes

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

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

发布评论

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