7
7
* @subpackage Multisite
11
// @todo use update_blog_details
12
* Update the last_updated field for the current blog.
12
16
function wpmu_update_blogs_date() {
19
// TODO: use update_blog_details
15
21
$wpdb->update( $wpdb->blogs, array('last_updated' => current_time('mysql', true)), array('blog_id' => $wpdb->blogid) );
16
22
refresh_blog_details( $wpdb->blogid );
18
24
do_action( 'wpmu_blog_updated', $wpdb->blogid );
28
* Get a full blog URL, given a blog id.
32
* @param int $blog_id Blog ID
21
35
function get_blogaddress_by_id( $blog_id ) {
22
36
$bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
23
37
return esc_url( 'http://' . $bloginfo->domain . $bloginfo->path );
41
* Get a full blog URL, given a blog name.
45
* @param string $blogname The (subdomain or directory) name
26
48
function get_blogaddress_by_name( $blogname ) {
27
49
global $current_site;
38
60
return esc_url( $url . '/' );
41
function get_blogaddress_by_domain( $domain, $path ){
64
* Get a full blog URL, given a domain and a path.
68
* @param string $domain
72
function get_blogaddress_by_domain( $domain, $path ) {
42
73
if ( is_subdomain_install() ) {
43
74
$url = "http://".$domain.$path;
55
86
return esc_url( $url );
90
* Given a blog's (subdomain or directory) name, retrieve it's id.
95
* @return int A blog id
58
97
function get_id_from_blogname( $name ) {
59
98
global $wpdb, $current_site;
60
99
$blog_id = wp_cache_get( "get_id_from_blogname_" . $name, 'blog-details' );
77
116
* Retrieve the details for a blog from the blogs table and blog options.
80
120
* @param int|string|array $fields A blog ID, a blog name, or an array of fields to query against.
81
121
* @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
82
122
* @return object Blog details.
262
302
if ( isset($details[ 'public' ]) )
263
update_blog_option( $blog_id, 'blog_public', $details[ 'public' ], false );
303
update_blog_option( $blog_id, 'blog_public', $details[ 'public' ] );
265
305
refresh_blog_details($blog_id);
280
320
* $blog_id. It returns $value.
281
321
* The 'option_$option' filter in get_option() is not called.
284
* @package WordPress MU
286
324
* @uses apply_filters() Calls 'blog_option_$optionname' with the option name value.
288
326
* @param int $blog_id is the id of the blog.
289
* @param string $setting Name of option to retrieve. Should already be SQL-escaped
327
* @param string $setting Name of option to retrieve. Should already be SQL-escaped.
290
328
* @param string $default (optional) Default value returned if option not found.
291
329
* @return mixed Value set for the option.
334
372
if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
335
373
$value = untrailingslashit( $value );
337
if (! @unserialize( $value ) )
338
$value = stripslashes( $value );
340
375
return apply_filters( 'blog_option_' . $setting, maybe_unserialize( $value ), $blog_id );
379
* Add an option for a particular blog.
383
* @param int $id The blog id
384
* @param string $key The option key
385
* @param mixed $value The option value
343
387
function add_blog_option( $id, $key, $value ) {
349
393
wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options' );
397
* Delete an option for a particular blog.
401
* @param int $id The blog id
402
* @param string $key The option key
352
404
function delete_blog_option( $id, $key ) {
358
410
wp_cache_set( $id."-".$key."-blog_option", '', 'site-options' );
361
function update_blog_option( $id, $key, $value, $refresh = true ) {
414
* Update an option for a particular blog.
418
* @param int $id The blog id
419
* @param string $key The option key
420
* @param mixed $value The option value
422
function update_blog_option( $id, $key, $value, $deprecated = null ) {
425
if ( null !== $deprecated )
426
_deprecated_argument( __FUNCTION__, '3.1' );
364
428
switch_to_blog($id);
365
429
update_option( $key, $value );
366
430
restore_current_blog();
368
if ( $refresh == true )
369
refresh_blog_details( $id );
432
refresh_blog_details( $id );
370
434
wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options');
438
* Switch the current blog.
440
* This function is useful if you need to pull posts, or other information,
441
* from other blogs. You can switch back afterwards using restore_current_blog().
443
* Things that aren't switched:
444
* - autoloaded options. See #14992
445
* - plugins. See #14941
447
* @see restore_current_blog()
450
* @param int $new_blog The id of the blog you want to switch to. Default: current blog
451
* @param bool $validate Whether to check if $new_blog exists before proceeding
452
* @return bool True on success, False if the validation failed
373
454
function switch_to_blog( $new_blog, $validate = false ) {
374
455
global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
406
487
$wp_roles->__construct();
407
488
$wpdb->suppress_errors( false );
410
491
if ( did_action('init') ) {
411
$current_user = wp_get_current_user();
492
$current_user = wp_get_current_user();
412
493
if ( is_object( $current_user ) )
413
494
$current_user->for_blog( $blog_id );
423
504
if ( is_array( $global_groups ) )
424
505
wp_cache_add_global_groups( $global_groups );
426
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'site-transient', 'global-posts' ) );
507
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
427
508
wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
517
* Restore the current blog, after calling switch_to_blog()
519
* @see switch_to_blog()
522
* @return bool True on success, False if we're already on the current blog
435
524
function restore_current_blog() {
436
525
global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
479
568
if ( is_array( $global_groups ) )
480
569
wp_cache_add_global_groups( $global_groups );
482
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'site-transient' ) );
571
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
483
572
wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
583
* Check if a particular blog is archived.
587
* @param int $id The blog id
588
* @return string Whether the blog is archived or not
493
590
function is_archived( $id ) {
494
591
return get_blog_status($id, 'archived');
595
* Update the 'archived' status of a particular blog.
599
* @param int $id The blog id
600
* @param string $archived The new status
601
* @return string $archived
497
603
function update_archived( $id, $archived ) {
498
604
update_blog_status($id, 'archived', $archived);
499
605
return $archived;
503
609
* Update a blog details field.
507
613
* @param int $blog_id BLog ID
508
614
* @param string $pref A field name
509
615
* @param string $value Value for $pref
510
* @param bool $refresh Whether to refresh the blog details cache. Default is true.
616
* @return string $value
512
function update_blog_status( $blog_id, $pref, $value, $refresh = true ) {
618
function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) {
621
if ( null !== $deprecated )
622
_deprecated_argument( __FUNCTION__, '3.1' );
515
624
if ( !in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) )
518
627
$wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) );
521
refresh_blog_details($blog_id);
629
refresh_blog_details($blog_id);
523
if ( $pref == 'spam' ) {
525
do_action( "make_spam_blog", $blog_id );
527
do_action( "make_ham_blog", $blog_id );
631
if ( 'spam' == $pref )
632
( $value == 1 ) ? do_action( 'make_spam_blog', $blog_id ) : do_action( 'make_ham_blog', $blog_id );
633
elseif ( 'mature' == $pref )
634
( $value == 1 ) ? do_action( 'mature_blog', $blog_id ) : do_action( 'unmature_blog', $blog_id );
635
elseif ( 'archived' == $pref )
636
( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
637
elseif ( 'archived' == $pref )
638
( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
644
* Get a blog details field.
648
* @param int $id The blog id
649
* @param string $pref A field name
650
* @return bool $value
533
652
function get_blog_status( $id, $pref ) {
540
659
return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) );
663
* Get a list of most recently updated blogs.
667
* @param mixed $deprecated Not used
668
* @param int $start The offset
669
* @param int $quantity The maximum number of blogs to retrieve. Default is 40.
670
* @return array The list of blogs
543
672
function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) {
675
if ( ! empty( $deprecated ) )
676
_deprecated_argument( __FUNCTION__, 'MU' ); // never used
545
678
return $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", $wpdb->siteid, $start, $quantity ) , ARRAY_A );