WordPress.org

Make WordPress Core

Ticket #43357: #43357-2 2020-04-26.patch

File #43357-2 2020-04-26.patch, 4.9 KB (added by arena, 19 months ago)

with coding standards !

  • wp-includes/class-wp-feed-cache-transient.php

     
    1212 *
    1313 * @since 2.8.0
    1414 */
    15 class WP_Feed_Cache_Transient {
    16 
     15class WP_Feed_Cache_Transient implements SimplePie_Cache_Base {
    1716        /**
    1817         * Holds the transient name.
    1918         *
     
    3332        /**
    3433         * Holds the cache duration in seconds.
    3534         *
    36          * Defaults to 43200 seconds (12 hours).
    37          *
    3835         * @since 2.8.0
    3936         * @var int
    4037         */
    41         public $lifetime = 43200;
     38        public $lifetime;
    4239
    4340        /**
    4441         * Constructor.
     
    5047         * @param string $filename  Unique identifier for cache object.
    5148         * @param string $extension 'spi' or 'spc'.
    5249         */
    53         public function __construct( $location, $filename, $extension ) {
    54                 $this->name     = 'feed_' . $filename;
    55                 $this->mod_name = 'feed_mod_' . $filename;
     50        public function __construct( $location, $name, $type ) {
    5651
    57                 $lifetime = $this->lifetime;
    58                 /**
    59                  * Filters the transient lifetime of the feed cache.
    60                  *
    61                  * @since 2.8.0
    62                  *
    63                  * @param int    $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours).
    64                  * @param string $filename Unique identifier for the cache object.
    65                  */
    66                 $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename );
     52                $options = SimplePie_Cache::parse_URL( $location );
     53
     54                $this->lifetime = $options['extras']['lifetime'];
     55
     56                $this->name     = 'feed_'     . md5( "$name:$type" );
     57                $this->mod_name = 'feed_mod_' . md5( "$name:$type" );
    6758        }
    6859
    6960        /**
     
    129120                delete_transient( $this->mod_name );
    130121                return true;
    131122        }
    132 }
     123}
     124 No newline at end of file
  • wp-includes/class-wp-feed-cache.php

     
    1 <?php
    2 /**
    3  * Feed API: WP_Feed_Cache class
    4  *
    5  * @package WordPress
    6  * @subpackage Feed
    7  * @since 4.7.0
    8  */
    9 
    10 /**
    11  * Core class used to implement a feed cache.
    12  *
    13  * @since 2.8.0
    14  *
    15  * @see SimplePie_Cache
    16  */
    17 class WP_Feed_Cache extends SimplePie_Cache {
    18 
    19         /**
    20          * Creates a new SimplePie_Cache object.
    21          *
    22          * @since 2.8.0
    23          *
    24          * @param string $location  URL location (scheme is used to determine handler).
    25          * @param string $filename  Unique identifier for cache object.
    26          * @param string $extension 'spi' or 'spc'.
    27          * @return WP_Feed_Cache_Transient Feed cache handler object that uses transients.
    28          */
    29         public function create( $location, $filename, $extension ) {
    30                 return new WP_Feed_Cache_Transient( $location, $filename, $extension );
    31         }
    32 }
  • wp-includes/feed.php

    Property changes on: wp-includes/class-wp-feed-cache.php
    ___________________________________________________________________
    Deleted: svn:eol-style
    ## -1 +0,0 ##
    -native
    \ No newline at end of property
     
    749749 * @return SimplePie|WP_Error SimplePie object on success or WP_Error object on failure.
    750750 */
    751751function fetch_feed( $url ) {
     752
     753        /**
     754         * Filters the transient lifetime of the feed cache.
     755         *
     756         * @since 2.8.0
     757         *
     758         * @param int    $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours).
     759         * @param string $filename Unique identifier for the cache object.
     760         */
     761        $lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url );
     762
    752763        if ( ! class_exists( 'SimplePie', false ) ) {
    753764                require_once ABSPATH . WPINC . '/class-simplepie.php';
    754765        }
    755766
    756         require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
    757767        require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
    758768        require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
    759769        require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.php';
     
    760770
    761771        $feed = new SimplePie();
    762772
    763         $feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' );
    764         // We must manually overwrite $feed->sanitize because SimplePie's
    765         // constructor sets it before we have a chance to set the sanitization class.
    766         $feed->sanitize = new WP_SimplePie_Sanitize_KSES();
     773        SimplePie_Cache::register( 'wordpress', 'WP_Feed_Cache_Transient');
     774        $feed->set_cache_duration( $lifetime );
     775        $feed->set_cache_location( 'wordpress://wordpress?&lifetime=' . $lifetime );
    767776
    768         $feed->set_cache_class( 'WP_Feed_Cache' );
    769         $feed->set_file_class( 'WP_SimplePie_File' );
     777        $feed->registry->register( 'File',  'WP_SimplePie_File', true );
    770778
    771779        $feed->set_feed_url( $url );
    772         /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    773         $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) );
     780
    774781        /**
    775782         * Fires just before processing the SimplePie feed object.
    776783         *