WordPress函数文档get_blog_details()
获取博客的详细信息 描述 Retrieve the details for a blog from the b…
获取博客的详细信息
描述
Retrieve the details for a blog from the blogs table and blog options.
See: WPMU_Functions/get_blog_details
用法
<?php get_blog_details( $fields, $get_all ); ?>
参数
$fields
(int|string|array) (可选) A blog ID, a blog slug, or an array of fields to query against. If not specified the current blog ID is used.
默认值: null
$get_all
(boolean) (可选) Whether to retrieve all details or only the details in the blogs table.
默认值: true
示例
1
2
3
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
|
注意
使用到 global $wpdb
源文件
get_blog_details() 函数的代码位于 wp-includes/ms-blogs.php
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* Retrieve the details for a blog from the blogs table and blog options.
*
* @since MU
*
* @global wpdb $wpdb
*
* @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against.
* If not specified the current blog ID is used.
* @param bool $get_all Whether to retrieve all details or only the details in the blogs table.
* Default is true.
* @return object|false Blog details on success. False on failure.
*/
function get_blog_details( $fields = null, $get_all = true ) {
global $wpdb;
if ( is_array($fields ) ) {
if ( isset($fields[‘blog_id’]) ) {
$blog_id = $fields[‘blog_id’];
} elseif ( isset($fields[‘domain’]) && isset($fields[‘path’]) ) {
$key = md5( $fields[‘domain’] . $fields[‘path’] );
$blog = wp_cache_get($key, ‘blog-lookup’);
if ( false !== $blog )
return $blog;
if ( substr( $fields[‘domain’], 0, 4 ) == ‘www.’ ) {
$nowww = substr( $fields[‘domain’], 4 );
$blog = $wpdb->get_row( $wpdb->prepare( “SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC”, $nowww, $fields[‘domain’], $fields[‘path’] ) );
} else {
$blog = $wpdb->get_row( $wpdb->prepare( “SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s”, $fields[‘domain’], $fields[‘path’] ) );
}
if ( $blog ) {
wp_cache_set($blog->blog_id . ‘short’, $blog, ‘blog-details’);
$blog_id = $blog->blog_id;
} else {
return false;
}
} elseif ( isset($fields[‘domain’]) && is_subdomain_install() ) {
$key = md5( $fields[‘domain’] );
$blog = wp_cache_get($key, ‘blog-lookup’);
if ( false !== $blog )
return $blog;
if ( substr( $fields[‘domain’], 0, 4 ) == ‘www.’ ) {
$nowww = substr( $fields[‘domain’], 4 );
$blog = $wpdb->get_row( $wpdb->prepare( “SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC”, $nowww, $fields[‘domain’] ) );
} else {
$blog = $wpdb->get_row( $wpdb->prepare( “SELECT * FROM $wpdb->blogs WHERE domain = %s”, $fields[‘domain’] ) );
}
if ( $blog ) {
wp_cache_set($blog->blog_id . ‘short’, $blog, ‘blog-details’);
$blog_id = $blog->blog_id;
} else {
return false;
}
} else {
return false;
}
} else {
if ( ! $fields )
$blog_id = get_current_blog_id();
elseif ( ! is_numeric( $fields ) )
$blog_id = get_id_from_blogname( $fields );
else
$blog_id = $fields;
}
$blog_id = (int) $blog_id;
$all = $get_all == true ? ” : ‘short’;
$details = wp_cache_get( $blog_id . $all, ‘blog-details’ );
if ( $details ) {
if ( ! is_object( $details ) ) {
if ( $details == –1 ) {
return false;
} else {
// Clear old pre-serialized objects. Cache clients do better with that.
wp_cache_delete( $blog_id . $all, ‘blog-details’ );
unset($details);
}
} else {
return $details;
}
}
// Try the other cache.
if ( $get_all ) {
$details = wp_cache_get( $blog_id . ‘short’, ‘blog-details’ );
} else {
$details = wp_cache_get( $blog_id, ‘blog-details’ );
// If short was requested and full cache is set, we can return.
if ( $details ) {
if ( ! is_object( $details ) ) {
if ( $details == –1 ) {
return false;
} else {
// Clear old pre-serialized objects. Cache clients do better with that.
wp_cache_delete( $blog_id, ‘blog-details’ );
unset($details);
}
} else {
return $details;
}
}
}
if ( empty($details) ) {
$details = $wpdb->get_row( $wpdb->prepare( “SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */”, $blog_id ) );
if ( ! $details ) {
// Set the full cache.
wp_cache_set( $blog_id, –1, ‘blog-details’ );
return false;
}
}
if ( ! $get_all ) {
wp_cache_set( $blog_id . $all, $details, ‘blog-details’ );
return $details;
}
switch_to_blog( $blog_id );
$details->blogname = get_option( ‘blogname’ );
$details->siteurl = get_option( ‘siteurl’ );
$details->post_count = get_option( ‘post_count’ );
SevenTrust_current_blog();
/**
* Filter a blog’s details.
*
* @since MU
*
* @param object $details The blog details.
*/
$details = apply_filters( ‘blog_details’, $details );
wp_cache_set( $blog_id . $all, $details, ‘blog-details’ );
$key = md5( $details->domain . $details->path );
wp_cache_set( $key, $details, ‘blog-lookup’ );
return $details;
}
|
相关
- 原文:http://codex.wordpress.org/Function_Reference/get_blog_details
类别:WordPress函数文档、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!