wp/wp-admin/my-sites.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 11:14:17 +0000
changeset 6 490d5cc509ed
parent 5 5e2f62d02dcd
child 7 cf61fcea0001
permissions -rw-r--r--
update portfolio
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * My Sites dashboard.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Multisite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
require_once( dirname( __FILE__ ) . '/admin.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
if ( !is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
	wp_die( __( 'Multisite support is not enabled.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
if ( ! current_user_can('read') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
	wp_die( __( 'You do not have sufficient permissions to view this page.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
$action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
$blogs = get_blogs_of_user( $current_user->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
$updated = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
if ( 'updateblogsettings' == $action && isset( $_POST['primary_blog'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	check_admin_referer( 'update-my-sites' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	$blog = get_blog_details( (int) $_POST['primary_blog'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	if ( $blog && isset( $blog->domain ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		update_user_option( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'], true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		$updated = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		wp_die( __( 'The primary site you chose does not exist.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
$title = __( 'My Sites' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
$parent_file = 'index.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	'id'      => 'overview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	'title'   => __('Overview'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	'content' =>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    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>' .
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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>'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
get_current_screen()->set_help_sidebar(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	'<p><strong>' . __('For more information:') . '</strong></p>' .
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
	'<p>' . __('<a href="https://codex.wordpress.org/Dashboard_My_Sites_Screen" target="_blank">Documentation on My Sites</a>') . '</p>' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    49
	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
require_once( ABSPATH . 'wp-admin/admin-header.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
if ( $updated ) { ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
	<div id="message" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.' ); ?></strong></p></div>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
<div class="wrap">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
<h2><?php echo esc_html( $title ); ?></h2>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
if ( empty( $blogs ) ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	echo '<p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	_e( 'You must be a member of at least one site to use this page.' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	echo '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
else :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
<form id="myblogs" method="post">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	choose_primary_blog();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
	 * Fires before the sites table on the My Sites screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	do_action( 'myblogs_allblogs_options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
	<br clear="all" />
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
	<table class="widefat fixed striped">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
	 * Enable the Global Settings section on the My Sites screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
	 * By default, the Global Settings section is hidden. Passing a non-empty
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
	 * string to this filter will enable the section, and allow new settings
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
	 * to be added, either globally or for specific sites.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
	 * @since MU
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
	 * @param string $settings_html The settings HTML markup. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
	 * @param object $context       Context of the setting (global or site-specific). Default 'global'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	$settings_html = apply_filters( 'myblogs_options', '', 'global' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	if ( $settings_html != '' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
		echo '<tr><td><h3>' . __( 'Global Settings' ) . '</h3></td><td>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
		echo $settings_html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		echo '</td></tr>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	reset( $blogs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	$num = count( $blogs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	$cols = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	if ( $num >= 20 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
		$cols = 4;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	elseif ( $num >= 10 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
		$cols = 2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	$num_rows = ceil( $num / $cols );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	$split = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	for ( $i = 1; $i <= $num_rows; $i++ ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
		$rows[] = array_slice( $blogs, $split, $cols );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
		$split = $split + $cols;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	foreach ( $rows as $row ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
		echo "<tr>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		$i = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		foreach ( $row as $user_blog ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
			$s = $i == 3 ? '' : 'border-right: 1px solid #ccc;';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
			echo "<td style='$s'>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
			echo "<h3>{$user_blog->blogname}</h3>";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
			 * Filter the row links displayed for each site on the My Sites screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
			 * @since MU
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
			 * @param string $string    The HTML site link markup.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
			 * @param object $user_blog An object containing the site data.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   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>";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
			/** This filter is documented in wp-admin/my-sites.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
			echo apply_filters( 'myblogs_options', '', $user_blog );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
			echo "</td>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
			$i++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		echo "</tr>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
	}?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
	</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
	<input type="hidden" name="action" value="updateblogsettings" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
	<?php wp_nonce_field( 'update-my-sites' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
	<?php submit_button(); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
	</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
include( ABSPATH . 'wp-admin/admin-footer.php' );