[44] | 1 | <?php
|
---|
| 2 | /**
|
---|
| 3 | * Themes administration panel.
|
---|
| 4 | *
|
---|
| 5 | * @package WordPress
|
---|
| 6 | * @subpackage Administration
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | /** WordPress Administration Bootstrap */
|
---|
| 10 | require_once('admin.php');
|
---|
| 11 |
|
---|
| 12 | if ( isset($_GET['action']) ) {
|
---|
| 13 | if ( 'activate' == $_GET['action'] ) {
|
---|
| 14 | check_admin_referer('switch-theme_' . $_GET['template']);
|
---|
| 15 | switch_theme($_GET['template'], $_GET['stylesheet']);
|
---|
| 16 | wp_redirect('themes.php?activated=true');
|
---|
| 17 | exit;
|
---|
| 18 | } else if ( 'delete' == $_GET['action'] ) {
|
---|
| 19 | check_admin_referer('delete-theme_' . $_GET['template']);
|
---|
| 20 | if ( !current_user_can('update_themes') )
|
---|
| 21 | wp_die( __( 'Cheatin’ uh?' ) );
|
---|
| 22 | delete_theme($_GET['template']);
|
---|
| 23 | wp_redirect('themes.php?deleted=true');
|
---|
| 24 | exit;
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | $title = __('Manage Themes');
|
---|
| 29 | $parent_file = 'themes.php';
|
---|
| 30 |
|
---|
| 31 | $help = '<p>' . __('Themes give your WordPress style. Once a theme is installed, you may preview it, activate it or deactivate it here.') . '</p>';
|
---|
| 32 | if ( current_user_can('install_themes') ) {
|
---|
| 33 | $help .= '<p>' . sprintf(__('You can find additional themes for your site by using the new <a href="%1$s">Theme Browser/Installer</a> functionality or by browsing the <a href="http://wordpress.org/extend/themes/">WordPress Theme Directory</a> directly and installing manually. To install a theme <em>manually</em>, <a href="%2$s">upload its ZIP archive with the new uploader</a> or copy its folder via FTP into your <code>wp-content/themes</code> directory.'), 'theme-install.php', 'theme-install.php?tab=upload' ) . '</p>';
|
---|
| 34 | $help .= '<p>' . __('Once a theme is uploaded, you should see it on this page.') . '</p>' ;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | add_contextual_help('themes', $help);
|
---|
| 38 |
|
---|
| 39 | add_thickbox();
|
---|
| 40 | wp_enqueue_script( 'theme-preview' );
|
---|
| 41 |
|
---|
| 42 | require_once('admin-header.php');
|
---|
| 43 | ?>
|
---|
| 44 |
|
---|
| 45 | <?php if ( ! validate_current_theme() ) : ?>
|
---|
| 46 | <div id="message1" class="updated fade"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
|
---|
| 47 | <?php elseif ( isset($_GET['activated']) ) :
|
---|
| 48 | if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) ) { ?>
|
---|
| 49 | <div id="message2" class="updated fade"><p><?php printf(__('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings page</a> to configure them.'), admin_url('widgets.php') ); ?></p></div><?php
|
---|
| 50 | } else { ?>
|
---|
| 51 | <div id="message2" class="updated fade"><p><?php printf(__('New theme activated. <a href="%s">Visit site</a>'), get_bloginfo('url') . '/'); ?></p></div><?php
|
---|
| 52 | }
|
---|
| 53 | elseif ( isset($_GET['deleted']) ) : ?>
|
---|
| 54 | <div id="message3" class="updated fade"><p><?php _e('Theme deleted.') ?></p></div>
|
---|
| 55 | <?php endif; ?>
|
---|
| 56 |
|
---|
| 57 | <?php
|
---|
| 58 | $themes = get_themes();
|
---|
| 59 | $ct = current_theme_info();
|
---|
| 60 | unset($themes[$ct->name]);
|
---|
| 61 |
|
---|
| 62 | uksort( $themes, "strnatcasecmp" );
|
---|
| 63 | $theme_total = count( $themes );
|
---|
| 64 | $per_page = 15;
|
---|
| 65 |
|
---|
| 66 | if ( isset( $_GET['pagenum'] ) )
|
---|
| 67 | $page = absint( $_GET['pagenum'] );
|
---|
| 68 |
|
---|
| 69 | if ( empty($page) )
|
---|
| 70 | $page = 1;
|
---|
| 71 |
|
---|
| 72 | $start = $offset = ( $page - 1 ) * $per_page;
|
---|
| 73 |
|
---|
| 74 | $page_links = paginate_links( array(
|
---|
| 75 | 'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
|
---|
| 76 | 'format' => '',
|
---|
| 77 | 'prev_text' => __('«'),
|
---|
| 78 | 'next_text' => __('»'),
|
---|
| 79 | 'total' => ceil($theme_total / $per_page),
|
---|
| 80 | 'current' => $page
|
---|
| 81 | ));
|
---|
| 82 |
|
---|
| 83 | $themes = array_slice( $themes, $start, $per_page );
|
---|
| 84 |
|
---|
| 85 | /**
|
---|
| 86 | * Check if there is an update for a theme available.
|
---|
| 87 | *
|
---|
| 88 | * Will display link, if there is an update available.
|
---|
| 89 | *
|
---|
| 90 | * @since 2.7.0
|
---|
| 91 | *
|
---|
| 92 | * @param object $theme Theme data object.
|
---|
| 93 | * @return bool False if no valid info was passed.
|
---|
| 94 | */
|
---|
| 95 | function theme_update_available( $theme ) {
|
---|
| 96 | static $themes_update;
|
---|
| 97 | if ( !isset($themes_update) )
|
---|
| 98 | $themes_update = get_transient('update_themes');
|
---|
| 99 |
|
---|
| 100 | if ( is_object($theme) && isset($theme->stylesheet) )
|
---|
| 101 | $stylesheet = $theme->stylesheet;
|
---|
| 102 | elseif ( is_array($theme) && isset($theme['Stylesheet']) )
|
---|
| 103 | $stylesheet = $theme['Stylesheet'];
|
---|
| 104 | else
|
---|
| 105 | return false; //No valid info passed.
|
---|
| 106 |
|
---|
| 107 | if ( isset($themes_update->response[ $stylesheet ]) ) {
|
---|
| 108 | $update = $themes_update->response[ $stylesheet ];
|
---|
| 109 | $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
|
---|
| 110 | $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.
|
---|
| 111 | $update_url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
|
---|
| 112 | $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Upgrading this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to upgrade.") ) . '\') ) {return true;}return false;"';
|
---|
| 113 |
|
---|
| 114 | if ( ! current_user_can('update_themes') )
|
---|
| 115 | printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
|
---|
| 116 | else if ( empty($update->package) )
|
---|
| 117 | printf( '<p><strong>' . __('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>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
|
---|
| 118 | else
|
---|
| 119 | printf( '<p><strong>' . __('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" %5$s >upgrade automatically</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | ?>
|
---|
| 124 |
|
---|
| 125 | <div class="wrap">
|
---|
| 126 | <?php screen_icon(); ?>
|
---|
| 127 | <h2><?php echo esc_html( $title ); ?></h2>
|
---|
| 128 |
|
---|
| 129 | <h3><?php _e('Current Theme'); ?></h3>
|
---|
| 130 | <div id="current-theme">
|
---|
| 131 | <?php if ( $ct->screenshot ) : ?>
|
---|
| 132 | <img src="<?php echo content_url($ct->stylesheet_dir . '/' . $ct->screenshot); ?>" alt="<?php _e('Current theme preview'); ?>" />
|
---|
| 133 | <?php endif; ?>
|
---|
| 134 | <h4><?php
|
---|
| 135 | /* translators: 1: theme title, 2: theme version, 3: theme author */
|
---|
| 136 | printf(__('%1$s %2$s by %3$s'), $ct->title, $ct->version, $ct->author) ; ?></h4>
|
---|
| 137 | <p class="theme-description"><?php echo $ct->description; ?></p>
|
---|
| 138 | <?php if ($ct->parent_theme) { ?>
|
---|
| 139 | <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>
|
---|
| 140 | <?php } else { ?>
|
---|
| 141 | <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>
|
---|
| 142 | <?php } ?>
|
---|
| 143 | <?php if ( $ct->tags ) : ?>
|
---|
| 144 | <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
|
---|
| 145 | <?php endif; ?>
|
---|
| 146 | <?php theme_update_available($ct); ?>
|
---|
| 147 |
|
---|
| 148 | </div>
|
---|
| 149 |
|
---|
| 150 | <div class="clear"></div>
|
---|
| 151 | <h3><?php _e('Available Themes'); ?></h3>
|
---|
| 152 | <div class="clear"></div>
|
---|
| 153 |
|
---|
| 154 | <?php if ( $theme_total ) { ?>
|
---|
| 155 |
|
---|
| 156 | <?php if ( $page_links ) : ?>
|
---|
| 157 | <div class="tablenav">
|
---|
| 158 | <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s',
|
---|
| 159 | number_format_i18n( $start + 1 ),
|
---|
| 160 | number_format_i18n( min( $page * $per_page, $theme_total ) ),
|
---|
| 161 | number_format_i18n( $theme_total ),
|
---|
| 162 | $page_links
|
---|
| 163 | ); echo $page_links_text; ?></div>
|
---|
| 164 | </div>
|
---|
| 165 | <?php endif; ?>
|
---|
| 166 |
|
---|
| 167 | <table id="availablethemes" cellspacing="0" cellpadding="0">
|
---|
| 168 | <?php
|
---|
| 169 | $style = '';
|
---|
| 170 |
|
---|
| 171 | $theme_names = array_keys($themes);
|
---|
| 172 | natcasesort($theme_names);
|
---|
| 173 |
|
---|
| 174 | $table = array();
|
---|
| 175 | $rows = ceil(count($theme_names) / 3);
|
---|
| 176 | for ( $row = 1; $row <= $rows; $row++ )
|
---|
| 177 | for ( $col = 1; $col <= 3; $col++ )
|
---|
| 178 | $table[$row][$col] = array_shift($theme_names);
|
---|
| 179 |
|
---|
| 180 | foreach ( $table as $row => $cols ) {
|
---|
| 181 | ?>
|
---|
| 182 | <tr>
|
---|
| 183 | <?php
|
---|
| 184 | foreach ( $cols as $col => $theme_name ) {
|
---|
| 185 | $class = array('available-theme');
|
---|
| 186 | if ( $row == 1 ) $class[] = 'top';
|
---|
| 187 | if ( $col == 1 ) $class[] = 'left';
|
---|
| 188 | if ( $row == $rows ) $class[] = 'bottom';
|
---|
| 189 | if ( $col == 3 ) $class[] = 'right';
|
---|
| 190 | ?>
|
---|
| 191 | <td class="<?php echo join(' ', $class); ?>">
|
---|
| 192 | <?php if ( !empty($theme_name) ) :
|
---|
| 193 | $template = $themes[$theme_name]['Template'];
|
---|
| 194 | $stylesheet = $themes[$theme_name]['Stylesheet'];
|
---|
| 195 | $title = $themes[$theme_name]['Title'];
|
---|
| 196 | $version = $themes[$theme_name]['Version'];
|
---|
| 197 | $description = $themes[$theme_name]['Description'];
|
---|
| 198 | $author = $themes[$theme_name]['Author'];
|
---|
| 199 | $screenshot = $themes[$theme_name]['Screenshot'];
|
---|
| 200 | $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
|
---|
| 201 | $template_dir = $themes[$theme_name]['Template Dir'];
|
---|
| 202 | $parent_theme = $themes[$theme_name]['Parent Theme'];
|
---|
| 203 | $preview_link = esc_url(get_option('home') . '/');
|
---|
| 204 | if ( is_ssl() )
|
---|
| 205 | $preview_link = str_replace( 'http://', 'https://', $preview_link );
|
---|
| 206 | $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
|
---|
| 207 | $preview_text = esc_attr( sprintf( __('Preview of “%s”'), $title ) );
|
---|
| 208 | $tags = $themes[$theme_name]['Tags'];
|
---|
| 209 | $thickbox_class = 'thickbox thickbox-preview';
|
---|
| 210 | $activate_link = wp_nonce_url("themes.php?action=activate&template=".urlencode($template)."&stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
|
---|
| 211 | $activate_text = esc_attr( sprintf( __('Activate “%s”'), $title ) );
|
---|
| 212 | $actions = array();
|
---|
| 213 | $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="' . $activate_text . '">' . __('Activate') . '</a>';
|
---|
| 214 | $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $theme_name)) . '">' . __('Preview') . '</a>';
|
---|
| 215 | if ( current_user_can('update_themes') )
|
---|
| 216 | $actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url("themes.php?action=delete&template=$stylesheet", 'delete-theme_' . $stylesheet) . '" onclick="' . "if ( confirm('" . esc_js(sprintf( __("You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete."), $theme_name )) . "') ) {return true;}return false;" . '">' . __('Delete') . '</a>';
|
---|
| 217 | $actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);
|
---|
| 218 |
|
---|
| 219 | $actions = implode ( ' | ', $actions );
|
---|
| 220 | ?>
|
---|
| 221 | <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
|
---|
| 222 | <?php if ( $screenshot ) : ?>
|
---|
| 223 | <img src="<?php echo content_url($stylesheet_dir . '/' . $screenshot); ?>" alt="" />
|
---|
| 224 | <?php endif; ?>
|
---|
| 225 | </a>
|
---|
| 226 | <h3><?php
|
---|
| 227 | /* translators: 1: theme title, 2: theme version, 3: theme author */
|
---|
| 228 | printf(__('%1$s %2$s by %3$s'), $title, $version, $author) ; ?></h3>
|
---|
| 229 | <p class="description"><?php echo $description; ?></p>
|
---|
| 230 | <span class='action-links'><?php echo $actions ?></span>
|
---|
| 231 | <?php if ($parent_theme) {
|
---|
| 232 | /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
|
---|
| 233 | <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, $template_dir, $stylesheet_dir, $title, $parent_theme); ?></p>
|
---|
| 234 | <?php } else { ?>
|
---|
| 235 | <p><?php printf(__('All of this theme’s files are located in <code>%2$s</code>.'), $title, $template_dir, $stylesheet_dir); ?></p>
|
---|
| 236 | <?php } ?>
|
---|
| 237 | <?php if ( $tags ) : ?>
|
---|
| 238 | <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
|
---|
| 239 | <?php endif; ?>
|
---|
| 240 | <?php theme_update_available( $themes[$theme_name] ); ?>
|
---|
| 241 | <?php endif; // end if not empty theme_name ?>
|
---|
| 242 | </td>
|
---|
| 243 | <?php } // end foreach $cols ?>
|
---|
| 244 | </tr>
|
---|
| 245 | <?php } // end foreach $table ?>
|
---|
| 246 | </table>
|
---|
| 247 | <?php } else { ?>
|
---|
| 248 | <p><?php _e('You only have one theme installed at the moment so there is nothing to show you here. Maybe you should download some more to try out.'); ?></p>
|
---|
| 249 | <?php } // end if $theme_total?>
|
---|
| 250 | <br class="clear" />
|
---|
| 251 |
|
---|
| 252 | <?php if ( $page_links ) : ?>
|
---|
| 253 | <div class="tablenav">
|
---|
| 254 | <?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
|
---|
| 255 | <br class="clear" />
|
---|
| 256 | </div>
|
---|
| 257 | <?php endif; ?>
|
---|
| 258 |
|
---|
| 259 | <br class="clear" />
|
---|
| 260 |
|
---|
| 261 | <?php
|
---|
| 262 | // List broken themes, if any.
|
---|
| 263 | $broken_themes = get_broken_themes();
|
---|
| 264 | if ( count($broken_themes) ) {
|
---|
| 265 | ?>
|
---|
| 266 |
|
---|
| 267 | <h2><?php _e('Broken Themes'); ?></h2>
|
---|
| 268 | <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
|
---|
| 269 |
|
---|
| 270 | <table width="100%" cellpadding="3" cellspacing="3">
|
---|
| 271 | <tr>
|
---|
| 272 | <th><?php _e('Name'); ?></th>
|
---|
| 273 | <th><?php _e('Description'); ?></th>
|
---|
| 274 | </tr>
|
---|
| 275 | <?php
|
---|
| 276 | $theme = '';
|
---|
| 277 |
|
---|
| 278 | $theme_names = array_keys($broken_themes);
|
---|
| 279 | natcasesort($theme_names);
|
---|
| 280 |
|
---|
| 281 | foreach ($theme_names as $theme_name) {
|
---|
| 282 | $title = $broken_themes[$theme_name]['Title'];
|
---|
| 283 | $description = $broken_themes[$theme_name]['Description'];
|
---|
| 284 |
|
---|
| 285 | $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
|
---|
| 286 | echo "
|
---|
| 287 | <tr $theme>
|
---|
| 288 | <td>$title</td>
|
---|
| 289 | <td>$description</td>
|
---|
| 290 | </tr>";
|
---|
| 291 | }
|
---|
| 292 | ?>
|
---|
| 293 | </table>
|
---|
| 294 | <?php
|
---|
| 295 | }
|
---|
| 296 | ?>
|
---|
| 297 | </div>
|
---|
| 298 |
|
---|
| 299 | <?php require('admin-footer.php'); ?>
|
---|