choose_primary_blog

Handles the display of choosing a user's primary site.

Description

choose_primary_blog(); 

This displays the user's primary site and allows the user to choose which site is primary.


Usage

  1. if ( !function_exists( 'choose_primary_blog' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ms.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = choose_primary_blog(); 
  7.  

Defined (1)

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

/wp-admin/includes/ms.php  
  1. function choose_primary_blog() { 
  2. ?> 
  3. <table class="form-table"> 
  4. <tr> 
  5. <?php /** translators: My sites label */ ?> 
  6. <th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th> 
  7. <td> 
  8. <?php 
  9. $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true ); 
  10. if ( count( $all_blogs ) > 1 ) { 
  11. $found = false; 
  12. ?> 
  13. <select name="primary_blog" id="primary_blog"> 
  14. <?php foreach ( (array) $all_blogs as $blog ) { 
  15. if ( $primary_blog == $blog->userblog_id ) 
  16. $found = true; 
  17. ?><option value="<?php echo $blog->userblog_id ?>"<?php selected( $primary_blog, $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ) ?></option><?php 
  18. } ?> 
  19. </select> 
  20. <?php 
  21. if ( !$found ) { 
  22. $blog = reset( $all_blogs ); 
  23. update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); 
  24. } elseif ( count( $all_blogs ) == 1 ) { 
  25. $blog = reset( $all_blogs ); 
  26. echo esc_url( get_home_url( $blog->userblog_id ) ); 
  27. if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list. 
  28. update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); 
  29. } else { 
  30. echo "N/A"; 
  31. ?> 
  32. </td> 
  33. </tr> 
  34. </table> 
  35. <?php