update_blog_details

Update the details for a blog.

Description

update_blog_details( (int) $blog_id, (array) $details = array() ); 

Updates the blogs table for a given blog id.

Parameters (2)

0. $blog_id (int)
The blog id.
1. $details — Optional. (array) => array()
Array of details keyed by blogs table field names.

Usage

  1. if ( !function_exists( 'update_blog_details' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-blogs.php'; 
  3.  
  4. // The blog id. 
  5. $blog_id = -1; 
  6.  
  7. // Array of details keyed by blogs table field names. 
  8. $details = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = update_blog_details($blog_id, $details); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-blogs.php  
  1. function update_blog_details( $blog_id, $details = array() ) { 
  2. global $wpdb; 
  3.  
  4. if ( empty($details) ) 
  5. return false; 
  6.  
  7. if ( is_object($details) ) 
  8. $details = get_object_vars($details); 
  9.  
  10. $current_details = get_site( $blog_id ); 
  11. if ( empty($current_details) ) 
  12. return false; 
  13.  
  14. $current_details = get_object_vars($current_details); 
  15.  
  16. $details = array_merge($current_details, $details); 
  17. $details['last_updated'] = current_time('mysql', true); 
  18.  
  19. $update_details = array(); 
  20. $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'); 
  21. foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) { 
  22. if ( 'path' === $field ) { 
  23. $details[ $field ] = trailingslashit( '/' . trim( $details[ $field ], '/' ) ); 
  24.  
  25. $update_details[ $field ] = $details[ $field ]; 
  26.  
  27. $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) ); 
  28.  
  29. if ( false === $result ) 
  30. return false; 
  31.  
  32. // If spam status changed, issue actions. 
  33. if ( $details['spam'] != $current_details['spam'] ) { 
  34. if ( $details['spam'] == 1 ) { 
  35. /** 
  36. * Fires when the blog status is changed to 'spam'. 
  37. * @since MU 
  38. * @param int $blog_id Blog ID. 
  39. */ 
  40. do_action( 'make_spam_blog', $blog_id ); 
  41. } else { 
  42. /** 
  43. * Fires when the blog status is changed to 'ham'. 
  44. * @since MU 
  45. * @param int $blog_id Blog ID. 
  46. */ 
  47. do_action( 'make_ham_blog', $blog_id ); 
  48.  
  49. // If mature status changed, issue actions. 
  50. if ( $details['mature'] != $current_details['mature'] ) { 
  51. if ( $details['mature'] == 1 ) { 
  52. /** 
  53. * Fires when the blog status is changed to 'mature'. 
  54. * @since 3.1.0 
  55. * @param int $blog_id Blog ID. 
  56. */ 
  57. do_action( 'mature_blog', $blog_id ); 
  58. } else { 
  59. /** 
  60. * Fires when the blog status is changed to 'unmature'. 
  61. * @since 3.1.0 
  62. * @param int $blog_id Blog ID. 
  63. */ 
  64. do_action( 'unmature_blog', $blog_id ); 
  65.  
  66. // If archived status changed, issue actions. 
  67. if ( $details['archived'] != $current_details['archived'] ) { 
  68. if ( $details['archived'] == 1 ) { 
  69. /** 
  70. * Fires when the blog status is changed to 'archived'. 
  71. * @since MU 
  72. * @param int $blog_id Blog ID. 
  73. */ 
  74. do_action( 'archive_blog', $blog_id ); 
  75. } else { 
  76. /** 
  77. * Fires when the blog status is changed to 'unarchived'. 
  78. * @since MU 
  79. * @param int $blog_id Blog ID. 
  80. */ 
  81. do_action( 'unarchive_blog', $blog_id ); 
  82.  
  83. // If deleted status changed, issue actions. 
  84. if ( $details['deleted'] != $current_details['deleted'] ) { 
  85. if ( $details['deleted'] == 1 ) { 
  86. /** 
  87. * Fires when the blog status is changed to 'deleted'. 
  88. * @since 3.5.0 
  89. * @param int $blog_id Blog ID. 
  90. */ 
  91. do_action( 'make_delete_blog', $blog_id ); 
  92. } else { 
  93. /** 
  94. * Fires when the blog status is changed to 'undeleted'. 
  95. * @since 3.5.0 
  96. * @param int $blog_id Blog ID. 
  97. */ 
  98.  
  99. if ( isset( $details['public'] ) ) { 
  100. switch_to_blog( $blog_id ); 
  101. update_option( 'blog_public', $details['public'] ); 
  102.  
  103. refresh_blog_details($blog_id); 
  104.  
  105. return true;