3 * Themes administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
12 if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
13 wp_die( __( 'Cheatin’ uh?' ) );
15 if ( current_user_can('switch_themes') && isset($_GET['action']) ) {
16 if ( 'activate' == $_GET['action'] ) {
17 check_admin_referer('switch-theme_' . $_GET['template']);
18 switch_theme($_GET['template'], $_GET['stylesheet']);
19 wp_redirect('themes.php?activated=true');
21 } else if ( 'delete' == $_GET['action'] ) {
22 check_admin_referer('delete-theme_' . $_GET['template']);
23 if ( !current_user_can('delete_themes') )
24 wp_die( __( 'Cheatin’ uh?' ) );
25 delete_theme($_GET['template']);
26 wp_redirect('themes.php?deleted=true');
31 $title = __('Manage Themes');
32 $parent_file = 'themes.php';
34 if ( current_user_can( 'switch_themes' ) ) :
36 $help = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>';
37 $help .= '<p>' . __('You can see your active theme at the top of the screen. Below are the other themes you have installed that are not currently in use. You can see what your site would look like with one of these themes by clicking the Preview link. To change themes, click the Activate link.') . '</p>';
38 if ( current_user_can('install_themes') )
39 $help .= '<p>' . sprintf(__('If you would like to see more themes to choose from, click on the “Install Themes” tab and you will be able to browse or search for additional themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. Themes in the WordPress.org Theme Directory are designed and developed by third parties, and are licensed under the GNU General Public License, version 2, just like WordPress. Oh, and they’re free!'), 'http://wordpress.org/extend/themes/') . '</p>';
41 $help .= '<p><strong>' . __('For more information:') . '</strong></p>';
42 $help .= '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>') . '</p>';
43 $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
44 add_contextual_help($current_screen, $help);
47 wp_enqueue_script( 'theme-preview' );
51 require_once('./admin-header.php');
52 if ( is_multisite() && current_user_can('edit_themes') ) {
53 ?><div id="message0" class="updated"><p><?php printf( __('Administrator: new themes must be activated in the <a href="%s">Network Themes</a> screen before they appear here.'), admin_url( 'ms-themes.php') ); ?></p></div><?php
57 <?php if ( ! validate_current_theme() ) : ?>
58 <div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
59 <?php elseif ( isset($_GET['activated']) ) :
60 if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?>
61 <div id="message2" class="updated"><p><?php printf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) ); ?></p></div><?php
63 <div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
65 elseif ( isset($_GET['deleted']) ) : ?>
66 <div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
69 $themes = get_allowed_themes();
70 $ct = current_theme_info();
71 unset($themes[$ct->name]);
73 uksort( $themes, "strnatcasecmp" );
74 $theme_total = count( $themes );
77 if ( isset( $_GET['pagenum'] ) )
78 $page = absint( $_GET['pagenum'] );
83 $start = $offset = ( $page - 1 ) * $per_page;
85 $page_links = paginate_links( array(
86 'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
88 'prev_text' => __('«'),
89 'next_text' => __('»'),
90 'total' => ceil($theme_total / $per_page),
94 $themes = array_slice( $themes, $start, $per_page );
98 <?php screen_icon(); ?>
99 <h2><a href="themes.php" class="nav-tab nav-tab-active"><?php echo esc_html( $title ); ?></a><?php if ( current_user_can('install_themes') ) { ?><a href="theme-install.php" class="nav-tab"><?php echo esc_html_x('Install Themes', 'theme'); ?></a><?php } ?></h2>
101 <h3><?php _e('Current Theme'); ?></h3>
102 <div id="current-theme">
103 <?php if ( $ct->screenshot ) : ?>
104 <img src="<?php echo $ct->theme_root_uri . '/' . $ct->stylesheet . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
107 /* translators: 1: theme title, 2: theme version, 3: theme author */
108 printf(__('%1$s %2$s by %3$s'), $ct->title, $ct->version, $ct->author) ; ?></h4>
109 <p class="theme-description"><?php echo $ct->description; ?></p>
110 <?php if ( current_user_can('edit_themes') && $ct->parent_theme ) { ?>
111 <p><?php printf(__('The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.'), $ct->title, str_replace( WP_CONTENT_DIR, '', $ct->template_dir ), str_replace( WP_CONTENT_DIR, '', $ct->stylesheet_dir ), $ct->title, $ct->parent_theme); ?></p>
113 <p><?php printf(__('All of this theme’s files are located in <code>%2$s</code>.'), $ct->title, str_replace( WP_CONTENT_DIR, '', $ct->template_dir ), str_replace( WP_CONTENT_DIR, '', $ct->stylesheet_dir ) ); ?></p>
115 <?php if ( $ct->tags ) : ?>
116 <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
118 <?php theme_update_available($ct); ?>
122 <div class="clear"></div>
124 if ( ! current_user_can( 'switch_themes' ) ) {
126 require( './admin-footer.php' );
130 <h3><?php _e('Available Themes'); ?></h3>
131 <div class="clear"></div>
133 <?php if ( $theme_total ) { ?>
135 <?php if ( $page_links ) : ?>
136 <div class="tablenav">
137 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s',
138 number_format_i18n( $start + 1 ),
139 number_format_i18n( min( $page * $per_page, $theme_total ) ),
140 number_format_i18n( $theme_total ),
142 ); echo $page_links_text; ?></div>
146 <table id="availablethemes" cellspacing="0" cellpadding="0">
150 $theme_names = array_keys($themes);
151 natcasesort($theme_names);
154 $rows = ceil(count($theme_names) / 3);
155 for ( $row = 1; $row <= $rows; $row++ )
156 for ( $col = 1; $col <= 3; $col++ )
157 $table[$row][$col] = array_shift($theme_names);
159 foreach ( $table as $row => $cols ) {
163 foreach ( $cols as $col => $theme_name ) {
164 $class = array('available-theme');
165 if ( $row == 1 ) $class[] = 'top';
166 if ( $col == 1 ) $class[] = 'left';
167 if ( $row == $rows ) $class[] = 'bottom';
168 if ( $col == 3 ) $class[] = 'right';
170 <td class="<?php echo join(' ', $class); ?>">
171 <?php if ( !empty($theme_name) ) :
172 $template = $themes[$theme_name]['Template'];
173 $stylesheet = $themes[$theme_name]['Stylesheet'];
174 $title = $themes[$theme_name]['Title'];
175 $version = $themes[$theme_name]['Version'];
176 $description = $themes[$theme_name]['Description'];
177 $author = $themes[$theme_name]['Author'];
178 $screenshot = $themes[$theme_name]['Screenshot'];
179 $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
180 $template_dir = $themes[$theme_name]['Template Dir'];
181 $parent_theme = $themes[$theme_name]['Parent Theme'];
182 $theme_root = $themes[$theme_name]['Theme Root'];
183 $theme_root_uri = $themes[$theme_name]['Theme Root URI'];
184 $preview_link = esc_url(get_option('home') . '/');
186 $preview_link = str_replace( 'http://', 'https://', $preview_link );
187 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
188 $preview_text = esc_attr( sprintf( __('Preview of “%s”'), $title ) );
189 $tags = $themes[$theme_name]['Tags'];
190 $thickbox_class = 'thickbox thickbox-preview';
191 $activate_link = wp_nonce_url("themes.php?action=activate&template=".urlencode($template)."&stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
192 $activate_text = esc_attr( sprintf( __('Activate “%s”'), $title ) );
194 $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="' . $activate_text . '">' . __('Activate') . '</a>';
195 $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $theme_name)) . '">' . __('Preview') . '</a>';
196 if ( current_user_can('delete_themes') )
197 $actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url("themes.php?action=delete&template=$stylesheet", 'delete-theme_' . $stylesheet) . '" onclick="' . "return confirm('" . esc_js(sprintf( __("You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete."), $theme_name )) . "');" . '">' . __('Delete') . '</a>';
198 $actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);
200 $actions = implode ( ' | ', $actions );
202 <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
203 <?php if ( $screenshot ) : ?>
204 <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" />
208 /* translators: 1: theme title, 2: theme version, 3: theme author */
209 printf(__('%1$s %2$s by %3$s'), $title, $version, $author) ; ?></h3>
210 <p class="description"><?php echo $description; ?></p>
211 <span class='action-links'><?php echo $actions ?></span>
212 <?php if ( current_user_can('edit_themes') && $parent_theme ) {
213 /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
214 <p><?php printf(__('The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.'), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ), $title, $parent_theme); ?></p>
216 <p><?php printf(__('All of this theme’s files are located in <code>%2$s</code>.'), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ) ); ?></p>
218 <?php if ( $tags ) : ?>
219 <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
221 <?php theme_update_available( $themes[$theme_name] ); ?>
222 <?php endif; // end if not empty theme_name ?>
224 <?php } // end foreach $cols ?>
226 <?php } // end foreach $table ?>
230 if ( current_user_can('install_themes') )
231 printf(__('You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress.org Theme Directory at any time: just click on the <em><a href="%s">Install Themes</a></em> tab above.'), 'theme-install.php');
233 printf(__('Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.'), get_site_option('site_name'));
235 <?php } // end if $theme_total?>
238 <?php if ( $page_links ) : ?>
239 <div class="tablenav">
240 <?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
248 // List broken themes, if any.
249 $broken_themes = get_broken_themes();
250 if ( current_user_can('edit_themes') && count( $broken_themes ) ) {
253 <h2><?php _e('Broken Themes'); ?> <?php if ( is_multisite() ) _e( '(Site admin only)' ); ?></h2>
254 <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
256 <table id="broken-themes">
258 <th><?php _e('Name'); ?></th>
259 <th><?php _e('Description'); ?></th>
264 $theme_names = array_keys($broken_themes);
265 natcasesort($theme_names);
267 foreach ($theme_names as $theme_name) {
268 $title = $broken_themes[$theme_name]['Title'];
269 $description = $broken_themes[$theme_name]['Description'];
271 $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
275 <td>$description</td>
285 <?php require('./admin-footer.php'); ?>