author | ymh <ymh.work@gmail.com> |
Wed, 16 Oct 2019 11:23:38 +0200 | |
changeset 14 | 00ac8f60d73f |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Edit Site Themes Administration Screen |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Multisite |
|
7 |
* @since 3.1.0 |
|
8 |
*/ |
|
9 |
||
10 |
/** Load WordPress Administration Bootstrap */ |
|
11 |
require_once( dirname( __FILE__ ) . '/admin.php' ); |
|
12 |
||
9 | 13 |
if ( ! current_user_can( 'manage_sites' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
wp_die( __( 'Sorry, you are not allowed to manage themes for this site.' ) ); |
9 | 15 |
} |
0 | 16 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
get_current_screen()->add_help_tab( get_site_screen_help_tab_args() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() ); |
0 | 19 |
|
9 | 20 |
get_current_screen()->set_screen_reader_content( |
21 |
array( |
|
22 |
'heading_views' => __( 'Filter site themes list' ), |
|
23 |
'heading_pagination' => __( 'Site themes list navigation' ), |
|
24 |
'heading_list' => __( 'Site themes list' ), |
|
25 |
) |
|
26 |
); |
|
0 | 27 |
|
9 | 28 |
$wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' ); |
0 | 29 |
|
30 |
$action = $wp_list_table->current_action(); |
|
31 |
||
9 | 32 |
$s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; |
0 | 33 |
|
34 |
// Clean up request URI from temporary args for screen options/paging uri's to work as expected. |
|
9 | 35 |
$temp_args = array( 'enabled', 'disabled', 'error' ); |
0 | 36 |
$_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] ); |
9 | 37 |
$referer = remove_query_arg( $temp_args, wp_get_referer() ); |
0 | 38 |
|
5 | 39 |
if ( ! empty( $_REQUEST['paged'] ) ) { |
40 |
$referer = add_query_arg( 'paged', (int) $_REQUEST['paged'], $referer ); |
|
41 |
} |
|
42 |
||
0 | 43 |
$id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; |
44 |
||
9 | 45 |
if ( ! $id ) { |
46 |
wp_die( __( 'Invalid site ID.' ) ); |
|
47 |
} |
|
0 | 48 |
|
49 |
$wp_list_table->prepare_items(); |
|
50 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
$details = get_site( $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
if ( ! $details ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
wp_die( __( 'The requested site does not exist.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
|
9 | 56 |
if ( ! can_edit_network( $details->site_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
9 | 58 |
} |
0 | 59 |
|
60 |
$is_main_site = is_main_site( $id ); |
|
61 |
||
62 |
if ( $action ) { |
|
63 |
switch_to_blog( $id ); |
|
64 |
$allowed_themes = get_option( 'allowedthemes' ); |
|
65 |
||
66 |
switch ( $action ) { |
|
67 |
case 'enable': |
|
68 |
check_admin_referer( 'enable-theme_' . $_GET['theme'] ); |
|
9 | 69 |
$theme = $_GET['theme']; |
0 | 70 |
$action = 'enabled'; |
9 | 71 |
$n = 1; |
72 |
if ( ! $allowed_themes ) { |
|
0 | 73 |
$allowed_themes = array( $theme => true ); |
9 | 74 |
} else { |
75 |
$allowed_themes[ $theme ] = true; |
|
76 |
} |
|
0 | 77 |
break; |
78 |
case 'disable': |
|
79 |
check_admin_referer( 'disable-theme_' . $_GET['theme'] ); |
|
9 | 80 |
$theme = $_GET['theme']; |
0 | 81 |
$action = 'disabled'; |
9 | 82 |
$n = 1; |
83 |
if ( ! $allowed_themes ) { |
|
0 | 84 |
$allowed_themes = array(); |
9 | 85 |
} else { |
86 |
unset( $allowed_themes[ $theme ] ); |
|
87 |
} |
|
0 | 88 |
break; |
89 |
case 'enable-selected': |
|
90 |
check_admin_referer( 'bulk-themes' ); |
|
91 |
if ( isset( $_POST['checked'] ) ) { |
|
92 |
$themes = (array) $_POST['checked']; |
|
93 |
$action = 'enabled'; |
|
9 | 94 |
$n = count( $themes ); |
95 |
foreach ( (array) $themes as $theme ) { |
|
0 | 96 |
$allowed_themes[ $theme ] = true; |
9 | 97 |
} |
0 | 98 |
} else { |
99 |
$action = 'error'; |
|
9 | 100 |
$n = 'none'; |
0 | 101 |
} |
102 |
break; |
|
103 |
case 'disable-selected': |
|
104 |
check_admin_referer( 'bulk-themes' ); |
|
105 |
if ( isset( $_POST['checked'] ) ) { |
|
106 |
$themes = (array) $_POST['checked']; |
|
107 |
$action = 'disabled'; |
|
9 | 108 |
$n = count( $themes ); |
109 |
foreach ( (array) $themes as $theme ) { |
|
0 | 110 |
unset( $allowed_themes[ $theme ] ); |
9 | 111 |
} |
0 | 112 |
} else { |
113 |
$action = 'error'; |
|
9 | 114 |
$n = 'none'; |
0 | 115 |
} |
116 |
break; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
default: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
if ( isset( $_POST['checked'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
check_admin_referer( 'bulk-themes' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
$themes = (array) $_POST['checked']; |
9 | 121 |
$n = count( $themes ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
$screen = get_current_screen()->id; |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
* Fires when a custom bulk action should be handled. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* The redirect link should be modified with success or failure feedback |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
* from the action to be used to display feedback to the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
* The dynamic portion of the hook name, `$screen`, refers to the current screen ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
* @param string $redirect_url The redirect URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
* @param string $action The action being taken. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
* @param array $items The items to take the action on. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
* @param int $site_id The site ID. |
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 |
$referer = apply_filters( "handle_network_bulk_actions-{$screen}", $referer, $action, $themes, $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
$action = 'error'; |
9 | 142 |
$n = 'none'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
} |
0 | 144 |
} |
145 |
||
146 |
update_option( 'allowedthemes', $allowed_themes ); |
|
147 |
restore_current_blog(); |
|
148 |
||
9 | 149 |
wp_safe_redirect( |
150 |
add_query_arg( |
|
151 |
array( |
|
152 |
'id' => $id, |
|
153 |
$action => $n, |
|
154 |
), |
|
155 |
$referer |
|
156 |
) |
|
157 |
); |
|
0 | 158 |
exit; |
159 |
} |
|
160 |
||
161 |
if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) { |
|
162 |
wp_safe_redirect( $referer ); |
|
163 |
exit(); |
|
164 |
} |
|
165 |
||
166 |
add_thickbox(); |
|
5 | 167 |
add_screen_option( 'per_page' ); |
0 | 168 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
/* translators: %s: site name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
$title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) ); |
0 | 171 |
|
9 | 172 |
$parent_file = 'sites.php'; |
0 | 173 |
$submenu_file = 'sites.php'; |
174 |
||
175 |
require( ABSPATH . 'wp-admin/admin-header.php' ); ?> |
|
176 |
||
177 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
<h1 id="edit-site"><?php echo $title; ?></h1> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
<p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p> |
0 | 180 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
|
9 | 182 |
network_edit_site_nav( |
183 |
array( |
|
184 |
'blog_id' => $id, |
|
185 |
'selected' => 'site-themes', |
|
186 |
) |
|
187 |
); |
|
0 | 188 |
|
189 |
if ( isset( $_GET['enabled'] ) ) { |
|
5 | 190 |
$enabled = absint( $_GET['enabled'] ); |
191 |
if ( 1 == $enabled ) { |
|
192 |
$message = __( 'Theme enabled.' ); |
|
193 |
} else { |
|
194 |
$message = _n( '%s theme enabled.', '%s themes enabled.', $enabled ); |
|
195 |
} |
|
196 |
echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>'; |
|
0 | 197 |
} elseif ( isset( $_GET['disabled'] ) ) { |
5 | 198 |
$disabled = absint( $_GET['disabled'] ); |
199 |
if ( 1 == $disabled ) { |
|
200 |
$message = __( 'Theme disabled.' ); |
|
201 |
} else { |
|
202 |
$message = _n( '%s theme disabled.', '%s themes disabled.', $disabled ); |
|
203 |
} |
|
204 |
echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>'; |
|
0 | 205 |
} elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) { |
5 | 206 |
echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>'; |
9 | 207 |
} |
208 |
?> |
|
0 | 209 |
|
9 | 210 |
<p><?php _e( 'Network enabled themes are not shown on this screen.' ); ?></p> |
0 | 211 |
|
5 | 212 |
<form method="get"> |
0 | 213 |
<?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?> |
9 | 214 |
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" /> |
0 | 215 |
</form> |
216 |
||
217 |
<?php $wp_list_table->views(); ?> |
|
218 |
||
219 |
<form method="post" action="site-themes.php?action=update-site"> |
|
9 | 220 |
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" /> |
0 | 221 |
|
222 |
<?php $wp_list_table->display(); ?> |
|
223 |
||
224 |
</form> |
|
225 |
||
226 |
</div> |
|
9 | 227 |
<?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?> |