my-sites.php 4.6 KB

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