Make WordPress Core

Changeset 27120


Ignore:
Timestamp:
02/07/2014 05:38:08 PM (11 years ago)
Author:
lancewillett
Message:

Twenty Fourteen: delete the featured_content_ids transient on theme switch to make sure child themes can override the Featured Content quantity value. Also remove quantity parameter so child themes can change the amount of featured posts with $max_posts.

Props obenland, see #26660.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyfourteen/inc/featured-content.php

    r27118 r27120  
    8787        add_action( 'customize_register',                 array( __CLASS__, 'customize_register' ), 9 );
    8888        add_action( 'admin_init',                         array( __CLASS__, 'register_setting'   )    );
     89        add_action( 'switch_theme',                       array( __CLASS__, 'delete_transient'   )    );
    8990        add_action( 'save_post',                          array( __CLASS__, 'delete_transient'   )    );
    9091        add_action( 'delete_post_tag',                    array( __CLASS__, 'delete_post_tag'    )    );
     
    169170        // Query for featured posts.
    170171        $featured = get_posts( array(
    171             'numberposts' => $settings['quantity'],
     172            'numberposts' => self::$max_posts,
    172173            'tax_query'   => array(
    173174                array(
     
    204205    public static function get_sticky_posts() {
    205206        $settings = self::get_setting();
    206         return array_slice( get_option( 'sticky_posts', array() ), 0, $settings['quantity'] );
     207        return array_slice( get_option( 'sticky_posts', array() ), 0, self::$max_posts );
    207208    }
    208209
     
    475476        $defaults = array(
    476477            'hide-tag' => 1,
    477             'quantity' => 6,
    478478            'tag-id'   => 0,
    479479            'tag-name' => 'featured',
     
    482482        $options = wp_parse_args( $saved, $defaults );
    483483        $options = array_intersect_key( $options, $defaults );
    484         $options['quantity'] = self::sanitize_quantity( $options['quantity'] );
    485484
    486485        if ( 'all' != $key ) {
     
    526525        }
    527526
    528         if ( isset( $input['quantity'] ) ) {
    529             $output['quantity'] = self::sanitize_quantity( $input['quantity'] );
    530         }
    531 
    532527        $output['hide-tag'] = isset( $input['hide-tag'] ) && $input['hide-tag'] ? 1 : 0;
    533528
     
    537532        return $output;
    538533    }
    539 
    540     /**
    541      * Sanitize quantity of featured posts.
    542      *
    543      * @static
    544      * @access public
    545      * @since Twenty Fourteen 1.0
    546      *
    547      * @param int $input The value to sanitize.
    548      * @return int A number between 1 and FeaturedContent::$max_posts.
    549      */
    550     public static function sanitize_quantity( $input ) {
    551         $quantity = absint( $input );
    552 
    553         if ( $quantity > self::$max_posts ) {
    554             $quantity = self::$max_posts;
    555         } else if ( 1 > $quantity ) {
    556             $quantity = 1;
    557         }
    558 
    559         return $quantity;
    560     }
    561 
    562534} // Featured_Content
    563535
Note: See TracChangeset for help on using the changeset viewer.