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