Wordpress 4.6
[autoinstalls/wordpress.git] / wp-admin / network / themes.php
1 <?php
2 /**
3  * Multisite themes administration panel.
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
13 if ( ! is_multisite() )
14         wp_die( __( 'Multisite support is not enabled.' ) );
15
16 if ( !current_user_can('manage_network_themes') )
17         wp_die( __( 'Sorry, you are not allowed to manage network themes.' ) );
18
19 $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
20 $pagenum = $wp_list_table->get_pagenum();
21
22 $action = $wp_list_table->current_action();
23
24 $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
25
26 // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
27 $temp_args = array( 'enabled', 'disabled', 'deleted', 'error' );
28 $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
29 $referer = remove_query_arg( $temp_args, wp_get_referer() );
30
31 if ( $action ) {
32         switch ( $action ) {
33                 case 'enable':
34                         check_admin_referer('enable-theme_' . $_GET['theme']);
35                         WP_Theme::network_enable_theme( $_GET['theme'] );
36                         if ( false === strpos( $referer, '/network/themes.php' ) )
37                                 wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
38                         else
39                                 wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
40                         exit;
41                 case 'disable':
42                         check_admin_referer('disable-theme_' . $_GET['theme']);
43                         WP_Theme::network_disable_theme( $_GET['theme'] );
44                         wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
45                         exit;
46                 case 'enable-selected':
47                         check_admin_referer('bulk-themes');
48                         $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
49                         if ( empty($themes) ) {
50                                 wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
51                                 exit;
52                         }
53                         WP_Theme::network_enable_theme( (array) $themes );
54                         wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
55                         exit;
56                 case 'disable-selected':
57                         check_admin_referer('bulk-themes');
58                         $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
59                         if ( empty($themes) ) {
60                                 wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
61                                 exit;
62                         }
63                         WP_Theme::network_disable_theme( (array) $themes );
64                         wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
65                         exit;
66                 case 'update-selected' :
67                         check_admin_referer( 'bulk-themes' );
68
69                         if ( isset( $_GET['themes'] ) )
70                                 $themes = explode( ',', $_GET['themes'] );
71                         elseif ( isset( $_POST['checked'] ) )
72                                 $themes = (array) $_POST['checked'];
73                         else
74                                 $themes = array();
75
76                         $title = __( 'Update Themes' );
77                         $parent_file = 'themes.php';
78
79                         require_once(ABSPATH . 'wp-admin/admin-header.php');
80
81                         echo '<div class="wrap">';
82                         echo '<h1>' . esc_html( $title ) . '</h1>';
83
84                         $url = self_admin_url('update.php?action=update-selected-themes&amp;themes=' . urlencode( join(',', $themes) ));
85                         $url = wp_nonce_url($url, 'bulk-update-themes');
86
87                         echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
88                         echo '</div>';
89                         require_once(ABSPATH . 'wp-admin/admin-footer.php');
90                         exit;
91                 case 'delete-selected':
92                         if ( ! current_user_can( 'delete_themes' ) ) {
93                                 wp_die( __('Sorry, you are not allowed to delete themes for this site.') );
94                         }
95
96                         check_admin_referer( 'bulk-themes' );
97
98                         $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
99
100                         if ( empty( $themes ) ) {
101                                 wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
102                                 exit;
103                         }
104
105                         $themes = array_diff( $themes, array( get_option( 'stylesheet' ), get_option( 'template' ) ) );
106
107                         if ( empty( $themes ) ) {
108                                 wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) );
109                                 exit;
110                         }
111
112                         $theme_info = array();
113                         foreach ( $themes as $key => $theme ) {
114                                 $theme_info[ $theme ] = wp_get_theme( $theme );
115                         }
116
117                         include(ABSPATH . 'wp-admin/update.php');
118
119                         $parent_file = 'themes.php';
120
121                         if ( ! isset( $_REQUEST['verify-delete'] ) ) {
122                                 wp_enqueue_script( 'jquery' );
123                                 require_once( ABSPATH . 'wp-admin/admin-header.php' );
124                                 $themes_to_delete = count( $themes );
125                                 ?>
126                         <div class="wrap">
127                                 <?php if ( 1 == $themes_to_delete ) : ?>
128                                         <h1><?php _e( 'Delete Theme' ); ?></h1>
129                                         <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'This theme may be active on other sites in the network.' ); ?></p></div>
130                                         <p><?php _e( 'You are about to remove the following theme:' ); ?></p>
131                                 <?php else : ?>
132                                         <h1><?php _e( 'Delete Themes' ); ?></h1>
133                                         <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'These themes may be active on other sites in the network.' ); ?></p></div>
134                                         <p><?php _e( 'You are about to remove the following themes:' ); ?></p>
135                                 <?php endif; ?>
136                                         <ul class="ul-disc">
137                                         <?php
138                                                 foreach ( $theme_info as $theme ) {
139                                                         echo '<li>' . sprintf(
140                                                                 /* translators: 1: theme name, 2: theme author */
141                                                                 _x( '%1$s by %2$s', 'theme' ),
142                                                                 '<strong>' . $theme->display( 'Name' ) . '</strong>',
143                                                                 '<em>' . $theme->display( 'Author' ) . '</em>'
144                                                         ) . '</li>';
145                                                 }
146                                         ?>
147                                         </ul>
148                                 <?php if ( 1 == $themes_to_delete ) : ?>
149                                         <p><?php _e( 'Are you sure you wish to delete this theme?' ); ?></p>
150                                 <?php else : ?>
151                                         <p><?php _e( 'Are you sure you wish to delete these themes?' ); ?></p>
152                                 <?php endif; ?>
153                                 <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
154                                         <input type="hidden" name="verify-delete" value="1" />
155                                         <input type="hidden" name="action" value="delete-selected" />
156                                         <?php
157                                                 foreach ( (array) $themes as $theme ) {
158                                                         echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />';
159                                                 }
160
161                                                 wp_nonce_field( 'bulk-themes' );
162
163                                                 if ( 1 == $themes_to_delete ) {
164                                                         submit_button( __( 'Yes, delete this theme' ), 'button', 'submit', false );
165                                                 } else {
166                                                         submit_button( __( 'Yes, delete these themes' ), 'button', 'submit', false );
167                                                 }
168                                         ?>
169                                 </form>
170                                 <?php
171                                 $referer = wp_get_referer();
172                                 ?>
173                                 <form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;">
174                                         <?php submit_button( __( 'No, return me to the theme list' ), 'button', 'submit', false ); ?>
175                                 </form>
176                         </div>
177                                 <?php
178                                 require_once(ABSPATH . 'wp-admin/admin-footer.php');
179                                 exit;
180                         } // Endif verify-delete
181
182                         foreach ( $themes as $theme ) {
183                                 $delete_result = delete_theme( $theme, esc_url( add_query_arg( array(
184                                         'verify-delete' => 1,
185                                         'action' => 'delete-selected',
186                                         'checked' => $_REQUEST['checked'],
187                                         '_wpnonce' => $_REQUEST['_wpnonce']
188                                 ), network_admin_url( 'themes.php' ) ) ) );
189                         }
190
191                         $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
192                         wp_redirect( add_query_arg( array(
193                                 'deleted' => count( $themes ),
194                                 'paged' => $paged,
195                                 's' => $s
196                         ), network_admin_url( 'themes.php' ) ) );
197                         exit;
198         }
199 }
200
201 $wp_list_table->prepare_items();
202
203 add_thickbox();
204
205 add_screen_option( 'per_page' );
206
207 get_current_screen()->add_help_tab( array(
208         'id'      => 'overview',
209         'title'   => __('Overview'),
210         'content' =>
211                 '<p>' . __('This screen enables and disables the inclusion of themes available to choose in the Appearance menu for each site. It does not activate or deactivate which theme a site is currently using.') . '</p>' .
212                 '<p>' . __('If the network admin disables a theme that is in use, it can still remain selected on that site. If another theme is chosen, the disabled theme will not appear in the site&#8217;s Appearance > Themes screen.') . '</p>' .
213                 '<p>' . __('Themes can be enabled on a site by site basis by the network admin on the Edit Site screen (which has a Themes tab); get there via the Edit action link on the All Sites screen. Only network admins are able to install or edit themes.') . '</p>'
214 ) );
215
216 get_current_screen()->set_help_sidebar(
217         '<p><strong>' . __('For more information:') . '</strong></p>' .
218         '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen" target="_blank">Documentation on Network Themes</a>') . '</p>' .
219         '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
220 );
221
222 get_current_screen()->set_screen_reader_content( array(
223         'heading_views'      => __( 'Filter themes list' ),
224         'heading_pagination' => __( 'Themes list navigation' ),
225         'heading_list'       => __( 'Themes list' ),
226 ) );
227
228 $title = __('Themes');
229 $parent_file = 'themes.php';
230
231 wp_enqueue_script( 'updates' );
232 wp_enqueue_script( 'theme-preview' );
233
234 require_once(ABSPATH . 'wp-admin/admin-header.php');
235
236 ?>
237
238 <div class="wrap">
239 <h1><?php echo esc_html( $title ); if ( current_user_can('install_themes') ) { ?> <a href="theme-install.php" class="page-title-action"><?php echo esc_html_x('Add New', 'theme'); ?></a><?php }
240 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
241         /* translators: %s: search keywords */
242         printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
243 }
244 ?>
245 </h1>
246
247 <?php
248 if ( isset( $_GET['enabled'] ) ) {
249         $enabled = absint( $_GET['enabled'] );
250         if ( 1 == $enabled ) {
251                 $message = __( 'Theme enabled.' );
252         } else {
253                 $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
254         }
255         echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
256 } elseif ( isset( $_GET['disabled'] ) ) {
257         $disabled = absint( $_GET['disabled'] );
258         if ( 1 == $disabled ) {
259                 $message = __( 'Theme disabled.' );
260         } else {
261                 $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
262         }
263         echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
264 } elseif ( isset( $_GET['deleted'] ) ) {
265         $deleted = absint( $_GET['deleted'] );
266         if ( 1 == $deleted ) {
267                 $message = __( 'Theme deleted.' );
268         } else {
269                 $message = _n( '%s theme deleted.', '%s themes deleted.', $deleted );
270         }
271         echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $deleted ) ) . '</p></div>';
272 } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
273         echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
274 } elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) {
275         echo '<div class="error notice is-dismissible"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
276 }
277
278 ?>
279
280 <form method="get">
281 <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
282 </form>
283
284 <?php
285 $wp_list_table->views();
286
287 if ( 'broken' == $status )
288         echo '<p class="clear">' . __( 'The following themes are installed but incomplete.' ) . '</p>';
289 ?>
290
291 <form id="bulk-action-form" method="post">
292 <input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" />
293 <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
294
295 <?php $wp_list_table->display(); ?>
296 </form>
297
298 </div>
299
300 <?php
301 wp_print_request_filesystem_credentials_modal();
302 wp_print_admin_notice_templates();
303 wp_print_update_row_templates();
304
305 include(ABSPATH . 'wp-admin/admin-footer.php');