返回介绍

get_blog_option()

发布于 2017-09-10 22:53:43 字数 3197 浏览 968 评论 0 收藏 0

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

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


description

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 );
}

更新日志

Versiondescription
MUIntroduced.

相关函数

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().

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

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

发布评论

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