3 * Plugin Installer List Table class.
6 * @subpackage List_Table
10 class WP_Plugin_Install_List_Table extends WP_List_Table {
12 function ajax_user_can() {
13 return current_user_can('install_plugins');
16 function prepare_items() {
17 include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
19 global $tabs, $tab, $paged, $type, $term;
21 wp_reset_vars( array( 'tab' ) );
23 $paged = $this->get_pagenum();
27 // These are the tabs which are shown on the page
29 $tabs['dashboard'] = __( 'Search' );
30 if ( 'search' == $tab )
31 $tabs['search'] = __( 'Search Results' );
32 $tabs['upload'] = __( 'Upload' );
33 $tabs['featured'] = _x( 'Featured', 'Plugin Installer' );
34 $tabs['popular'] = _x( 'Popular', 'Plugin Installer' );
35 $tabs['new'] = _x( 'Newest', 'Plugin Installer' );
36 $tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' );
38 $nonmenu_tabs = array( 'plugin-information' ); //Valid actions to perform which do not have a Menu item.
40 $tabs = apply_filters( 'install_plugins_tabs', $tabs );
41 $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
43 // If a non-valid menu tab has been selected, And it's not a non-menu action.
44 if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
47 $args = array( 'page' => $paged, 'per_page' => $per_page );
51 $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
52 $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
56 $args['tag'] = sanitize_title_with_dashes( $term );
59 $args['search'] = $term;
62 $args['author'] = $term;
66 add_action( 'install_plugins_table_header', 'install_search_form', 10, 0 );
72 $args['browse'] = $tab;
76 $user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
77 update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
79 $args['user'] = $user;
83 add_action( 'install_plugins_favorites', 'install_plugins_favorites_form', 9, 0 );
93 $api = plugins_api( 'query_plugins', $args );
95 if ( is_wp_error( $api ) )
96 wp_die( $api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
98 $this->items = $api->plugins;
100 $this->set_pagination_args( array(
101 'total_items' => $api->info['results'],
102 'per_page' => $per_page,
106 function no_items() {
107 _e( 'No plugins match your request.' );
110 function get_views() {
113 $display_tabs = array();
114 foreach ( (array) $tabs as $action => $text ) {
115 $class = ( $action == $tab ) ? ' class="current"' : '';
116 $href = self_admin_url('plugin-install.php?tab=' . $action);
117 $display_tabs['plugin-install-'.$action] = "<a href='$href'$class>$text</a>";
120 return $display_tabs;
123 function display_tablenav( $which ) {
124 if ( 'top' == $which ) { ?>
125 <div class="tablenav top">
126 <div class="alignleft actions">
127 <?php do_action( 'install_plugins_table_header' ); ?>
129 <?php $this->pagination( $which ); ?>
133 <div class="tablenav bottom">
134 <?php $this->pagination( $which ); ?>
141 function get_table_classes() {
142 extract( $this->_args );
144 return array( 'widefat', $plural );
147 function get_columns() {
149 'name' => _x( 'Name', 'plugin name' ),
150 'version' => __( 'Version' ),
151 'rating' => __( 'Rating' ),
152 'description' => __( 'Description' ),
156 function display_rows() {
157 $plugins_allowedtags = array(
158 'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
159 'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
160 'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
161 'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
164 list( $columns, $hidden ) = $this->get_column_info();
167 foreach ( $columns as $column_name => $column_display_name ) {
168 $style[ $column_name ] = in_array( $column_name, $hidden ) ? 'style="display:none;"' : '';
171 foreach ( (array) $this->items as $plugin ) {
172 if ( is_object( $plugin ) )
173 $plugin = (array) $plugin;
175 $title = wp_kses( $plugin['name'], $plugins_allowedtags );
176 //Limit description to 400char, and remove any HTML.
177 $description = strip_tags( $plugin['description'] );
178 if ( strlen( $description ) > 400 )
179 $description = mb_substr( $description, 0, 400 ) . '…';
180 //remove any trailing entities
181 $description = preg_replace( '/&[^;\s]{0,6}$/', '', $description );
182 //strip leading/trailing & multiple consecutive lines
183 $description = trim( $description );
184 $description = preg_replace( "|(\r?\n)+|", "\n", $description );
186 $description = nl2br( $description );
187 $version = wp_kses( $plugin['version'], $plugins_allowedtags );
189 $name = strip_tags( $title . ' ' . $version );
191 $author = $plugin['author'];
192 if ( ! empty( $plugin['author'] ) )
193 $author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '.</cite>';
195 $author = wp_kses( $author, $plugins_allowedtags );
197 $action_links = array();
198 $action_links[] = '<a href="' . self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin['slug'] .
199 '&TB_iframe=true&width=600&height=550' ) . '" class="thickbox" title="' .
200 esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
202 if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
203 $status = install_plugin_install_status( $plugin );
205 switch ( $status['status'] ) {
207 if ( $status['url'] )
208 $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
210 case 'update_available':
211 if ( $status['url'] )
212 $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $status['version'] ) ) . '">' . sprintf( __( 'Update Now' ), $status['version'] ) . '</a>';
214 case 'latest_installed':
215 case 'newer_installed':
216 $action_links[] = '<span title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . _x( 'Installed', 'plugin' ) . '</span>';
221 $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
224 <td class="name column-name"<?php echo $style['name']; ?>><strong><?php echo $title; ?></strong>
225 <div class="action-links"><?php if ( !empty( $action_links ) ) echo implode( ' | ', $action_links ); ?></div>
227 <td class="vers column-version"<?php echo $style['version']; ?>><?php echo $version; ?></td>
228 <td class="vers column-rating"<?php echo $style['rating']; ?>>
229 <div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin['num_ratings'] ), number_format_i18n( $plugin['num_ratings'] ) ) ?>">
230 <div class="star star-rating" style="width: <?php echo esc_attr( str_replace( ',', '.', $plugin['rating'] ) ); ?>px"></div>
233 <td class="desc column-description"<?php echo $style['description']; ?>><?php echo $description, $author; ?></td>