wp/wp-admin/my-sites.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    11 
    11 
    12 if ( !is_multisite() )
    12 if ( !is_multisite() )
    13 	wp_die( __( 'Multisite support is not enabled.' ) );
    13 	wp_die( __( 'Multisite support is not enabled.' ) );
    14 
    14 
    15 if ( ! current_user_can('read') )
    15 if ( ! current_user_can('read') )
    16 	wp_die( __( 'You do not have sufficient permissions to view this page.' ) );
    16 	wp_die( __( 'Sorry, you are not allowed to access this page.' ) );
    17 
    17 
    18 $action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
    18 $action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
    19 
    19 
    20 $blogs = get_blogs_of_user( $current_user->ID );
    20 $blogs = get_blogs_of_user( $current_user->ID );
    21 
    21 
    22 $updated = false;
    22 $updated = false;
    23 if ( 'updateblogsettings' == $action && isset( $_POST['primary_blog'] ) ) {
    23 if ( 'updateblogsettings' == $action && isset( $_POST['primary_blog'] ) ) {
    24 	check_admin_referer( 'update-my-sites' );
    24 	check_admin_referer( 'update-my-sites' );
    25 
    25 
    26 	$blog = get_blog_details( (int) $_POST['primary_blog'] );
    26 	$blog = get_site( (int) $_POST['primary_blog'] );
    27 	if ( $blog && isset( $blog->domain ) ) {
    27 	if ( $blog && isset( $blog->domain ) ) {
    28 		update_user_option( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'], true );
    28 		update_user_option( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'], true );
    29 		$updated = true;
    29 		$updated = true;
    30 	} else {
    30 	} else {
    31 		wp_die( __( 'The primary site you chose does not exist.' ) );
    31 		wp_die( __( 'The primary site you chose does not exist.' ) );
    37 
    37 
    38 get_current_screen()->add_help_tab( array(
    38 get_current_screen()->add_help_tab( array(
    39 	'id'      => 'overview',
    39 	'id'      => 'overview',
    40 	'title'   => __('Overview'),
    40 	'title'   => __('Overview'),
    41 	'content' =>
    41 	'content' =>
    42 		'<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 frontend or the dashboard for that site.') . '</p>' .
    42 		'<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>'
    43 		'<p>' . __('Up until WordPress version 3.0, what is now called a Multisite Network had to be installed separately as WordPress MU (multi-user).') . '</p>'
       
    44 ) );
    43 ) );
    45 
    44 
    46 get_current_screen()->set_help_sidebar(
    45 get_current_screen()->set_help_sidebar(
    47 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    46 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    48 	'<p>' . __('<a href="https://codex.wordpress.org/Dashboard_My_Sites_Screen" target="_blank">Documentation on My Sites</a>') . '</p>' .
    47 	'<p>' . __('<a href="https://codex.wordpress.org/Dashboard_My_Sites_Screen">Documentation on My Sites</a>') . '</p>' .
    49 	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    48 	'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
    50 );
    49 );
    51 
    50 
    52 require_once( ABSPATH . 'wp-admin/admin-header.php' );
    51 require_once( ABSPATH . 'wp-admin/admin-header.php' );
    53 
    52 
    54 if ( $updated ) { ?>
    53 if ( $updated ) { ?>
    55 	<div id="message" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.' ); ?></strong></p></div>
    54 	<div id="message" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.' ); ?></strong></p></div>
    56 <?php } ?>
    55 <?php } ?>
    57 
    56 
    58 <div class="wrap">
    57 <div class="wrap">
    59 <h2><?php echo esc_html( $title ); ?></h2>
    58 <h1 class="wp-heading-inline"><?php
       
    59 echo esc_html( $title );
       
    60 ?></h1>
       
    61 
    60 <?php
    62 <?php
       
    63 if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) {
       
    64 	/** This filter is documented in wp-login.php */
       
    65 	$sign_up_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) );
       
    66 	printf( ' <a href="%s" class="page-title-action">%s</a>', esc_url( $sign_up_url ), esc_html_x( 'Add New', 'site' ) );
       
    67 }
       
    68 
    61 if ( empty( $blogs ) ) :
    69 if ( empty( $blogs ) ) :
    62 	echo '<p>';
    70 	echo '<p>';
    63 	_e( 'You must be a member of at least one site to use this page.' );
    71 	_e( 'You must be a member of at least one site to use this page.' );
    64 	echo '</p>';
    72 	echo '</p>';
    65 else :
    73 else :
    66 ?>
    74 ?>
       
    75 
       
    76 <hr class="wp-header-end">
       
    77 
    67 <form id="myblogs" method="post">
    78 <form id="myblogs" method="post">
    68 	<?php
    79 	<?php
    69 	choose_primary_blog();
    80 	choose_primary_blog();
    70 	/**
    81 	/**
    71 	 * Fires before the sites table on the My Sites screen.
    82 	 * Fires before the sites list on the My Sites screen.
    72 	 *
    83 	 *
    73 	 * @since 3.0.0
    84 	 * @since 3.0.0
    74 	 */
    85 	 */
    75 	do_action( 'myblogs_allblogs_options' );
    86 	do_action( 'myblogs_allblogs_options' );
    76 	?>
    87 	?>
    77 	<br clear="all" />
    88 	<br clear="all" />
    78 	<table class="widefat fixed striped">
    89 	<ul class="my-sites striped">
    79 	<?php
    90 	<?php
    80 	/**
    91 	/**
    81 	 * Enable the Global Settings section on the My Sites screen.
    92 	 * Enable the Global Settings section on the My Sites screen.
    82 	 *
    93 	 *
    83 	 * By default, the Global Settings section is hidden. Passing a non-empty
    94 	 * 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
    95 	 * string to this filter will enable the section, and allow new settings
    85 	 * to be added, either globally or for specific sites.
    96 	 * to be added, either globally or for specific sites.
    86 	 *
    97 	 *
    87 	 * @since MU
    98 	 * @since MU (3.0.0)
    88 	 *
    99 	 *
    89 	 * @param string $settings_html The settings HTML markup. Default empty.
   100 	 * @param string $settings_html The settings HTML markup. Default empty.
    90 	 * @param object $context       Context of the setting (global or site-specific). Default 'global'.
   101 	 * @param object $context       Context of the setting (global or site-specific). Default 'global'.
    91 	 */
   102 	 */
    92 	$settings_html = apply_filters( 'myblogs_options', '', 'global' );
   103 	$settings_html = apply_filters( 'myblogs_options', '', 'global' );
    93 	if ( $settings_html != '' ) {
   104 	if ( $settings_html != '' ) {
    94 		echo '<tr><td><h3>' . __( 'Global Settings' ) . '</h3></td><td>';
   105 		echo '<h3>' . __( 'Global Settings' ) . '</h3>';
    95 		echo $settings_html;
   106 		echo $settings_html;
    96 		echo '</td></tr>';
       
    97 	}
   107 	}
    98 	reset( $blogs );
   108 	reset( $blogs );
    99 	$num = count( $blogs );
   109 
   100 	$cols = 1;
   110 	foreach ( $blogs as $user_blog ) {
   101 	if ( $num >= 20 )
   111 		switch_to_blog( $user_blog->userblog_id );
   102 		$cols = 4;
   112 
   103 	elseif ( $num >= 10 )
   113 		echo "<li>";
   104 		$cols = 2;
   114 		echo "<h3>{$user_blog->blogname}</h3>";
   105 	$num_rows = ceil( $num / $cols );
   115 
   106 	$split = 0;
   116 		$actions = "<a href='" . esc_url( home_url() ). "'>" . __( 'Visit' ) . '</a>';
   107 	for ( $i = 1; $i <= $num_rows; $i++ ) {
   117 
   108 		$rows[] = array_slice( $blogs, $split, $cols );
   118 		if ( current_user_can( 'read' ) ) {
   109 		$split = $split + $cols;
   119 			$actions .= " | <a href='" . esc_url( admin_url() ) . "'>" . __( 'Dashboard' ) . '</a>';
       
   120 		}
       
   121 
       
   122 		/**
       
   123 		 * Filters the row links displayed for each site on the My Sites screen.
       
   124 		 *
       
   125 		 * @since MU (3.0.0)
       
   126 		 *
       
   127 		 * @param string $actions   The HTML site link markup.
       
   128 		 * @param object $user_blog An object containing the site data.
       
   129 		 */
       
   130 		$actions = apply_filters( 'myblogs_blog_actions', $actions, $user_blog );
       
   131 		echo "<p class='my-sites-actions'>" . $actions . '</p>';
       
   132 
       
   133 		/** This filter is documented in wp-admin/my-sites.php */
       
   134 		echo apply_filters( 'myblogs_options', '', $user_blog );
       
   135 		echo "</li>";
       
   136 
       
   137 		restore_current_blog();
       
   138 	}?>
       
   139 	</ul>
       
   140 	<?php
       
   141 	if ( count( $blogs ) > 1 || has_action( 'myblogs_allblogs_options' ) || has_filter( 'myblogs_options' ) ) {
       
   142 		?><input type="hidden" name="action" value="updateblogsettings" /><?php
       
   143 		wp_nonce_field( 'update-my-sites' );
       
   144 		submit_button();
   110 	}
   145 	}
   111 
   146 	?>
   112 	foreach ( $rows as $row ) {
       
   113 		echo "<tr>";
       
   114 		$i = 0;
       
   115 		foreach ( $row as $user_blog ) {
       
   116 			$s = $i == 3 ? '' : 'border-right: 1px solid #ccc;';
       
   117 			echo "<td style='$s'>";
       
   118 			echo "<h3>{$user_blog->blogname}</h3>";
       
   119 			/**
       
   120 			 * Filter the row links displayed for each site on the My Sites screen.
       
   121 			 *
       
   122 			 * @since MU
       
   123 			 *
       
   124 			 * @param string $string    The HTML site link markup.
       
   125 			 * @param object $user_blog An object containing the site data.
       
   126 			 */
       
   127 			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>";
       
   128 			/** This filter is documented in wp-admin/my-sites.php */
       
   129 			echo apply_filters( 'myblogs_options', '', $user_blog );
       
   130 			echo "</td>";
       
   131 			$i++;
       
   132 		}
       
   133 		echo "</tr>";
       
   134 	}?>
       
   135 	</table>
       
   136 	<input type="hidden" name="action" value="updateblogsettings" />
       
   137 	<?php wp_nonce_field( 'update-my-sites' ); ?>
       
   138 	<?php submit_button(); ?>
       
   139 	</form>
   147 	</form>
   140 <?php endif; ?>
   148 <?php endif; ?>
   141 	</div>
   149 	</div>
   142 <?php
   150 <?php
   143 include( ABSPATH . 'wp-admin/admin-footer.php' );
   151 include( ABSPATH . 'wp-admin/admin-footer.php' );