my-sites.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * My Sites dashboard.
  4. *
  5. * @package WordPress
  6. * @subpackage Multisite
  7. * @since 3.0.0
  8. */
  9. require_once( './admin.php' );
  10. if ( !is_multisite() )
  11. wp_die( __( 'Multisite support is not enabled.' ) );
  12. if ( ! current_user_can('read') )
  13. wp_die( __( 'You do not have sufficient permissions to view this page.' ) );
  14. $action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
  15. $blogs = get_blogs_of_user( $current_user->id );
  16. if ( empty( $blogs ) )
  17. wp_die( __( 'You must be a member of at least one site to use this page.' ) );
  18. $updated = false;
  19. if ( 'updateblogsettings' == $action && isset( $_POST['primary_blog'] ) ) {
  20. check_admin_referer( 'update-my-sites' );
  21. $blog = get_blog_details( (int) $_POST['primary_blog'] );
  22. if ( $blog && isset( $blog->domain ) ) {
  23. update_user_option( $current_user->id, 'primary_blog', (int) $_POST['primary_blog'], true );
  24. $updated = true;
  25. } else {
  26. wp_die( __( 'The primary site you chose does not exist.' ) );
  27. }
  28. }
  29. $title = __( 'My Sites' );
  30. $parent_file = 'index.php';
  31. add_contextual_help($current_screen,
  32. '<p>' . __('This screen shows an individual user all of their sites in this network, and also allows that user to set a primary site. He or she can use the links under each site to visit either the frontend or the dashboard for that site.') . '</p>' .
  33. '<p>' . __('Up until WordPress version 3.0, what is now called a Multi-site Network had to be installed separately as WordPress MU (multi-user).') . '</p>' .
  34. '<p><strong>' . __('For more information:') . '</strong></p>' .
  35. '<p>' . __('<a href="http://codex.wordpress.org/Dashboard_My_Sites_Screen" target="_blank">Documentation on My Sites</a>') . '</p>' .
  36. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  37. );
  38. require_once( './admin-header.php' );
  39. if ( $updated ) { ?>
  40. <div id="message" class="updated"><p><strong><?php _e( 'Settings saved.' ); ?></strong></p></div>
  41. <?php } ?>
  42. <div class="wrap">
  43. <?php screen_icon(); ?>
  44. <h2><?php echo esc_html( $title ); ?></h2>
  45. <form id="myblogs" action="" method="post">
  46. <?php
  47. choose_primary_blog();
  48. do_action( 'myblogs_allblogs_options' );
  49. ?>
  50. <br clear="all" />
  51. <table class="widefat fixed">
  52. <?php
  53. $settings_html = apply_filters( 'myblogs_options', '', 'global' );
  54. if ( $settings_html != '' ) {
  55. echo '<tr><td valign="top"><h3>' . __( 'Global Settings' ) . '</h3></td><td>';
  56. echo $settings_html;
  57. echo '</td></tr>';
  58. }
  59. reset( $blogs );
  60. $num = count( $blogs );
  61. $cols = 1;
  62. if ( $num >= 20 )
  63. $cols = 4;
  64. elseif ( $num >= 10 )
  65. $cols = 2;
  66. $num_rows = ceil( $num / $cols );
  67. $split = 0;
  68. for ( $i = 1; $i <= $num_rows; $i++ ) {
  69. $rows[] = array_slice( $blogs, $split, $cols );
  70. $split = $split + $cols;
  71. }
  72. $c = '';
  73. foreach ( $rows as $row ) {
  74. $c = $c == 'alternate' ? '' : 'alternate';
  75. echo "<tr class='$c'>";
  76. $i = 0;
  77. foreach ( $row as $user_blog ) {
  78. $s = $i == 3 ? '' : 'border-right: 1px solid #ccc;';
  79. echo "<td valign='top' style='$s'>";
  80. echo "<h3>{$user_blog->blogname}</h3>";
  81. echo "<p>" . apply_filters( 'myblogs_blog_actions', "<a href='" . esc_url( get_home_url( $user_blog->userblog_id ) ). "'>" . __( 'Visit' ) . "</a> | <a href='" . esc_url( get_admin_url( $user_blog->userblog_id ) ) . "'>" . __( 'Dashboard' ) . "</a>", $user_blog ) . "</p>";
  82. echo apply_filters( 'myblogs_options', '', $user_blog );
  83. echo "</td>";
  84. $i++;
  85. }
  86. echo "</tr>";
  87. }?>
  88. </table>
  89. <input type="hidden" name="action" value="updateblogsettings" />
  90. <?php wp_nonce_field( 'update-my-sites' ); ?>
  91. <?php submit_button(); ?>
  92. </form>
  93. </div>
  94. <?php
  95. include( './admin-footer.php' );
  96. ?>