my-sites.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * My Sites dashboard.
  4. *
  5. * @package WordPress
  6. * @subpackage Multisite
  7. * @since 3.0.0
  8. */
  9. require_once( dirname( __FILE__ ) . '/admin.php' );
  10. if ( ! is_multisite() ) {
  11. wp_die( __( 'Multisite support is not enabled.' ) );
  12. }
  13. if ( ! current_user_can( 'read' ) ) {
  14. wp_die( __( 'Sorry, you are not allowed to access this page.' ) );
  15. }
  16. $action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
  17. $blogs = get_blogs_of_user( $current_user->ID );
  18. $updated = false;
  19. if ( 'updateblogsettings' == $action && isset( $_POST['primary_blog'] ) ) {
  20. check_admin_referer( 'update-my-sites' );
  21. $blog = get_site( (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. get_current_screen()->add_help_tab(
  32. array(
  33. 'id' => 'overview',
  34. 'title' => __( 'Overview' ),
  35. 'content' =>
  36. '<p>' . __( 'This screen shows an individual user all of their sites in this network, and also allows that user to set a primary site. They can use the links under each site to visit either the front end or the dashboard for that site.' ) . '</p>',
  37. )
  38. );
  39. get_current_screen()->set_help_sidebar(
  40. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  41. '<p>' . __( '<a href="https://codex.wordpress.org/Dashboard_My_Sites_Screen">Documentation on My Sites</a>' ) . '</p>' .
  42. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  43. );
  44. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  45. if ( $updated ) { ?>
  46. <div id="message" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.' ); ?></strong></p></div>
  47. <?php } ?>
  48. <div class="wrap">
  49. <h1 class="wp-heading-inline">
  50. <?php
  51. echo esc_html( $title );
  52. ?>
  53. </h1>
  54. <?php
  55. if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) {
  56. /** This filter is documented in wp-login.php */
  57. $sign_up_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) );
  58. printf( ' <a href="%s" class="page-title-action">%s</a>', esc_url( $sign_up_url ), esc_html_x( 'Add New', 'site' ) );
  59. }
  60. if ( empty( $blogs ) ) :
  61. echo '<p>';
  62. _e( 'You must be a member of at least one site to use this page.' );
  63. echo '</p>';
  64. else :
  65. ?>
  66. <hr class="wp-header-end">
  67. <form id="myblogs" method="post">
  68. <?php
  69. choose_primary_blog();
  70. /**
  71. * Fires before the sites list on the My Sites screen.
  72. *
  73. * @since 3.0.0
  74. */
  75. do_action( 'myblogs_allblogs_options' );
  76. ?>
  77. <br clear="all" />
  78. <ul class="my-sites striped">
  79. <?php
  80. /**
  81. * Enable the Global Settings section on the My Sites screen.
  82. *
  83. * By default, the Global Settings section is hidden. Passing a non-empty
  84. * string to this filter will enable the section, and allow new settings
  85. * to be added, either globally or for specific sites.
  86. *
  87. * @since MU (3.0.0)
  88. *
  89. * @param string $settings_html The settings HTML markup. Default empty.
  90. * @param object $context Context of the setting (global or site-specific). Default 'global'.
  91. */
  92. $settings_html = apply_filters( 'myblogs_options', '', 'global' );
  93. if ( $settings_html != '' ) {
  94. echo '<h3>' . __( 'Global Settings' ) . '</h3>';
  95. echo $settings_html;
  96. }
  97. reset( $blogs );
  98. foreach ( $blogs as $user_blog ) {
  99. switch_to_blog( $user_blog->userblog_id );
  100. echo '<li>';
  101. echo "<h3>{$user_blog->blogname}</h3>";
  102. $actions = "<a href='" . esc_url( home_url() ) . "'>" . __( 'Visit' ) . '</a>';
  103. if ( current_user_can( 'read' ) ) {
  104. $actions .= " | <a href='" . esc_url( admin_url() ) . "'>" . __( 'Dashboard' ) . '</a>';
  105. }
  106. /**
  107. * Filters the row links displayed for each site on the My Sites screen.
  108. *
  109. * @since MU (3.0.0)
  110. *
  111. * @param string $actions The HTML site link markup.
  112. * @param object $user_blog An object containing the site data.
  113. */
  114. $actions = apply_filters( 'myblogs_blog_actions', $actions, $user_blog );
  115. echo "<p class='my-sites-actions'>" . $actions . '</p>';
  116. /** This filter is documented in wp-admin/my-sites.php */
  117. echo apply_filters( 'myblogs_options', '', $user_blog );
  118. echo '</li>';
  119. restore_current_blog();
  120. }
  121. ?>
  122. </ul>
  123. <?php
  124. if ( count( $blogs ) > 1 || has_action( 'myblogs_allblogs_options' ) || has_filter( 'myblogs_options' ) ) {
  125. ?>
  126. <input type="hidden" name="action" value="updateblogsettings" />
  127. <?php
  128. wp_nonce_field( 'update-my-sites' );
  129. submit_button();
  130. }
  131. ?>
  132. </form>
  133. <?php endif; ?>
  134. </div>
  135. <?php
  136. include( ABSPATH . 'wp-admin/admin-footer.php' );