3 * Themes administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
12 if ( isset($_GET['action']) ) {
13 check_admin_referer('switch-theme_' . $_GET['template']);
15 if ('activate' == $_GET['action']) {
16 switch_theme($_GET['template'], $_GET['stylesheet']);
17 wp_redirect('themes.php?activated=true');
22 $title = __('Manage Themes');
23 $parent_file = 'themes.php';
26 wp_enqueue_script( 'theme-preview' );
28 require_once('admin-header.php');
31 <?php if ( ! validate_current_theme() ) : ?>
32 <div id="message1" class="updated fade"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
33 <?php elseif ( isset($_GET['activated']) ) : ?>
34 <div id="message2" class="updated fade"><p><?php printf(__('New theme activated. <a href="%s">Visit site</a>'), get_bloginfo('url') . '/'); ?></p></div>
38 $themes = get_themes();
39 $ct = current_theme_info();
42 $theme_total = count( $themes );
45 if ( isset( $_GET['pagenum'] ) )
46 $page = absint( $_GET['pagenum'] );
51 $start = $offset = ( $page - 1 ) * $per_page;
53 $page_links = paginate_links( array(
54 'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
56 'prev_text' => __('«'),
57 'next_text' => __('»'),
58 'total' => ceil($theme_total / $per_page),
62 $themes = array_slice( $themes, $start, $per_page );
65 * Check if there is an update for a theme available.
67 * Will display link, if there is an update available.
71 * @param object $theme Theme data object.
72 * @return bool False if no valid info was passed.
74 function theme_update_available( $theme ) {
75 static $themes_update;
76 if ( !isset($themes_update) )
77 $themes_update = get_option('update_themes');
79 if ( is_object($theme) && isset($theme->stylesheet) )
80 $stylesheet = $theme->stylesheet;
81 elseif ( is_array($theme) && isset($theme['Stylesheet']) )
82 $stylesheet = $theme['Stylesheet'];
84 return false; //No valid info passed.
86 if ( isset($themes_update->response[ $stylesheet ]) ) {
87 $update = $themes_update->response[ $stylesheet ];
88 $details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
89 $update_url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
91 if ( ! current_user_can('update_themes') )
92 printf( __('<p>There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a>.</p>'), $ct->name, $details_url, $update['new_version']);
93 else if ( empty($update->package) )
94 printf( __('<p>There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> <em>automatic upgrade unavailable for this theme</em>.</p>'), $ct->name, $details_url, $update['new_version']);
96 printf( __('<p>There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> or <a href="%4$s">upgrade automatically</a>.</p>'), $ct->name, $details_url, $update['new_version'], $update_url );
103 <?php screen_icon(); ?>
104 <h2><?php echo wp_specialchars( $title ); ?></h2>
106 <h3><?php _e('Current Theme'); ?></h3>
107 <div id="current-theme">
108 <?php if ( $ct->screenshot ) : ?>
109 <img src="<?php echo WP_CONTENT_URL . $ct->stylesheet_dir . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
111 <h4><?php printf(_c('%1$s %2$s by %3$s|1: theme title, 2: theme version, 3: theme author'), $ct->title, $ct->version, $ct->author) ; ?></h4>
112 <p class="description"><?php echo $ct->description; ?></p>
113 <?php if ($ct->parent_theme) { ?>
114 <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, $ct->template_dir, $ct->stylesheet_dir, $ct->title, $ct->parent_theme); ?></p>
116 <p><?php printf(__('All of this theme’s files are located in <code>%2$s</code>.'), $ct->title, $ct->template_dir, $ct->stylesheet_dir); ?></p>
118 <?php if ( $ct->tags ) : ?>
119 <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
121 <?php theme_update_available($ct); ?>
124 <div class="clear"></div>
125 <h3><?php _e('Available Themes'); ?></h3>
126 <div class="clear"></div>
128 <?php if ( $page_links ) : ?>
129 <div class="tablenav">
130 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s',
131 number_format_i18n( $start + 1 ),
132 number_format_i18n( min( $page * $per_page, $theme_total ) ),
133 number_format_i18n( $theme_total ),
135 ); echo $page_links_text; ?></div>
139 <?php if ( 1 < $theme_total ) { ?>
140 <table id="availablethemes" cellspacing="0" cellpadding="0">
144 $theme_names = array_keys($themes);
145 natcasesort($theme_names);
147 $rows = ceil(count($theme_names) / 3);
148 for ( $row = 1; $row <= $rows; $row++ )
149 for ( $col = 1; $col <= 3; $col++ )
150 $table[$row][$col] = array_shift($theme_names);
152 foreach ( $table as $row => $cols ) {
156 foreach ( $cols as $col => $theme_name ) {
157 $class = array('available-theme');
158 if ( $row == 1 ) $class[] = 'top';
159 if ( $col == 1 ) $class[] = 'left';
160 if ( $row == $rows ) $class[] = 'bottom';
161 if ( $col == 3 ) $class[] = 'right';
163 <td class="<?php echo join(' ', $class); ?>">
164 <?php if ( !empty($theme_name) ) :
165 $template = $themes[$theme_name]['Template'];
166 $stylesheet = $themes[$theme_name]['Stylesheet'];
167 $title = $themes[$theme_name]['Title'];
168 $version = $themes[$theme_name]['Version'];
169 $description = $themes[$theme_name]['Description'];
170 $author = $themes[$theme_name]['Author'];
171 $screenshot = $themes[$theme_name]['Screenshot'];
172 $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
173 $preview_link = clean_url( get_option('home') . '/');
174 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true', 'width' => 600, 'height' => 400 ), $preview_link ) );
175 $preview_text = attribute_escape( sprintf( __('Preview of "%s"'), $title ) );
176 $tags = $themes[$theme_name]['Tags'];
177 $thickbox_class = 'thickbox';
178 $activate_link = wp_nonce_url("themes.php?action=activate&template=".urlencode($template)."&stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
179 $activate_text = attribute_escape( sprintf( __('Activate "%s"'), $title ) );
181 <a href="<?php echo $activate_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
182 <?php if ( $screenshot ) : ?>
183 <img src="<?php echo WP_CONTENT_URL . $stylesheet_dir . '/' . $screenshot; ?>" alt="" />
186 <h3><a class="<?php echo $thickbox_class; ?>" href="<?php echo $activate_link; ?>"><?php echo $title; ?></a></h3>
187 <p><?php echo $description; ?></p>
188 <?php if ( $tags ) : ?>
189 <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
191 <?php theme_update_available( $themes[$theme_name] ); ?>
192 <noscript><p class="themeactions"><a href="<?php echo $preview_link; ?>" title="<?php echo $preview_text; ?>"><?php _e('Preview'); ?></a> <a href="<?php echo $activate_link; ?>" title="<?php echo $activate_text; ?>"><?php _e('Activate'); ?></a></p></noscript>
193 <div style="display:none;"><a class="previewlink" href="<?php echo $preview_link; ?>"><?php echo $preview_text; ?></a> <a class="activatelink" href="<?php echo $activate_link; ?>"><?php echo $activate_text; ?></a></div>
194 <?php endif; // end if not empty theme_name ?>
196 <?php } // end foreach $cols ?>
198 <?php } // end foreach $table ?>
204 <?php if ( $page_links ) : ?>
205 <div class="tablenav">
206 <?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
214 // List broken themes, if any.
215 $broken_themes = get_broken_themes();
216 if ( count($broken_themes) ) {
219 <h2><?php _e('Broken Themes'); ?></h2>
220 <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
222 <table width="100%" cellpadding="3" cellspacing="3">
224 <th><?php _e('Name'); ?></th>
225 <th><?php _e('Description'); ?></th>
230 $theme_names = array_keys($broken_themes);
231 natcasesort($theme_names);
233 foreach ($theme_names as $theme_name) {
234 $title = $broken_themes[$theme_name]['Title'];
235 $description = $broken_themes[$theme_name]['Description'];
237 $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
241 <td>$description</td>
250 <h2><?php _e('Get More Themes'); ?></h2>
251 <p><?php _e('You can find additional themes for your site in the <a href="http://wordpress.org/extend/themes/">WordPress theme directory</a>. To install a theme you generally just need to upload the theme folder into your <code>wp-content/themes</code> directory. Once a theme is uploaded, you should see it on this page.'); ?></p>
255 <?php require('admin-footer.php'); ?>