get_blog_option() - WordPress 函数参考中文文档

返回介绍

get_blog_option()

发布于 2017-09-10 字数3199 浏览 879 评论 0

get_blog_option( int $id,  string $option,  mixed $default = false )

Retrieve option value for a given blog id based on name of option.


描述

If the option does not exist or does not have a value, then the return value will be false. This is useful to check whether you need to install an option and is commonly used during installation of plugin options and to test whether upgrading is required.

If the option was serialized then it will be unserialized when it is returned.


参数

$id

(int)
(Required)
A blog ID. Can be null to refer to the current blog.

$option

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

$default

(mixed)
(Optional)
Default value to return if the option does not exist.

Default value: false


返回值

(mixed) Value set for the option.


源代码

File: wp-includes/ms-blogs.php

function get_blog_option( $id, $option, $default = false ) {
	$id = (int) $id;

	if ( empty( $id ) )
		$id = get_current_blog_id();

	if ( get_current_blog_id() == $id )
		return get_option( $option, $default );

	switch_to_blog( $id );
	$value = get_option( $option, $default );
	restore_current_blog();

	/**
	 * Filters a blog option value.
	 *
	 * The dynamic portion of the hook name, `$option`, refers to the blog option name.
	 *
	 * @since 3.5.0
	 *
	 * @param string  $value The option value.
	 * @param int     $id    Blog ID.
	 */
	return apply_filters( "blog_option_{$option}", $value, $id );
}

更新日志

Version 描述
MU Introduced.

相关函数

Uses

  • wp-includes/load.php:
    get_current_blog_id()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/option.php:
    get_option()
  • wp-includes/ms-blogs.php:
    switch_to_blog()
  • wp-includes/ms-blogs.php:
    restore_current_blog()
  • wp-includes/ms-blogs.php:
    blog_option_{$option}
  • Show 1 more use
    Hide more uses


Used By

  • wp-includes/rest-api.php:
    get_rest_url()
  • wp-includes/ms-functions.php:
    install_blog()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Store Locator Plus

    This function is only available if WordPress has been installed and configured as a multisite install. Check function_exists() or use is_multisite() before calling get_blog_option().

上一篇:get_blog_list()

下一篇:get_blog_permalink()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!