author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* My Sites dashboard. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Multisite |
|
7 |
* @since 3.0.0 |
|
8 |
*/ |
|
9 |
||
10 |
require_once( dirname( __FILE__ ) . '/admin.php' ); |
|
11 |
||
9 | 12 |
if ( ! is_multisite() ) { |
0 | 13 |
wp_die( __( 'Multisite support is not enabled.' ) ); |
9 | 14 |
} |
0 | 15 |
|
9 | 16 |
if ( ! current_user_can( 'read' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
wp_die( __( 'Sorry, you are not allowed to access this page.' ) ); |
9 | 18 |
} |
0 | 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 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
$blog = get_site( (int) $_POST['primary_blog'] ); |
0 | 29 |
if ( $blog && isset( $blog->domain ) ) { |
30 |
update_user_option( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'], true ); |
|
31 |
$updated = true; |
|
32 |
} else { |
|
33 |
wp_die( __( 'The primary site you chose does not exist.' ) ); |
|
34 |
} |
|
35 |
} |
|
36 |
||
9 | 37 |
$title = __( 'My Sites' ); |
0 | 38 |
$parent_file = 'index.php'; |
39 |
||
9 | 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 |
); |
|
0 | 48 |
|
49 |
get_current_screen()->set_help_sidebar( |
|
9 | 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>' |
|
0 | 53 |
); |
54 |
||
55 |
require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
|
56 |
||
57 |
if ( $updated ) { ?> |
|
5 | 58 |
<div id="message" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.' ); ?></strong></p></div> |
0 | 59 |
<?php } ?> |
60 |
||
61 |
<div class="wrap"> |
|
9 | 62 |
<h1 class="wp-heading-inline"> |
63 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
echo esc_html( $title ); |
9 | 65 |
?> |
66 |
</h1> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
|
0 | 68 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
/** This filter is documented in wp-login.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
$sign_up_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
printf( ' <a href="%s" class="page-title-action">%s</a>', esc_url( $sign_up_url ), esc_html_x( 'Add New', 'site' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
|
0 | 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 : |
|
9 | 80 |
?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
<hr class="wp-header-end"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
|
5 | 84 |
<form id="myblogs" method="post"> |
0 | 85 |
<?php |
86 |
choose_primary_blog(); |
|
5 | 87 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
* Fires before the sites list on the My Sites screen. |
5 | 89 |
* |
90 |
* @since 3.0.0 |
|
91 |
*/ |
|
0 | 92 |
do_action( 'myblogs_allblogs_options' ); |
93 |
?> |
|
94 |
<br clear="all" /> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
<ul class="my-sites striped"> |
0 | 96 |
<?php |
5 | 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 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
* @since MU (3.0.0) |
5 | 105 |
* |
106 |
* @param string $settings_html The settings HTML markup. Default empty. |
|
107 |
* @param object $context Context of the setting (global or site-specific). Default 'global'. |
|
108 |
*/ |
|
0 | 109 |
$settings_html = apply_filters( 'myblogs_options', '', 'global' ); |
110 |
if ( $settings_html != '' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
echo '<h3>' . __( 'Global Settings' ) . '</h3>'; |
0 | 112 |
echo $settings_html; |
113 |
} |
|
114 |
reset( $blogs ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
foreach ( $blogs as $user_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
switch_to_blog( $user_blog->userblog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
|
9 | 119 |
echo '<li>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
echo "<h3>{$user_blog->blogname}</h3>"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
|
9 | 122 |
$actions = "<a href='" . esc_url( home_url() ) . "'>" . __( 'Visit' ) . '</a>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
if ( current_user_can( 'read' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
$actions .= " | <a href='" . esc_url( admin_url() ) . "'>" . __( 'Dashboard' ) . '</a>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
} |
0 | 127 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
* Filters the row links displayed for each site on the My Sites screen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
* @param string $actions The HTML site link markup. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
* @param object $user_blog An object containing the site data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
$actions = apply_filters( 'myblogs_blog_actions', $actions, $user_blog ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
echo "<p class='my-sites-actions'>" . $actions . '</p>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
/** This filter is documented in wp-admin/my-sites.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
echo apply_filters( 'myblogs_options', '', $user_blog ); |
9 | 141 |
echo '</li>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
restore_current_blog(); |
9 | 144 |
} |
145 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
</ul> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
if ( count( $blogs ) > 1 || has_action( 'myblogs_allblogs_options' ) || has_filter( 'myblogs_options' ) ) { |
9 | 149 |
?> |
150 |
<input type="hidden" name="action" value="updateblogsettings" /> |
|
151 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
wp_nonce_field( 'update-my-sites' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
submit_button(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
?> |
0 | 156 |
</form> |
157 |
<?php endif; ?> |
|
158 |
</div> |
|
159 |
<?php |
|
160 |
include( ABSPATH . 'wp-admin/admin-footer.php' ); |