author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
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 */ |
|
16 | 11 |
require_once __DIR__ . '/admin.php'; |
0 | 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 |
||
18 | 43 |
$id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0; |
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 |
*/ |
16 | 139 |
$referer = apply_filters( "handle_network_bulk_actions-{$screen}", $referer, $action, $themes, $id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
7
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 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
146 |
update_option( 'allowedthemes', $allowed_themes, false ); |
0 | 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 |
||
16 | 161 |
if ( isset( $_GET['action'] ) && 'update-site' === $_GET['action'] ) { |
0 | 162 |
wp_safe_redirect( $referer ); |
16 | 163 |
exit; |
0 | 164 |
} |
165 |
||
166 |
add_thickbox(); |
|
5 | 167 |
add_screen_option( 'per_page' ); |
0 | 168 |
|
19 | 169 |
// Used in the HTML title tag. |
16 | 170 |
/* translators: %s: Site title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
$title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) ); |
0 | 172 |
|
9 | 173 |
$parent_file = 'sites.php'; |
0 | 174 |
$submenu_file = 'sites.php'; |
175 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
176 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
177 |
?> |
0 | 178 |
|
179 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
<h1 id="edit-site"><?php echo $title; ?></h1> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
<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 | 182 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
|
9 | 184 |
network_edit_site_nav( |
185 |
array( |
|
186 |
'blog_id' => $id, |
|
187 |
'selected' => 'site-themes', |
|
188 |
) |
|
189 |
); |
|
0 | 190 |
|
191 |
if ( isset( $_GET['enabled'] ) ) { |
|
5 | 192 |
$enabled = absint( $_GET['enabled'] ); |
16 | 193 |
if ( 1 === $enabled ) { |
5 | 194 |
$message = __( 'Theme enabled.' ); |
195 |
} else { |
|
16 | 196 |
/* translators: %s: Number of themes. */ |
5 | 197 |
$message = _n( '%s theme enabled.', '%s themes enabled.', $enabled ); |
198 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
199 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
200 |
wp_admin_notice( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
201 |
sprintf( $message, number_format_i18n( $enabled ) ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
202 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
203 |
'type' => 'success', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
204 |
'dismissible' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
205 |
'id' => 'message', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
206 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
207 |
); |
0 | 208 |
} elseif ( isset( $_GET['disabled'] ) ) { |
5 | 209 |
$disabled = absint( $_GET['disabled'] ); |
16 | 210 |
if ( 1 === $disabled ) { |
5 | 211 |
$message = __( 'Theme disabled.' ); |
212 |
} else { |
|
16 | 213 |
/* translators: %s: Number of themes. */ |
5 | 214 |
$message = _n( '%s theme disabled.', '%s themes disabled.', $disabled ); |
215 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
216 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
217 |
wp_admin_notice( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
218 |
sprintf( $message, number_format_i18n( $disabled ) ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
219 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
220 |
'type' => 'success', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
221 |
'dismissible' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
222 |
'id' => 'message', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
223 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
224 |
); |
16 | 225 |
} elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
226 |
wp_admin_notice( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
227 |
__( 'No theme selected.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
228 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
229 |
'type' => 'error', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
230 |
'dismissible' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
231 |
'id' => 'message', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
233 |
); |
9 | 234 |
} |
235 |
?> |
|
0 | 236 |
|
9 | 237 |
<p><?php _e( 'Network enabled themes are not shown on this screen.' ); ?></p> |
0 | 238 |
|
5 | 239 |
<form method="get"> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
240 |
<?php $wp_list_table->search_box( __( 'Search installed themes' ), 'theme' ); ?> |
9 | 241 |
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" /> |
0 | 242 |
</form> |
243 |
||
244 |
<?php $wp_list_table->views(); ?> |
|
245 |
||
246 |
<form method="post" action="site-themes.php?action=update-site"> |
|
9 | 247 |
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" /> |
0 | 248 |
|
249 |
<?php $wp_list_table->display(); ?> |
|
250 |
||
251 |
</form> |
|
252 |
||
253 |
</div> |
|
16 | 254 |
<?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?> |