3 * Themes List Table class.
6 * @subpackage List_Table
10 class WP_Themes_List_Table extends WP_List_Table {
12 protected $search_terms = array();
13 var $features = array();
15 function __construct() {
16 parent::__construct( array(
21 function ajax_user_can() {
22 // Do not check edit_theme_options here. AJAX calls for available themes require switch_themes.
23 return current_user_can( 'switch_themes' );
26 function prepare_items() {
27 $themes = wp_get_themes( array( 'allowed' => true ) );
29 if ( ! empty( $_REQUEST['s'] ) )
30 $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( stripslashes( $_REQUEST['s'] ) ) ) ) ) );
32 if ( ! empty( $_REQUEST['features'] ) )
33 $this->features = $_REQUEST['features'];
35 if ( $this->search_terms || $this->features ) {
36 foreach ( $themes as $key => $theme ) {
37 if ( ! $this->search_theme( $theme ) )
38 unset( $themes[ $key ] );
42 unset( $themes[ get_option( 'stylesheet' ) ] );
43 WP_Theme::sort_by_name( $themes );
46 $page = $this->get_pagenum();
48 $start = ( $page - 1 ) * $per_page;
50 $this->items = array_slice( $themes, $start, $per_page, true );
52 $this->set_pagination_args( array(
53 'total_items' => count( $themes ),
54 'per_page' => $per_page,
55 'infinite_scroll' => true,
60 if ( $this->search_terms || $this->features ) {
61 _e( 'No items found.' );
65 if ( is_multisite() ) {
66 if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) {
67 printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ), network_admin_url( 'theme-install.php' ) );
70 } elseif ( current_user_can( 'manage_network_themes' ) ) {
71 printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ) );
75 // else, fallthrough. install_themes doesn't help if you can't enable it.
77 if ( current_user_can( 'install_themes' ) ) {
78 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 <a href="%s">Install Themes</a> tab above.' ), admin_url( 'theme-install.php' ) );
84 printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) );
87 function tablenav( $which = 'top' ) {
88 if ( $this->get_pagination_arg( 'total_pages' ) <= 1 )
91 <div class="tablenav themes <?php echo $which; ?>">
92 <?php $this->pagination( $which ); ?>
93 <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
100 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
102 <?php $this->tablenav( 'top' ); ?>
104 <div id="availablethemes">
105 <?php $this->display_rows_or_placeholder(); ?>
108 <?php $this->tablenav( 'bottom' ); ?>
112 function get_columns() {
116 function display_rows() {
117 $themes = $this->items;
119 foreach ( $themes as $theme ):
120 ?><div class="available-theme"><?php
122 $template = $theme->get_template();
123 $stylesheet = $theme->get_stylesheet();
124 $title = $theme->display('Name');
125 $version = $theme->display('Version');
126 $author = $theme->display('Author');
128 $activate_link = wp_nonce_url( "themes.php?action=activate&template=" . urlencode( $template ) . "&stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet );
130 $preview_link = esc_url( add_query_arg(
131 array( 'preview' => 1, 'template' => urlencode( $template ), 'stylesheet' => urlencode( $stylesheet ), 'preview_iframe' => true, 'TB_iframe' => 'true' ),
135 $actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="'
136 . esc_attr( sprintf( __( 'Activate “%s”' ), $title ) ) . '">' . __( 'Activate' ) . '</a>';
138 $actions['preview'] = '<a href="' . $preview_link . '" class="hide-if-customize" title="'
139 . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '">' . __( 'Preview' ) . '</a>';
141 if ( current_user_can( 'edit_theme_options' ) )
142 $actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="load-customize hide-if-no-customize">'
143 . __( 'Live Preview' ) . '</a>';
145 if ( ! is_multisite() && current_user_can( 'delete_themes' ) )
146 $actions['delete'] = '<a class="submitdelete deletion" href="' . wp_nonce_url( "themes.php?action=delete&stylesheet=$stylesheet", 'delete-theme_' . $stylesheet )
147 . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) )
148 . "' );" . '">' . __( 'Delete' ) . '</a>';
150 $actions = apply_filters( 'theme_action_links', $actions, $theme );
151 $delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : '';
152 unset( $actions['delete'] );
156 <a href="<?php echo $preview_link; ?>" class="screenshot hide-if-customize">
157 <?php if ( $screenshot = $theme->get_screenshot() ) : ?>
158 <img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
161 <a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize">
162 <?php if ( $screenshot = $theme->get_screenshot() ) : ?>
163 <img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
167 <h3><?php echo $title; ?></h3>
168 <div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div>
169 <div class="action-links">
171 <?php foreach ( $actions as $action ): ?>
172 <li><?php echo $action; ?></li>
174 <li class="hide-if-no-js"><a href="#" class="theme-detail" tabindex='4'><?php _e('Details') ?></a></li>
176 <?php echo $delete_action; ?>
178 <?php theme_update_available( $theme ); ?>
181 <div class="themedetaildiv hide-if-js">
182 <p><strong><?php _e('Version: '); ?></strong><?php echo $version; ?></p>
183 <p><?php echo $theme->display('Description'); ?></p>
184 <?php if ( current_user_can( 'edit_themes' ) && $theme->parent() ) :
185 /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
186 <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.' ),
187 $title, str_replace( WP_CONTENT_DIR, '', $theme->get_template_directory() ), str_replace( WP_CONTENT_DIR, '', $theme->get_stylesheet_directory() ), $title, $theme->parent()->display('Name') ); ?></p>
189 /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir */ ?>
190 <p><?php printf( __( 'All of this theme’s files are located in <code>%2$s</code>.' ),
191 $title, str_replace( WP_CONTENT_DIR, '', $theme->get_template_directory() ), str_replace( WP_CONTENT_DIR, '', $theme->get_stylesheet_directory() ) ); ?></p>
200 function search_theme( $theme ) {
201 // Search the features
202 foreach ( $this->features as $word ) {
203 if ( ! in_array( $word, $theme->get('Tags') ) )
208 foreach ( $this->search_terms as $word ) {
209 if ( in_array( $word, $theme->get('Tags') ) )
212 foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) {
213 // Don't mark up; Do translate.
214 if ( false !== stripos( $theme->display( $header, false, true ), $word ) )
218 if ( false !== stripos( $theme->get_stylesheet(), $word ) )
221 if ( false !== stripos( $theme->get_template(), $word ) )
231 * Send required variables to JavaScript land
236 * @uses $this->features Array of all feature search terms.
237 * @uses get_pagenum()
238 * @uses _pagination_args['total_pages']
240 function _js_vars( $extra_args = array() ) {
241 $search_string = isset( $_REQUEST['s'] ) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '';
244 'search' => $search_string,
245 'features' => $this->features,
246 'paged' => $this->get_pagenum(),
247 'total_pages' => ! empty( $this->_pagination_args['total_pages'] ) ? $this->_pagination_args['total_pages'] : 1,
250 if ( is_array( $extra_args ) )
251 $args = array_merge( $args, $extra_args );
253 printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", json_encode( $args ) );