15 */ |
15 */ |
16 function wpmu_update_blogs_date() { |
16 function wpmu_update_blogs_date() { |
17 global $wpdb; |
17 global $wpdb; |
18 |
18 |
19 update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) ); |
19 update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) ); |
20 |
20 /** |
|
21 * Fires after the blog details are updated. |
|
22 * |
|
23 * @since MU |
|
24 * |
|
25 * @param int $blog_id Blog ID. |
|
26 */ |
21 do_action( 'wpmu_blog_updated', $wpdb->blogid ); |
27 do_action( 'wpmu_blog_updated', $wpdb->blogid ); |
22 } |
28 } |
23 |
29 |
24 /** |
30 /** |
25 * Get a full blog URL, given a blog id. |
31 * Get a full blog URL, given a blog id. |
26 * |
32 * |
27 * @since MU |
33 * @since MU |
28 * |
34 * |
29 * @param int $blog_id Blog ID |
35 * @param int $blog_id Blog ID |
30 * @return string |
36 * @return string Full URL of the blog if found. Empty string if not. |
31 */ |
37 */ |
32 function get_blogaddress_by_id( $blog_id ) { |
38 function get_blogaddress_by_id( $blog_id ) { |
33 $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details! |
39 $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details! |
34 return esc_url( 'http://' . $bloginfo->domain . $bloginfo->path ); |
40 return ( $bloginfo ) ? esc_url( 'http://' . $bloginfo->domain . $bloginfo->path ) : ''; |
35 } |
41 } |
36 |
42 |
37 /** |
43 /** |
38 * Get a full blog URL, given a blog name. |
44 * Get a full blog URL, given a blog name. |
39 * |
45 * |
269 $details = array_merge($current_details, $details); |
294 $details = array_merge($current_details, $details); |
270 $details['last_updated'] = current_time('mysql', true); |
295 $details['last_updated'] = current_time('mysql', true); |
271 |
296 |
272 $update_details = array(); |
297 $update_details = array(); |
273 $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'); |
298 $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'); |
274 foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) |
299 foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) { |
275 $update_details[$field] = $details[$field]; |
300 if ( 'path' === $field ) { |
|
301 $details[ $field ] = trailingslashit( '/' . trim( $details[ $field ], '/' ) ); |
|
302 } |
|
303 |
|
304 $update_details[ $field ] = $details[ $field ]; |
|
305 } |
276 |
306 |
277 $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) ); |
307 $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) ); |
278 |
308 |
279 if ( false === $result ) |
309 if ( false === $result ) |
280 return false; |
310 return false; |
281 |
311 |
282 // If spam status changed, issue actions. |
312 // If spam status changed, issue actions. |
283 if ( $details[ 'spam' ] != $current_details[ 'spam' ] ) { |
313 if ( $details['spam'] != $current_details['spam'] ) { |
284 if ( $details[ 'spam' ] == 1 ) |
314 if ( $details['spam'] == 1 ) { |
|
315 /** |
|
316 * Fires when the blog status is changed to 'spam'. |
|
317 * |
|
318 * @since MU |
|
319 * |
|
320 * @param int $blog_id Blog ID. |
|
321 */ |
285 do_action( 'make_spam_blog', $blog_id ); |
322 do_action( 'make_spam_blog', $blog_id ); |
286 else |
323 } else { |
|
324 /** |
|
325 * Fires when the blog status is changed to 'ham'. |
|
326 * |
|
327 * @since MU |
|
328 * |
|
329 * @param int $blog_id Blog ID. |
|
330 */ |
287 do_action( 'make_ham_blog', $blog_id ); |
331 do_action( 'make_ham_blog', $blog_id ); |
|
332 } |
288 } |
333 } |
289 |
334 |
290 // If mature status changed, issue actions. |
335 // If mature status changed, issue actions. |
291 if ( $details[ 'mature' ] != $current_details[ 'mature' ] ) { |
336 if ( $details['mature'] != $current_details['mature'] ) { |
292 if ( $details[ 'mature' ] == 1 ) |
337 if ( $details['mature'] == 1 ) { |
|
338 /** |
|
339 * Fires when the blog status is changed to 'mature'. |
|
340 * |
|
341 * @since 3.1.0 |
|
342 * |
|
343 * @param int $blog_id Blog ID. |
|
344 */ |
293 do_action( 'mature_blog', $blog_id ); |
345 do_action( 'mature_blog', $blog_id ); |
294 else |
346 } else { |
|
347 /** |
|
348 * Fires when the blog status is changed to 'unmature'. |
|
349 * |
|
350 * @since 3.1.0 |
|
351 * |
|
352 * @param int $blog_id Blog ID. |
|
353 */ |
295 do_action( 'unmature_blog', $blog_id ); |
354 do_action( 'unmature_blog', $blog_id ); |
|
355 } |
296 } |
356 } |
297 |
357 |
298 // If archived status changed, issue actions. |
358 // If archived status changed, issue actions. |
299 if ( $details[ 'archived' ] != $current_details[ 'archived' ] ) { |
359 if ( $details['archived'] != $current_details['archived'] ) { |
300 if ( $details[ 'archived' ] == 1 ) |
360 if ( $details['archived'] == 1 ) { |
|
361 /** |
|
362 * Fires when the blog status is changed to 'archived'. |
|
363 * |
|
364 * @since MU |
|
365 * |
|
366 * @param int $blog_id Blog ID. |
|
367 */ |
301 do_action( 'archive_blog', $blog_id ); |
368 do_action( 'archive_blog', $blog_id ); |
302 else |
369 } else { |
|
370 /** |
|
371 * Fires when the blog status is changed to 'unarchived'. |
|
372 * |
|
373 * @since MU |
|
374 * |
|
375 * @param int $blog_id Blog ID. |
|
376 */ |
303 do_action( 'unarchive_blog', $blog_id ); |
377 do_action( 'unarchive_blog', $blog_id ); |
|
378 } |
304 } |
379 } |
305 |
380 |
306 // If deleted status changed, issue actions. |
381 // If deleted status changed, issue actions. |
307 if ( $details[ 'deleted' ] != $current_details[ 'deleted' ] ) { |
382 if ( $details['deleted'] != $current_details['deleted'] ) { |
308 if ( $details[ 'deleted' ] == 1 ) |
383 if ( $details['deleted'] == 1 ) { |
|
384 /** |
|
385 * Fires when the blog status is changed to 'deleted'. |
|
386 * |
|
387 * @since 3.5.0 |
|
388 * |
|
389 * @param int $blog_id Blog ID. |
|
390 */ |
309 do_action( 'make_delete_blog', $blog_id ); |
391 do_action( 'make_delete_blog', $blog_id ); |
310 else |
392 } else { |
|
393 /** |
|
394 * Fires when the blog status is changed to 'undeleted'. |
|
395 * |
|
396 * @since 3.5.0 |
|
397 * |
|
398 * @param int $blog_id Blog ID. |
|
399 */ |
311 do_action( 'make_undelete_blog', $blog_id ); |
400 do_action( 'make_undelete_blog', $blog_id ); |
312 } |
401 } |
313 |
402 } |
314 if ( isset( $details[ 'public' ] ) ) { |
403 |
|
404 if ( isset( $details['public'] ) ) { |
315 switch_to_blog( $blog_id ); |
405 switch_to_blog( $blog_id ); |
316 update_option( 'blog_public', $details[ 'public' ] ); |
406 update_option( 'blog_public', $details['public'] ); |
317 restore_current_blog(); |
407 restore_current_blog(); |
318 } |
408 } |
319 |
409 |
320 refresh_blog_details($blog_id); |
410 refresh_blog_details($blog_id); |
321 |
411 |
476 * @see restore_current_blog() |
576 * @see restore_current_blog() |
477 * @since MU |
577 * @since MU |
478 * |
578 * |
479 * @param int $new_blog The id of the blog you want to switch to. Default: current blog |
579 * @param int $new_blog The id of the blog you want to switch to. Default: current blog |
480 * @param bool $deprecated Deprecated argument |
580 * @param bool $deprecated Deprecated argument |
481 * @return bool True on success, false if the validation failed |
581 * @return bool Always returns True. |
482 */ |
582 */ |
483 function switch_to_blog( $new_blog, $deprecated = null ) { |
583 function switch_to_blog( $new_blog, $deprecated = null ) { |
484 global $wpdb, $wp_roles; |
584 global $wpdb, $wp_roles; |
485 |
585 |
486 if ( empty( $new_blog ) ) |
586 if ( empty( $new_blog ) ) |
487 $new_blog = $GLOBALS['blog_id']; |
587 $new_blog = $GLOBALS['blog_id']; |
488 |
588 |
489 $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; |
589 $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; |
490 |
590 |
491 /* If we're switching to the same blog id that we're on, |
591 /* |
492 * set the right vars, do the associated actions, but skip |
592 * If we're switching to the same blog id that we're on, |
493 * the extra unnecessary work */ |
593 * set the right vars, do the associated actions, but skip |
|
594 * the extra unnecessary work |
|
595 */ |
494 if ( $new_blog == $GLOBALS['blog_id'] ) { |
596 if ( $new_blog == $GLOBALS['blog_id'] ) { |
|
597 /** |
|
598 * Fires when the blog is switched. |
|
599 * |
|
600 * @since MU |
|
601 * |
|
602 * @param int $new_blog New blog ID. |
|
603 * @param int $new_blog Blog ID. |
|
604 */ |
495 do_action( 'switch_blog', $new_blog, $new_blog ); |
605 do_action( 'switch_blog', $new_blog, $new_blog ); |
496 $GLOBALS['switched'] = true; |
606 $GLOBALS['switched'] = true; |
497 return true; |
607 return true; |
498 } |
608 } |
499 |
609 |
513 $global_groups = false; |
623 $global_groups = false; |
514 |
624 |
515 wp_cache_init(); |
625 wp_cache_init(); |
516 |
626 |
517 if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
627 if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
518 if ( is_array( $global_groups ) ) |
628 if ( is_array( $global_groups ) ) { |
519 wp_cache_add_global_groups( $global_groups ); |
629 wp_cache_add_global_groups( $global_groups ); |
520 else |
630 } else { |
521 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache' ) ); |
631 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) ); |
|
632 } |
522 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); |
633 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); |
523 } |
634 } |
524 } |
635 } |
525 |
636 |
526 if ( did_action( 'init' ) ) { |
637 if ( did_action( 'init' ) ) { |
527 $wp_roles->reinit(); |
638 $wp_roles->reinit(); |
528 $current_user = wp_get_current_user(); |
639 $current_user = wp_get_current_user(); |
529 $current_user->for_blog( $new_blog ); |
640 $current_user->for_blog( $new_blog ); |
530 } |
641 } |
531 |
642 |
|
643 /** This filter is documented in wp-includes/ms-blogs.php */ |
532 do_action( 'switch_blog', $new_blog, $prev_blog_id ); |
644 do_action( 'switch_blog', $new_blog, $prev_blog_id ); |
533 $GLOBALS['switched'] = true; |
645 $GLOBALS['switched'] = true; |
534 |
646 |
535 return true; |
647 return true; |
536 } |
648 } |
574 $global_groups = false; |
687 $global_groups = false; |
575 |
688 |
576 wp_cache_init(); |
689 wp_cache_init(); |
577 |
690 |
578 if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
691 if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
579 if ( is_array( $global_groups ) ) |
692 if ( is_array( $global_groups ) ) { |
580 wp_cache_add_global_groups( $global_groups ); |
693 wp_cache_add_global_groups( $global_groups ); |
581 else |
694 } else { |
582 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache' ) ); |
695 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) ); |
|
696 } |
583 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); |
697 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); |
584 } |
698 } |
585 } |
699 } |
586 |
700 |
587 if ( did_action( 'init' ) ) { |
701 if ( did_action( 'init' ) ) { |
588 $wp_roles->reinit(); |
702 $wp_roles->reinit(); |
589 $current_user = wp_get_current_user(); |
703 $current_user = wp_get_current_user(); |
590 $current_user->for_blog( $blog ); |
704 $current_user->for_blog( $blog ); |
591 } |
705 } |
592 |
706 |
|
707 /** This filter is documented in wp-includes/ms-blogs.php */ |
593 do_action( 'switch_blog', $blog, $prev_blog_id ); |
708 do_action( 'switch_blog', $blog, $prev_blog_id ); |
594 |
709 |
595 // If we still have items in the switched stack, consider ourselves still 'switched' |
710 // If we still have items in the switched stack, consider ourselves still 'switched' |
596 $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
711 $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
597 |
712 |
659 if ( false === $result ) |
774 if ( false === $result ) |
660 return false; |
775 return false; |
661 |
776 |
662 refresh_blog_details( $blog_id ); |
777 refresh_blog_details( $blog_id ); |
663 |
778 |
664 if ( 'spam' == $pref ) |
779 if ( 'spam' == $pref ) { |
665 ( $value == 1 ) ? do_action( 'make_spam_blog', $blog_id ) : do_action( 'make_ham_blog', $blog_id ); |
780 if ( $value == 1 ) { |
666 elseif ( 'mature' == $pref ) |
781 /** This filter is documented in wp-includes/ms-blogs.php */ |
667 ( $value == 1 ) ? do_action( 'mature_blog', $blog_id ) : do_action( 'unmature_blog', $blog_id ); |
782 do_action( 'make_spam_blog', $blog_id ); |
668 elseif ( 'archived' == $pref ) |
783 } else { |
669 ( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id ); |
784 /** This filter is documented in wp-includes/ms-blogs.php */ |
670 elseif ( 'deleted' == $pref ) |
785 do_action( 'make_ham_blog', $blog_id ); |
671 ( $value == 1 ) ? do_action( 'make_delete_blog', $blog_id ) : do_action( 'make_undelete_blog', $blog_id ); |
786 } |
672 elseif ( 'public' == $pref ) |
787 } elseif ( 'mature' == $pref ) { |
|
788 if ( $value == 1 ) { |
|
789 /** This filter is documented in wp-includes/ms-blogs.php */ |
|
790 do_action( 'mature_blog', $blog_id ); |
|
791 } else { |
|
792 /** This filter is documented in wp-includes/ms-blogs.php */ |
|
793 do_action( 'unmature_blog', $blog_id ); |
|
794 } |
|
795 } elseif ( 'archived' == $pref ) { |
|
796 if ( $value == 1 ) { |
|
797 /** This filter is documented in wp-includes/ms-blogs.php */ |
|
798 do_action( 'archive_blog', $blog_id ); |
|
799 } else { |
|
800 /** This filter is documented in wp-includes/ms-blogs.php */ |
|
801 do_action( 'unarchive_blog', $blog_id ); |
|
802 } |
|
803 } elseif ( 'deleted' == $pref ) { |
|
804 if ( $value == 1 ) { |
|
805 /** This filter is documented in wp-includes/ms-blogs.php */ |
|
806 do_action( 'make_delete_blog', $blog_id ); |
|
807 } else { |
|
808 /** This filter is documented in wp-includes/ms-blogs.php */ |
|
809 do_action( 'make_undelete_blog', $blog_id ); |
|
810 } |
|
811 } elseif ( 'public' == $pref ) { |
|
812 /** |
|
813 * Fires after the current blog's 'public' setting is updated. |
|
814 * |
|
815 * @since MU |
|
816 * |
|
817 * @param int $blog_id Blog ID. |
|
818 * @param string $value The value of blog status. |
|
819 */ |
673 do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public(). |
820 do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public(). |
|
821 } |
674 |
822 |
675 return $value; |
823 return $value; |
676 } |
824 } |
677 |
825 |
678 /** |
826 /** |
744 */ |
894 */ |
745 function _update_blog_date_on_post_delete( $post_id ) { |
895 function _update_blog_date_on_post_delete( $post_id ) { |
746 $post = get_post( $post_id ); |
896 $post = get_post( $post_id ); |
747 |
897 |
748 $post_type_obj = get_post_type_object( $post->post_type ); |
898 $post_type_obj = get_post_type_object( $post->post_type ); |
749 if ( ! $post_type_obj->public ) |
899 if ( ! $post_type_obj || ! $post_type_obj->public ) { |
750 return; |
900 return; |
751 |
901 } |
752 if ( 'publish' != $post->post_status ) |
902 |
|
903 if ( 'publish' != $post->post_status ) { |
753 return; |
904 return; |
|
905 } |
754 |
906 |
755 wpmu_update_blogs_date(); |
907 wpmu_update_blogs_date(); |
756 } |
908 } |
757 |
909 |
|
910 /** |
|
911 * Handler for updating the blog posts count date when a post is deleted. |
|
912 * |
|
913 * @since 4.0.0 |
|
914 * |
|
915 * @param int $post_id Post ID. |
|
916 */ |
|
917 function _update_posts_count_on_delete( $post_id ) { |
|
918 $post = get_post( $post_id ); |
|
919 |
|
920 if ( ! $post || 'publish' !== $post->post_status ) { |
|
921 return; |
|
922 } |
|
923 |
|
924 update_posts_count(); |
|
925 } |
|
926 |
|
927 /** |
|
928 * Handler for updating the blog posts count date when a post status changes. |
|
929 * |
|
930 * @since 4.0.0 |
|
931 * |
|
932 * @param string $new_status The status the post is changing to. |
|
933 * @param string $old_status The status the post is changing from. |
|
934 */ |
|
935 function _update_posts_count_on_transition_post_status( $new_status, $old_status ) { |
|
936 if ( $new_status === $old_status ) { |
|
937 return; |
|
938 } |
|
939 |
|
940 if ( 'publish' !== $new_status && 'publish' !== $old_status ) { |
|
941 return; |
|
942 } |
|
943 |
|
944 update_posts_count(); |
|
945 } |
|
946 |