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['updated'] = _x( 'Recently Updated','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 its 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'] ) ? stripslashes( $_REQUEST['type'] ) : '';
52 $term = isset( $_REQUEST['s'] ) ? stripslashes( $_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' );
73 $args['browse'] = $tab;
83 $api = plugins_api( 'query_plugins', $args );
85 if ( is_wp_error( $api ) )
86 wp_die( $api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
88 $this->items = $api->plugins;
90 $this->set_pagination_args( array(
91 'total_items' => $api->info['results'],
92 'per_page' => $per_page,
97 _e( 'No plugins match your request.' );
100 function get_views() {
103 $display_tabs = array();
104 foreach ( (array) $tabs as $action => $text ) {
105 $class = ( $action == $tab ) ? ' class="current"' : '';
106 $href = self_admin_url('plugin-install.php?tab=' . $action);
107 $display_tabs['plugin-install-'.$action] = "<a href='$href'$class>$text</a>";
110 return $display_tabs;
113 function display_tablenav( $which ) {
114 if ( 'top' == $which ) { ?>
115 <div class="tablenav top">
116 <div class="alignleft actions">
117 <?php do_action( 'install_plugins_table_header' ); ?>
119 <?php $this->pagination( $which ); ?>
120 <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
124 <div class="tablenav bottom">
125 <?php $this->pagination( $which ); ?>
126 <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
133 function get_table_classes() {
134 extract( $this->_args );
136 return array( 'widefat', $plural );
139 function get_columns() {
141 'name' => __( 'Name' ),
142 'version' => __( 'Version' ),
143 'rating' => __( 'Rating' ),
144 'description' => __( 'Description' ),
148 function display_rows() {
149 $plugins_allowedtags = array(
150 'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
151 'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
152 'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
153 'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
156 list( $columns, $hidden ) = $this->get_column_info();
159 foreach ( $columns as $column_name => $column_display_name ) {
160 $style[ $column_name ] = in_array( $column_name, $hidden ) ? 'style="display:none;"' : '';
163 foreach ( (array) $this->items as $plugin ) {
164 if ( is_object( $plugin ) )
165 $plugin = (array) $plugin;
167 $title = wp_kses( $plugin['name'], $plugins_allowedtags );
168 //Limit description to 400char, and remove any HTML.
169 $description = strip_tags( $plugin['description'] );
170 if ( strlen( $description ) > 400 )
171 $description = mb_substr( $description, 0, 400 ) . '…';
172 //remove any trailing entities
173 $description = preg_replace( '/&[^;\s]{0,6}$/', '', $description );
174 //strip leading/trailing & multiple consecutive lines
175 $description = trim( $description );
176 $description = preg_replace( "|(\r?\n)+|", "\n", $description );
178 $description = nl2br( $description );
179 $version = wp_kses( $plugin['version'], $plugins_allowedtags );
181 $name = strip_tags( $title . ' ' . $version );
183 $author = $plugin['author'];
184 if ( ! empty( $plugin['author'] ) )
185 $author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '.</cite>';
187 $author = wp_kses( $author, $plugins_allowedtags );
189 $action_links = array();
190 $action_links[] = '<a href="' . self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin['slug'] .
191 '&TB_iframe=true&width=600&height=550' ) . '" class="thickbox" title="' .
192 esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
194 if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
195 $status = install_plugin_install_status( $plugin );
197 switch ( $status['status'] ) {
199 if ( $status['url'] )
200 $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
202 case 'update_available':
203 if ( $status['url'] )
204 $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $status['version'] ) ) . '">' . sprintf( __( 'Update Now' ), $status['version'] ) . '</a>';
206 case 'latest_installed':
207 case 'newer_installed':
208 $action_links[] = '<span title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . __( 'Installed' ) . '</span>';
213 $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
216 <td class="name column-name"<?php echo $style['name']; ?>><strong><?php echo $title; ?></strong>
217 <div class="action-links"><?php if ( !empty( $action_links ) ) echo implode( ' | ', $action_links ); ?></div>
219 <td class="vers column-version"<?php echo $style['version']; ?>><?php echo $version; ?></td>
220 <td class="vers column-rating"<?php echo $style['rating']; ?>>
221 <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'] ) ) ?>">
222 <div class="star star-rating" style="width: <?php echo esc_attr( $plugin['rating'] ) ?>px"></div>
223 <div class="star star5"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '5 stars' ) ?>" /></div>
224 <div class="star star4"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '4 stars' ) ?>" /></div>
225 <div class="star star3"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '3 stars' ) ?>" /></div>
226 <div class="star star2"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '2 stars' ) ?>" /></div>
227 <div class="star star1"><img src="<?php echo admin_url( 'images/star.gif' ); ?>" alt="<?php _e( '1 star' ) ?>" /></div>
230 <td class="desc column-description"<?php echo $style['description']; ?>><?php echo $description, $author; ?></td>