Make WordPress Core

Ticket #8781: 8781.9.patch

File 8781.9.patch, 3.6 KB (added by Viper007Bond, 16 years ago)

Use the new transient API instead of an option to cache the plugin slugs

  • wp-admin/includes/dashboard.php

     
    734734        $new     = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
    735735        $updated = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/updated/' );
    736736
     737        if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
     738                $plugin_slugs = array_keys( get_plugins() );
     739                set_transient( 'plugin_slugs', $plugin_slugs, 86400 );
     740        }
     741
    737742        foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
    738743                if ( !$$feed->get_item_quantity() )
    739744                        continue;
    740745
    741746                $items = $$feed->get_items(0, 5);
    742                 $item_key = array_rand($items);
    743747
     748                // Pick a random, non-installed plugin
     749                while ( true ) {
     750                        // Abort this foreach loop iteration if there's no plugins left of this type
     751                        if ( 0 == count($items) )
     752                                continue 2;
     753
     754                        $item_key = array_rand($items);
     755                        $item = $items[$item_key];
     756
     757                        list($link, $frag) = explode( '#', $item->get_link() );
     758
     759                        $link = clean_url($link);
     760                        if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
     761                                $slug = $matches[1];
     762                        else {
     763                                unset( $items[$item_key] );
     764                                continue;
     765                        }
     766
     767                        // Is this random plugin's slug already installed? If so, try again.
     768                        reset( $plugin_slugs );
     769                        foreach ( $plugin_slugs as $plugin_slug ) {
     770                                if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
     771                                        unset( $items[$item_key] );
     772                                        continue 2;
     773                                }
     774                        }
     775
     776                        // If we get to this point, then the random plugin isn't installed and we can stop the while().
     777                        break;
     778                }
     779
    744780                // Eliminate some common badly formed plugin descriptions
    745781                while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
    746782                        unset($items[$item_key]);
     
    748784                if ( !isset($items[$item_key]) )
    749785                        continue;
    750786
    751                 $item = $items[$item_key];
    752 
    753787                // current bbPress feed item titles are: user on "topic title"
    754788                if ( preg_match( '/"(.*)"/s', $item->get_title(), $matches ) )
    755789                        $title = $matches[1];
     
    759793
    760794                $description = wp_specialchars( strip_tags(html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset'))) );
    761795
    762                 list($link, $frag) = explode( '#', $item->get_link() );
    763 
    764                 $link = clean_url($link);
    765                 if( preg_match('|/([^/]+?)/?$|', $link, $matches) )
    766                         $slug = $matches[1];
    767                 else
    768                         $slug = '';
    769 
    770796                $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
    771797                                                        '&TB_iframe=true&width=600&height=800';
    772798
     
    885911 */
    886912function wp_dashboard_empty() {}
    887913
    888 ?>
     914?>
     915 No newline at end of file
  • wp-admin/plugins.php

     
    212212$inactive_plugins = array();
    213213$recent_plugins = array();
    214214$recently_activated = (array) get_option('recently_activated');
     215set_transient( 'plugin_slugs', array_keys($all_plugins), 86400 );
    215216
    216 //Clean out any plugins which were deactivated over a week ago.
     217// Clean out any plugins which were deactivated over a week ago.
    217218foreach ( $recently_activated as $key => $time )
    218219        if ( $time + (7*24*60*60) < time() ) //1 week
    219220                unset($recently_activated[ $key ]);
     
    394395
    395396<?php
    396397include('admin-footer.php');
    397 ?>
     398?>
     399 No newline at end of file