1 <?php |
1 <?php |
2 /** |
2 /** |
3 * Themes List Table class. |
3 * List Table API: WP_Themes_List_Table class |
4 * |
4 * |
5 * @package WordPress |
5 * @package WordPress |
6 * @subpackage List_Table |
6 * @subpackage Administration |
|
7 * @since 3.1.0 |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Core class used to implement displaying installed themes in a list table. |
|
12 * |
7 * @since 3.1.0 |
13 * @since 3.1.0 |
8 * @access private |
14 * @access private |
|
15 * |
|
16 * @see WP_List_Table |
9 */ |
17 */ |
10 class WP_Themes_List_Table extends WP_List_Table { |
18 class WP_Themes_List_Table extends WP_List_Table { |
11 |
19 |
12 protected $search_terms = array(); |
20 protected $search_terms = array(); |
13 public $features = array(); |
21 public $features = array(); |
14 |
22 |
15 /** |
23 /** |
16 * Constructor. |
24 * Constructor. |
17 * |
25 * |
18 * @since 3.1.0 |
26 * @since 3.1.0 |
19 * @access public |
|
20 * |
27 * |
21 * @see WP_List_Table::__construct() for more information on default arguments. |
28 * @see WP_List_Table::__construct() for more information on default arguments. |
22 * |
29 * |
23 * @param array $args An associative array of arguments. |
30 * @param array $args An associative array of arguments. |
24 */ |
31 */ |
27 'ajax' => true, |
34 'ajax' => true, |
28 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
35 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
29 ) ); |
36 ) ); |
30 } |
37 } |
31 |
38 |
|
39 /** |
|
40 * |
|
41 * @return bool |
|
42 */ |
32 public function ajax_user_can() { |
43 public function ajax_user_can() { |
33 // Do not check edit_theme_options here. AJAX calls for available themes require switch_themes. |
44 // Do not check edit_theme_options here. Ajax calls for available themes require switch_themes. |
34 return current_user_can( 'switch_themes' ); |
45 return current_user_can( 'switch_themes' ); |
35 } |
46 } |
36 |
47 |
|
48 /** |
|
49 */ |
37 public function prepare_items() { |
50 public function prepare_items() { |
38 $themes = wp_get_themes( array( 'allowed' => true ) ); |
51 $themes = wp_get_themes( array( 'allowed' => true ) ); |
39 |
52 |
40 if ( ! empty( $_REQUEST['s'] ) ) |
53 if ( ! empty( $_REQUEST['s'] ) ) |
41 $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) ); |
54 $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) ); |
65 'per_page' => $per_page, |
78 'per_page' => $per_page, |
66 'infinite_scroll' => true, |
79 'infinite_scroll' => true, |
67 ) ); |
80 ) ); |
68 } |
81 } |
69 |
82 |
|
83 /** |
|
84 */ |
70 public function no_items() { |
85 public function no_items() { |
71 if ( $this->search_terms || $this->features ) { |
86 if ( $this->search_terms || $this->features ) { |
72 _e( 'No items found.' ); |
87 _e( 'No items found.' ); |
73 return; |
88 return; |
74 } |
89 } |
75 |
90 |
|
91 $blog_id = get_current_blog_id(); |
76 if ( is_multisite() ) { |
92 if ( is_multisite() ) { |
77 if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) { |
93 if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) { |
78 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' ) ); |
94 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=' . $blog_id ), network_admin_url( 'theme-install.php' ) ); |
79 |
95 |
80 return; |
96 return; |
81 } elseif ( current_user_can( 'manage_network_themes' ) ) { |
97 } elseif ( current_user_can( 'manage_network_themes' ) ) { |
82 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'] ) ); |
98 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=' . $blog_id ) ); |
83 |
99 |
84 return; |
100 return; |
85 } |
101 } |
86 // Else, fallthrough. install_themes doesn't help if you can't enable it. |
102 // Else, fallthrough. install_themes doesn't help if you can't enable it. |
87 } else { |
103 } else { |
88 if ( current_user_can( 'install_themes' ) ) { |
104 if ( current_user_can( 'install_themes' ) ) { |
89 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' ) ); |
105 printf( __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress Theme Directory at any time: just click on the <a href="%s">Install Themes</a> tab above.' ), admin_url( 'theme-install.php' ) ); |
90 |
106 |
91 return; |
107 return; |
92 } |
108 } |
93 } |
109 } |
94 // Fallthrough. |
110 // Fallthrough. |
95 printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) ); |
111 printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) ); |
96 } |
112 } |
97 |
113 |
98 /** |
114 /** |
99 * @param string $which |
115 * @param string $which |
100 * @return null |
|
101 */ |
116 */ |
102 public function tablenav( $which = 'top' ) { |
117 public function tablenav( $which = 'top' ) { |
103 if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) |
118 if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) |
104 return; |
119 return; |
105 ?> |
120 ?> |
122 |
139 |
123 <?php $this->tablenav( 'bottom' ); ?> |
140 <?php $this->tablenav( 'bottom' ); ?> |
124 <?php |
141 <?php |
125 } |
142 } |
126 |
143 |
|
144 /** |
|
145 * |
|
146 * @return array |
|
147 */ |
127 public function get_columns() { |
148 public function get_columns() { |
128 return array(); |
149 return array(); |
129 } |
150 } |
130 |
151 |
|
152 /** |
|
153 */ |
131 public function display_rows_or_placeholder() { |
154 public function display_rows_or_placeholder() { |
132 if ( $this->has_items() ) { |
155 if ( $this->has_items() ) { |
133 $this->display_rows(); |
156 $this->display_rows(); |
134 } else { |
157 } else { |
135 echo '<div class="no-items">'; |
158 echo '<div class="no-items">'; |
136 $this->no_items(); |
159 $this->no_items(); |
137 echo '</div>'; |
160 echo '</div>'; |
138 } |
161 } |
139 } |
162 } |
140 |
163 |
|
164 /** |
|
165 */ |
141 public function display_rows() { |
166 public function display_rows() { |
142 $themes = $this->items; |
167 $themes = $this->items; |
143 |
168 |
144 foreach ( $themes as $theme ): |
169 foreach ( $themes as $theme ): |
145 ?><div class="available-theme"><?php |
170 ?><div class="available-theme"><?php |
150 $version = $theme->display('Version'); |
175 $version = $theme->display('Version'); |
151 $author = $theme->display('Author'); |
176 $author = $theme->display('Author'); |
152 |
177 |
153 $activate_link = wp_nonce_url( "themes.php?action=activate&template=" . urlencode( $template ) . "&stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet ); |
178 $activate_link = wp_nonce_url( "themes.php?action=activate&template=" . urlencode( $template ) . "&stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet ); |
154 |
179 |
155 $preview_link = esc_url( add_query_arg( |
|
156 array( 'preview' => 1, 'template' => urlencode( $template ), 'stylesheet' => urlencode( $stylesheet ), 'preview_iframe' => true, 'TB_iframe' => 'true' ), |
|
157 home_url( '/' ) ) ); |
|
158 |
|
159 $actions = array(); |
180 $actions = array(); |
160 $actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' |
181 $actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' |
161 . esc_attr( sprintf( __( 'Activate “%s”' ), $title ) ) . '">' . __( 'Activate' ) . '</a>'; |
182 . esc_attr( sprintf( __( 'Activate “%s”' ), $title ) ) . '">' . __( 'Activate' ) . '</a>'; |
162 |
|
163 $actions['preview'] = '<a href="' . $preview_link . '" class="hide-if-customize" title="' |
|
164 . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '">' . __( 'Preview' ) . '</a>'; |
|
165 |
183 |
166 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
184 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
167 $actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="load-customize hide-if-no-customize">' |
185 $actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="load-customize hide-if-no-customize">' |
168 . __( 'Live Preview' ) . '</a>'; |
186 . __( 'Live Preview' ) . '</a>'; |
169 } |
187 } |
172 $actions['delete'] = '<a class="submitdelete deletion" href="' . wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ) |
190 $actions['delete'] = '<a class="submitdelete deletion" href="' . wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ) |
173 . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ) |
191 . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ) |
174 . "' );" . '">' . __( 'Delete' ) . '</a>'; |
192 . "' );" . '">' . __( 'Delete' ) . '</a>'; |
175 |
193 |
176 /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ |
194 /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ |
177 $actions = apply_filters( 'theme_action_links', $actions, $theme ); |
195 $actions = apply_filters( 'theme_action_links', $actions, $theme, 'all' ); |
178 |
196 |
179 /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ |
197 /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ |
180 $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme ); |
198 $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, 'all' ); |
181 $delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : ''; |
199 $delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : ''; |
182 unset( $actions['delete'] ); |
200 unset( $actions['delete'] ); |
183 |
201 |
184 ?> |
202 ?> |
185 |
203 |
186 <a href="<?php echo $preview_link; ?>" class="screenshot hide-if-customize"> |
204 <span class="screenshot hide-if-customize"> |
187 <?php if ( $screenshot = $theme->get_screenshot() ) : ?> |
205 <?php if ( $screenshot = $theme->get_screenshot() ) : ?> |
188 <img src="<?php echo esc_url( $screenshot ); ?>" alt="" /> |
206 <img src="<?php echo esc_url( $screenshot ); ?>" alt="" /> |
189 <?php endif; ?> |
207 <?php endif; ?> |
190 </a> |
208 </span> |
191 <a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize"> |
209 <a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize"> |
192 <?php if ( $screenshot = $theme->get_screenshot() ) : ?> |
210 <?php if ( $screenshot = $theme->get_screenshot() ) : ?> |
193 <img src="<?php echo esc_url( $screenshot ); ?>" alt="" /> |
211 <img src="<?php echo esc_url( $screenshot ); ?>" alt="" /> |
194 <?php endif; ?> |
212 <?php endif; ?> |
195 </a> |
213 </a> |