^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_network_option()用法示例

get_network_option( int $network_id,  string $option,  mixed $default = false )

Retrieve a network’s option value based on the option name.


描述


参数

$network_id

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

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

$option

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

$default

(mixed)
(Optional)
Value to return if the option doesn’t exist.

Default value: false


返回值

(mixed) Value set for the option.


源代码

File: wp-includes/option.php

function get_network_option( $network_id, $option, $default = false ) {
	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();
	}

	/**
	 * Filters an existing network option before it is retrieved.
	 *
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
	 *
	 * Passing a truthy value to the filter will effectively short-circuit retrieval,
	 * returning the passed value instead.
	 *
	 * @since 2.9.0 As 'pre_site_option_' . $key
	 * @since 3.0.0
	 * @since 4.4.0 The `$option` parameter was added.
	 * @since 4.7.0 The `$network_id` parameter was added.
	 *
	 * @param mixed  $pre_option The default value to return if the option does not exist.
	 * @param string $option     Option name.
	 * @param int    $network_id ID of the network.
	 */
	$pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id );

	if ( false !== $pre ) {
		return $pre;
	}

	// prevent non-existent options from triggering multiple queries
	$notoptions_key = "$network_id:notoptions";
	$notoptions = wp_cache_get( $notoptions_key, 'site-options' );

	if ( isset( $notoptions[ $option ] ) ) {

		/**
		 * Filters a specific default network option.
		 *
		 * The dynamic portion of the hook name, `$option`, refers to the option name.
		 *
		 * @since 3.4.0
		 * @since 4.4.0 The `$option` parameter was added.
		 * @since 4.7.0 The `$network_id` parameter was added.
		 *
		 * @param mixed  $default    The value to return if the site option does not exist
		 *                           in the database.
		 * @param string $option     Option name.
		 * @param int    $network_id ID of the network.
		 */
		return apply_filters( "default_site_option_{$option}", $default, $option, $network_id );
	}

	if ( ! is_multisite() ) {
		/** This filter is documented in wp-includes/option.php */
		$default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
		$value = get_option( $option, $default );
	} else {
		$cache_key = "$network_id:$option";
		$value = wp_cache_get( $cache_key, 'site-options' );

		if ( ! isset( $value ) || false === $value ) {
			$row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );

			// Has to be get_row instead of get_var because of funkiness with 0, false, null values
			if ( is_object( $row ) ) {
				$value = $row->meta_value;
				$value = maybe_unserialize( $value );
				wp_cache_set( $cache_key, $value, 'site-options' );
			} else {
				if ( ! is_array( $notoptions ) ) {
					$notoptions = array();
				}
				$notoptions[ $option ] = true;
				wp_cache_set( $notoptions_key, $notoptions, 'site-options' );

				/** This filter is documented in wp-includes/option.php */
				$value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
			}
		}
	}

	/**
	 * Filters the value of an existing network option.
	 *
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
	 *
	 * @since 2.9.0 As 'site_option_' . $key
	 * @since 3.0.0
	 * @since 4.4.0 The `$option` parameter was added.
	 * @since 4.7.0 The `$network_id` parameter was added.
	 *
	 * @param mixed  $value      Value of network option.
	 * @param string $option     Option name.
	 * @param int    $network_id ID of the network.
	 */
	return apply_filters( "site_option_{$option}", $value, $option, $network_id );
}

更新日志

Version 描述
4.4.0 Introduced.

相关函数

Uses

  • wp-includes/load.php:
    get_current_network_id()
  • wp-includes/cache.php:
    wp_cache_get()
  • wp-includes/cache.php:
    wp_cache_set()
  • wp-includes/load.php:
    is_multisite()
  • wp-includes/functions.php:
    maybe_unserialize()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/option.php:
    site_option_{$option}
  • wp-includes/option.php:
    pre_site_option_{$option}
  • wp-includes/option.php:
    default_site_option_{$option}
  • wp-includes/option.php:
    get_option()
  • wp-includes/wp-db.php:
    wpdb::get_row()
  • wp-includes/wp-db.php:
    wpdb::prepare()
  • Show 7 more uses


Used By

  • wp-includes/class-wp-network.php:
    WP_Network::_set_site_name()
  • wp-includes/option.php:
    update_network_option()
  • wp-includes/option.php:
    add_network_option()
  • wp-includes/option.php:
    get_site_option()
  • wp-includes/ms-functions.php:
    get_user_count()
  • wp-includes/ms-functions.php:
    get_blog_count()
  • Show 1 more used by
    Hide more used by


让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈