angelovcom.net

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

my-sites.php (4638B)


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