X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/61343b82c4f0da4c68e4c6373daafff4a81efdd1..ef91a7f4f3c6468973e192335a27ec0e0faca0b5:/wp-admin/includes/class-wp-plugin-install-list-table.php diff --git a/wp-admin/includes/class-wp-plugin-install-list-table.php b/wp-admin/includes/class-wp-plugin-install-list-table.php index 76ef2ce2..cd718360 100644 --- a/wp-admin/includes/class-wp-plugin-install-list-table.php +++ b/wp-admin/includes/class-wp-plugin-install-list-table.php @@ -1,19 +1,76 @@ no_update ) ) { + foreach ( $plugin_info->no_update as $plugin ) { + $slugs[] = $plugin->slug; + } + } + + if ( isset( $plugin_info->response ) ) { + foreach ( $plugin_info->response as $plugin ) { + $slugs[] = $plugin->slug; + } + } + + return $slugs; + } + + /** + * + * @global array $tabs + * @global string $tab + * @global int $paged + * @global string $type + * @global string $term + */ + public function prepare_items() { include( ABSPATH . 'wp-admin/includes/plugin-install.php' ); global $tabs, $tab, $paged, $type, $term; @@ -26,25 +83,60 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { // These are the tabs which are shown on the page $tabs = array(); - $tabs['dashboard'] = __( 'Search' ); - if ( 'search' == $tab ) - $tabs['search'] = __( 'Search Results' ); - $tabs['upload'] = __( 'Upload' ); - $tabs['featured'] = _x( 'Featured', 'Plugin Installer' ); - $tabs['popular'] = _x( 'Popular', 'Plugin Installer' ); - $tabs['new'] = _x( 'Newest', 'Plugin Installer' ); - $tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' ); - $nonmenu_tabs = array( 'plugin-information' ); //Valid actions to perform which do not have a Menu item. + if ( 'search' === $tab ) { + $tabs['search'] = __( 'Search Results' ); + } + if ( $tab === 'beta' || false !== strpos( get_bloginfo( 'version' ), '-' ) ) { + $tabs['beta'] = _x( 'Beta Testing', 'Plugin Installer' ); + } + $tabs['featured'] = _x( 'Featured', 'Plugin Installer' ); + $tabs['popular'] = _x( 'Popular', 'Plugin Installer' ); + $tabs['recommended'] = _x( 'Recommended', 'Plugin Installer' ); + $tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' ); + if ( current_user_can( 'upload_plugins' ) ) { + // No longer a real tab. Here for filter compatibility. + // Gets skipped in get_views(). + $tabs['upload'] = __( 'Upload Plugin' ); + } + + $nonmenu_tabs = array( 'plugin-information' ); // Valid actions to perform which do not have a Menu item. + /** + * Filters the tabs shown on the Plugin Install screen. + * + * @since 2.7.0 + * + * @param array $tabs The tabs shown on the Plugin Install screen. Defaults include 'featured', 'popular', + * 'recommended', 'favorites', and 'upload'. + */ $tabs = apply_filters( 'install_plugins_tabs', $tabs ); + + /** + * Filters tabs not associated with a menu item on the Plugin Install screen. + * + * @since 2.7.0 + * + * @param array $nonmenu_tabs The tabs that don't have a Menu item on the Plugin Install screen. + */ $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs ); // If a non-valid menu tab has been selected, And it's not a non-menu action. if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) ) $tab = key( $tabs ); - $args = array( 'page' => $paged, 'per_page' => $per_page ); + $args = array( + 'page' => $paged, + 'per_page' => $per_page, + 'fields' => array( + 'last_updated' => true, + 'icons' => true, + 'active_installs' => true + ), + // Send the locale and installed plugin slugs to the API so it can provide context-sensitive results. + 'locale' => get_user_locale(), + 'installed_plugins' => $this->get_installed_plugin_slugs(), + ); switch ( $tab ) { case 'search': @@ -63,18 +155,27 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { break; } - add_action( 'install_plugins_table_header', 'install_search_form', 10, 0 ); break; case 'featured': + $args['fields']['group'] = true; + $this->orderby = 'group'; + // No break! case 'popular': case 'new': + case 'beta': + case 'recommended': $args['browse'] = $tab; break; case 'favorites': - $user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' ); - update_user_meta( get_current_user_id(), 'wporg_favorites', $user ); + $action = 'save_wporg_username_' . get_current_user_id(); + if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), $action ) ) { + $user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' ); + update_user_meta( get_current_user_id(), 'wporg_favorites', $user ); + } else { + $user = get_user_option( 'wporg_favorites' ); + } if ( $user ) $args['user'] = $user; else @@ -85,46 +186,158 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { default: $args = false; + break; } + /** + * Filters API request arguments for each Plugin Install screen tab. + * + * The dynamic portion of the hook name, `$tab`, refers to the plugin install tabs. + * Default tabs include 'featured', 'popular', 'recommended', 'favorites', and 'upload'. + * + * @since 3.7.0 + * + * @param array|bool $args Plugin Install API arguments. + */ + $args = apply_filters( "install_plugins_table_api_args_{$tab}", $args ); + if ( !$args ) return; $api = plugins_api( 'query_plugins', $args ); - if ( is_wp_error( $api ) ) - wp_die( $api->get_error_message() . '
'; + } else { + $message = __( 'No plugins match your request.' ); + } + echo '