Make WordPress Core

Ticket #17902: 17902-plugin-details-link-3.diff

File 17902-plugin-details-link-3.diff, 5.9 KB (added by tellyworth, 11 years ago)

Fix broken/missing Detail links in multisite

  • wp-admin/includes/class-wp-plugin-install-list-table.php

     
    1313                return current_user_can('install_plugins');
    1414        }
    1515
     16        /**
     17         * Return a list of slugs of installed plugins, if known.
     18         */
     19        public function get_installed_plugin_stubs() {
     20                $slugs = array();
     21               
     22                // Use the transient data from the updates API to determine the slugs of known installed plugins.
     23                // This code might be better placed elsewhere, perhaps even within get_plugins().
     24                $plugin_info = get_site_transient('update_plugins');
     25                if ( isset( $plugin_info->no_update ) ) {
     26                        foreach ( $plugin_info->no_update as $plugin ) {
     27                                $slugs[] = $plugin->slug;
     28                        }
     29                }
     30                if ( isset( $plugin_info->response ) ) {
     31                        foreach ( $plugin_info->response as $plugin ) {
     32                                $slugs[] = $plugin->slug;
     33                        }
     34                }
     35                return $slugs;
     36        }
     37
    1638        public function prepare_items() {
    1739                include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    1840
     
    6284                if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
    6385                        $tab = key( $tabs );
    6486
    65                 $args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => array( 'last_updated' => true, 'downloaded' => true ) );
    66 
     87                $args = array( 'page' => $paged, 'per_page' => $per_page,
     88                        'fields' => array( 'last_updated' => true, 'downloaded' => true ),
     89                        // Send the locale and installed plugin slugs to the API so it can provide context-sensitive results.
     90                        'locale' => get_locale(),
     91                        'installed_plugins' => $this->get_installed_plugin_stubs(),
     92                );
     93               
    6794                switch ( $tab ) {
    6895                        case 'search':
    6996                                $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
  • wp-admin/includes/class-wp-plugins-list-table.php

     
    108108                                        unset( $recently_activated[$key] );
    109109                        update_option( 'recently_activated', $recently_activated );
    110110                }
     111               
     112                $plugin_info = get_site_transient( 'update_plugins' );
    111113
    112114                foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
     115                        // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide.
     116                        if ( isset( $plugin_info->response[ $plugin_file ] ) ) {
     117                                $plugins['all'][$plugin_file] = $plugin_data = array_merge( (array)$plugin_info->response[ $plugin_file ], $plugin_data );
     118                        } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) {
     119                                $plugins['all'][$plugin_file] = $plugin_data = array_merge( (array)$plugin_info->no_update[ $plugin_file ], $plugin_data );
     120                        }
     121
    113122                        // Filter into individual sections
    114123                        if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) {
    115124                                // On the non-network screen, filter out network-only plugins as long as they're not individually activated
     
    344353                $actions = array(
    345354                        'deactivate' => '',
    346355                        'activate' => '',
     356                        'details' => '',
    347357                        'edit' => '',
    348358                        'delete' => '',
    349359                );
     
    392402                                        if ( ! is_multisite() && current_user_can('delete_plugins') )
    393403                                                $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
    394404                                } // end if $is_active
     405                               
    395406                         } // end if $screen->in_admin( 'network' )
    396407
     408                        // Extra data from the updates API, if available
     409                        if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && isset( $plugin_data['slug'] ) ) {
     410                                $actions['details'] = '<a href="' . self_admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin_data['slug'] .
     411                                                        '&amp;TB_iframe=true&amp;width=600&amp;height=550' ) . '" class="thickbox" title="' .
     412                                                        esc_attr( sprintf( __( 'More information about %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Details' ) . '</a>';
     413                        }
     414
    397415                        if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
    398416                                $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
    399417                } // end if $context
  • wp-includes/update.php

     
    277277                        'plugins'      => json_encode( $to_send ),
    278278                        'translations' => json_encode( $translations ),
    279279                        'locale'       => json_encode( $locales ),
     280                        'all'          => json_encode( true ),
    280281                ),
    281282                'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
    282283        );
     
    286287        }
    287288
    288289        $url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/';
     290
    289291        if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
    290292                $url = set_url_scheme( $url, 'https' );
    291293
     
    303305                $plugin = (object) $plugin;
    304306        }
    305307        unset( $plugin );
     308        foreach ( $response['no_update'] as &$plugin ) {
     309                $plugin = (object) $plugin;
     310        }
     311        unset( $plugin );
    306312
    307313        if ( is_array( $response ) ) {
    308314                $new_option->response = $response['plugins'];
    309315                $new_option->translations = $response['translations'];
     316                // TODO: Perhaps better to store no_update in a separate transient with an expiry?
     317                $new_option->no_update = $response['no_update'];
    310318        } else {
    311319                $new_option->response = array();
    312320                $new_option->translations = array();
     321                $new_option->no_update = array();
    313322        }
    314323
    315324        set_site_transient( 'update_plugins', $new_option );