Make WordPress Core

Ticket #18356: 18356.diff

File 18356.diff, 1.8 KB (added by prettyboymp, 14 years ago)
  • wp-includes/bookmark.php

     
    105105 *              separated by commas.
    106106 * 'exclude' - Default is empty string (string). Exclude other categories
    107107 *              separated by commas.
     108 * 'expiration' - Default is 600 (integer). Lifetime of result cache when ordering
     109 *              by 'rand'
    108110 *
    109111 * @since 2.1.0
    110112 * @uses $wpdb Database Object
     
    121123                'limit' => -1, 'category' => '',
    122124                'category_name' => '', 'hide_invisible' => 1,
    123125                'show_updated' => 0, 'include' => '',
    124                 'exclude' => '', 'search' => ''
     126                'exclude' => '', 'search' => '',
     127                'expiration' => 600
    125128        );
    126129
    127130        $r = wp_parse_args( $args, $defaults );
    128131        extract( $r, EXTR_SKIP );
    129 
     132       
    130133        $cache = array();
    131134        $key = md5( serialize( $r ) );
    132135        if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {
    133                 if ( is_array($cache) && isset( $cache[ $key ] ) )
    134                         return apply_filters('get_bookmarks', $cache[ $key ], $r );
     136                if ( is_array($cache) && isset( $cache[ $key ] ) ) {
     137                        if (    $orderby == 'rand' ) {
     138                                if ( is_array( $cache[ $key ] ) && isset( $cache[ $key ][ 'results' ] ) && isset( $cache[ $key ][ 'expires' ] ) &&   $cache[ $key ][ 'expires' ] > time() )
     139                                        return apply_filters('get_bookmarks', $cache[ $key ][ 'results' ], $r );
     140                        } else {
     141                                return apply_filters('get_bookmarks', $cache[ $key ], $r );
     142                        }
     143                }
    135144        }
    136145
    137146        if ( !is_array($cache) )
     
    252261
    253262        $results = $wpdb->get_results($query);
    254263
    255         $cache[ $key ] = $results;
     264        if(     $orderby == 'rand()' )
     265                $cache[ $key ] = array(  'expires' => time() + $expiration, 'results' => $results );
     266        else
     267                $cache[ $key ] = $results;
     268       
    256269        wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
    257270
    258271        return apply_filters('get_bookmarks', $results, $r);