WordPress 3.4
[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( './admin.php' );
12
13 if ( ! is_multisite() )
14         wp_die( __( 'Multisite support is not enabled.' ) );
15
16 $menu_perms = get_site_option( 'menu_items', array() );
17
18 if ( empty( $menu_perms['themes'] ) && ! is_super_admin() )
19         wp_die( __( 'Cheatin&#8217; uh?' ) );
20
21 if ( !current_user_can('manage_network_themes') )
22         wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) );
23
24 $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
25 $pagenum = $wp_list_table->get_pagenum();
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', 'deleted', 'error' );
33 $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
34 $referer = remove_query_arg( $temp_args, wp_get_referer() );
35
36 if ( $action ) {
37         $allowed_themes = get_site_option( 'allowedthemes' );
38         switch ( $action ) {
39                 case 'enable':
40                         check_admin_referer('enable-theme_' . $_GET['theme']);
41                         $allowed_themes[ $_GET['theme'] ] = true;
42                         update_site_option( 'allowedthemes', $allowed_themes );
43                         if ( false === strpos( $referer, '/network/themes.php' ) )
44                                 wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
45                         else
46                                 wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
47                         exit;
48                         break;
49                 case 'disable':
50                         check_admin_referer('disable-theme_' . $_GET['theme']);
51                         unset( $allowed_themes[ $_GET['theme'] ] );
52                         update_site_option( 'allowedthemes', $allowed_themes );
53                         wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
54                         exit;
55                         break;
56                 case 'enable-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                         foreach( (array) $themes as $theme )
64                                 $allowed_themes[ $theme ] = true;
65                         update_site_option( 'allowedthemes', $allowed_themes );
66                         wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
67                         exit;
68                         break;
69                 case 'disable-selected':
70                         check_admin_referer('bulk-themes');
71                         $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
72                         if ( empty($themes) ) {
73                                 wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
74                                 exit;
75                         }
76                         foreach( (array) $themes as $theme )
77                                 unset( $allowed_themes[ $theme ] );
78                         update_site_option( 'allowedthemes', $allowed_themes );
79                         wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
80                         exit;
81                         break;
82                 case 'update-selected' :
83                         check_admin_referer( 'bulk-themes' );
84
85                         if ( isset( $_GET['themes'] ) )
86                                 $themes = explode( ',', $_GET['themes'] );
87                         elseif ( isset( $_POST['checked'] ) )
88                                 $themes = (array) $_POST['checked'];
89                         else
90                                 $themes = array();
91
92                         $title = __( 'Update Themes' );
93                         $parent_file = 'themes.php';
94
95                         require_once(ABSPATH . 'wp-admin/admin-header.php');
96
97                         echo '<div class="wrap">';
98                         screen_icon();
99                         echo '<h2>' . esc_html( $title ) . '</h2>';
100
101                         $url = self_admin_url('update.php?action=update-selected-themes&amp;themes=' . urlencode( join(',', $themes) ));
102                         $url = wp_nonce_url($url, 'bulk-update-themes');
103
104                         echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
105                         echo '</div>';
106                         require_once(ABSPATH . 'wp-admin/admin-footer.php');
107                         exit;
108                         break;
109                 case 'delete-selected':
110                         if ( ! current_user_can( 'delete_themes' ) )
111                                 wp_die( __('You do not have sufficient permissions to delete themes for this site.') );
112                         check_admin_referer( 'bulk-themes' );
113
114                         $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
115
116                         unset( $themes[ get_option( 'stylesheet' ) ], $themes[ get_option( 'template' ) ] );
117
118                         if ( empty( $themes ) ) {
119                                 wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
120                                 exit;
121                         }
122
123                         $files_to_delete = $theme_info = array();
124                         foreach ( $themes as $key => $theme ) {
125                                 $theme_info[ $theme ] = wp_get_theme( $theme );
126                                 $files_to_delete = array_merge( $files_to_delete, list_files( $theme_info[ $theme ]->get_stylesheet_directory() ) );
127                         }
128
129                         if ( empty( $themes ) ) {
130                                 wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) );
131                                 exit;
132                         }
133
134                         include(ABSPATH . 'wp-admin/update.php');
135
136                         $parent_file = 'themes.php';
137
138                         if ( ! isset( $_REQUEST['verify-delete'] ) ) {
139                                 wp_enqueue_script( 'jquery' );
140                                 require_once( ABSPATH . 'wp-admin/admin-header.php' );
141                                 ?>
142                         <div class="wrap">
143                                 <?php
144                                         $themes_to_delete = count( $themes );
145                                         screen_icon();
146                                         echo '<h2>' . _n( 'Delete Theme', 'Delete Themes', $themes_to_delete ) . '</h2>';
147                                 ?>
148                                 <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo _n( 'This theme may be active on other sites in the network.', 'These themes may be active on other sites in the network.', $themes_to_delete ); ?></p></div>
149                                 <p><?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?></p>
150                                         <ul class="ul-disc">
151                                                 <?php foreach ( $theme_info as $theme )
152                                                         echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $theme->display('Name'), $theme->display('Author') ), '</li>'; /* translators: 1: theme name, 2: theme author */ ?>
153                                         </ul>
154                                 <p><?php _e('Are you sure you wish to delete these themes?'); ?></p>
155                                 <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
156                                         <input type="hidden" name="verify-delete" value="1" />
157                                         <input type="hidden" name="action" value="delete-selected" />
158                                         <?php
159                                                 foreach ( (array) $themes as $theme )
160                                                         echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />';
161                                         ?>
162                                         <?php wp_nonce_field('bulk-themes') ?>
163                                         <?php submit_button( _n( 'Yes, Delete this theme', 'Yes, Delete these themes', $themes_to_delete ), 'button', 'submit', false ); ?>
164                                 </form>
165                                 <form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;">
166                                         <?php submit_button( __( 'No, Return me to the theme list' ), 'button', 'submit', false ); ?>
167                                 </form>
168
169                                 <p><a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php _e('Click to view entire list of files which will be deleted'); ?></a></p>
170                                 <div id="files-list" style="display:none;">
171                                         <ul class="code">
172                                         <?php
173                                                 foreach ( (array) $files_to_delete as $file )
174                                                         echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . "/themes", '', $file) ) . '</li>';
175                                         ?>
176                                         </ul>
177                                 </div>
178                         </div>
179                                 <?php
180                                 require_once(ABSPATH . 'wp-admin/admin-footer.php');
181                                 exit;
182                         } // Endif verify-delete
183
184                         foreach ( $themes as $theme )
185                                 $delete_result = delete_theme( $theme, esc_url( add_query_arg( array('verify-delete' => 1), $_SERVER['REQUEST_URI'] ) ) );
186                         $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
187                         wp_redirect( network_admin_url( "themes.php?deleted=".count( $themes )."&paged=$paged&s=$s" ) );
188                         exit;
189                         break;
190         }
191 }
192
193 $wp_list_table->prepare_items();
194
195 add_thickbox();
196
197 add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' )) );
198
199 get_current_screen()->add_help_tab( array(
200         'id'      => 'overview',
201         'title'   => __('Overview'),
202         'content' =>
203                 '<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>' .
204                 '<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>' .
205                 '<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>'
206 ) );
207
208 get_current_screen()->set_help_sidebar(
209         '<p><strong>' . __('For more information:') . '</strong></p>' .
210         '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Themes_Screen" target="_blank">Documentation on Network Themes</a>') . '</p>' .
211         '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
212 );
213
214 $title = __('Themes');
215 $parent_file = 'themes.php';
216
217 require_once(ABSPATH . 'wp-admin/admin-header.php');
218
219 ?>
220
221 <div class="wrap">
222 <?php screen_icon('themes'); ?>
223 <h2><?php echo esc_html( $title ); if ( current_user_can('install_themes') ) { ?> <a href="theme-install.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'theme'); ?></a><?php }
224 if ( $s )
225         printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?>
226 </h2>
227
228 <?php
229 if ( isset( $_GET['enabled'] ) ) {
230         $_GET['enabled'] = absint( $_GET['enabled'] );
231         echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme enabled.', '%s themes enabled.', $_GET['enabled'] ), number_format_i18n( $_GET['enabled'] ) ) . '</p></div>';
232 } elseif ( isset( $_GET['disabled'] ) ) {
233         $_GET['disabled'] = absint( $_GET['disabled'] );
234         echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme disabled.', '%s themes disabled.', $_GET['disabled'] ), number_format_i18n( $_GET['disabled'] ) ) . '</p></div>';
235 } elseif ( isset( $_GET['deleted'] ) ) {
236         $_GET['deleted'] = absint( $_GET['deleted'] );
237         echo '<div id="message" class="updated"><p>' . sprintf( _nx( 'Theme deleted.', '%s themes deleted.', $_GET['deleted'], 'network' ), number_format_i18n( $_GET['deleted'] ) ) . '</p></div>';
238 } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
239         echo '<div id="message" class="error"><p>' . __( 'No theme selected.' ) . '</p></div>';
240 } elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) {
241         echo '<div class="error"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
242 }
243
244 ?>
245
246 <form method="get" action="">
247 <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
248 </form>
249
250 <?php
251 $wp_list_table->views();
252
253 if ( 'broken' == $status )
254         echo '<p class="clear">' . __('The following themes are installed but incomplete. Themes must have a stylesheet and a template.') . '</p>';
255 ?>
256
257 <form method="post" action="">
258 <input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" />
259 <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
260
261 <?php $wp_list_table->display(); ?>
262 </form>
263
264 </div>
265
266 <?php
267 include(ABSPATH . 'wp-admin/admin-footer.php');