my-sites.php 4.4 KB

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