my-sites.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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><?php
  46. echo esc_html( $title );
  47. if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) {
  48. /** This filter is documented in wp-login.php */
  49. $sign_up_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) );
  50. printf( ' <a href="%s" class="page-title-action">%s</a>', esc_url( $sign_up_url ), esc_html_x( 'Add New', 'site' ) );
  51. }
  52. ?></h1>
  53. <?php
  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. <form id="myblogs" method="post">
  61. <?php
  62. choose_primary_blog();
  63. /**
  64. * Fires before the sites list on the My Sites screen.
  65. *
  66. * @since 3.0.0
  67. */
  68. do_action( 'myblogs_allblogs_options' );
  69. ?>
  70. <br clear="all" />
  71. <ul class="my-sites striped">
  72. <?php
  73. /**
  74. * Enable the Global Settings section on the My Sites screen.
  75. *
  76. * By default, the Global Settings section is hidden. Passing a non-empty
  77. * string to this filter will enable the section, and allow new settings
  78. * to be added, either globally or for specific sites.
  79. *
  80. * @since MU
  81. *
  82. * @param string $settings_html The settings HTML markup. Default empty.
  83. * @param object $context Context of the setting (global or site-specific). Default 'global'.
  84. */
  85. $settings_html = apply_filters( 'myblogs_options', '', 'global' );
  86. if ( $settings_html != '' ) {
  87. echo '<h3>' . __( 'Global Settings' ) . '</h3>';
  88. echo $settings_html;
  89. }
  90. reset( $blogs );
  91. foreach ( $blogs as $user_blog ) {
  92. echo "<li>";
  93. echo "<h3>{$user_blog->blogname}</h3>";
  94. /**
  95. * Filters the row links displayed for each site on the My Sites screen.
  96. *
  97. * @since MU
  98. *
  99. * @param string $string The HTML site link markup.
  100. * @param object $user_blog An object containing the site data.
  101. */
  102. 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>";
  103. /** This filter is documented in wp-admin/my-sites.php */
  104. echo apply_filters( 'myblogs_options', '', $user_blog );
  105. echo "</li>";
  106. }?>
  107. </ul>
  108. <?php
  109. if ( count( $blogs ) > 1 || has_action( 'myblogs_allblogs_options' ) || has_filter( 'myblogs_options' ) ) {
  110. ?><input type="hidden" name="action" value="updateblogsettings" /><?php
  111. wp_nonce_field( 'update-my-sites' );
  112. submit_button();
  113. }
  114. ?>
  115. </form>
  116. <?php endif; ?>
  117. </div>
  118. <?php
  119. include( ABSPATH . 'wp-admin/admin-footer.php' );