get_blog_option

函式
get_blog_option ( $id, $option, $default = false )
引數
  • (int) $id A blog ID. Can be null to refer to the current blog.
    Required:
  • (string) $option Name of option to retrieve. Expected to not be SQL-escaped.
    Required:
  • (mixed) $default Optional. Default value to return if the option does not exist.
    Required:
    Default: false
返回值
  • (mixed) Value set for the option.
定義位置
相關方法
delete_blog_optionadd_blog_optionget_optionupdate_blog_optionget_blog_post
引入
-
棄用
-

get_blog_option:根據站點的ID或域/路徑組合檢索網路中站點的選項值。返回選項值或預設值(如果不存在)。

根據選項的名稱,為一個給定的部落格ID檢索選項值。

如果該選項不存在或沒有一個值,那麼返回值將是false。這對於檢查你是否需要安裝一個選項很有用,通常在安裝外掛選項時使用,並測試是否需要升級。

如果選項被序列化了,那麼當它被返回時將被取消序列化。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >