Make WordPress Core

Ticket #26233: 26233.diff

File 26233.diff, 12.1 KB (added by kovshenin, 12 years ago)
  • wp-content/themes/twentyfourteen/functions.php

     
    105105        ) ) );
    106106
    107107        // Add support for featured content.
    108         add_theme_support( 'featured-content', array(
     108        add_theme_support( 'twentyfourteen-featured-content', array(
    109109                'featured_content_filter' => 'twentyfourteen_get_featured_posts',
    110110                'max_posts' => 6,
    111111        ) );
     
    495495/*
    496496 * Add Featured Content functionality.
    497497 *
    498  * To overwrite in a plugin, define your own Featured_Content class on or
     498 * To overwrite in a plugin, define your own Twenty_Fourteen_Featured_Content class on or
    499499 * before the 'setup_theme' hook.
    500500 */
    501 if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
     501if ( ! class_exists( 'Twenty_Fourteen_Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
    502502        require get_template_directory() . '/inc/featured-content.php';
    503503}
  • wp-content/themes/twentyfourteen/inc/customizer.php

     
    3838        add_filter( 'theme_mod_accent_light', 'twentyfourteen_accent_light' );
    3939
    4040        // Add the featured content section in case it's not already there.
    41         $wp_customize->add_section( 'featured_content', array(
     41        $wp_customize->add_section( 'twentyfourteen_featured_content', array(
    4242                'title'       => __( 'Featured Content', 'twentyfourteen' ),
    4343                'description' => sprintf( __( 'Use a <a href="%1$s"> tag</a> to feature your posts. If no posts match the tag, <a href="%2$s">sticky posts</a> will be displayed instead.', 'twentyfourteen' ), admin_url( '/edit.php?tag=featured' ), admin_url( '/edit.php?show_sticky=1' ) ),
    4444                'priority'    => 130,
     
    5151
    5252        $wp_customize->add_control( 'featured_content_layout', array(
    5353                'label'   => __( 'Layout', 'twentyfourteen' ),
    54                 'section' => 'featured_content',
     54                'section' => 'twentyfourteen_featured_content',
    5555                'type'    => 'select',
    5656                'choices' => array(
    5757                        'grid'   => __( 'Grid',   'twentyfourteen' ),
  • wp-content/themes/twentyfourteen/inc/featured-content.php

     
    1010 * has special meaning beyond that of a normal tags, users will have the
    1111 * ability to hide it from the front-end of their site.
    1212 */
    13 class Featured_Content {
     13class Twenty_Fourteen_Featured_Content {
    1414
    1515        /**
    1616         * The maximum number of posts that a Featured Content area can contain. We
    1717         * define a default value here but themes can override this by defining a
    1818         * "max_posts" entry in the second parameter passed in the call to
    19          * add_theme_support( 'featured-content' ).
     19         * add_theme_support( 'twentyfourteen-featured-content' ).
    2020         *
    21          * @see Featured_Content::init()
     21         * @see Twenty_Fourteen_Featured_Content::init()
    2222         */
    2323        public static $max_posts = 15;
    2424
     
    3535         * Conditionally hook into WordPress
    3636         *
    3737         * Theme must declare that they support this module by adding
    38          * add_theme_support( 'featured-content' ); during after_setup_theme.
     38         * add_theme_support( 'twentyfourteen-featured-content' ); during after_setup_theme.
    3939         *
    4040         * If no theme support is found there is no need to hook into WordPress.
    4141         * We'll just return early instead.
    4242         *
    43          * @uses Featured_Content::$max_posts
     43         * @uses Twenty_Fourteen_Featured_Content::$max_posts
    4444         */
    4545        public static function init() {
    46                 $theme_support = get_theme_support( 'featured-content' );
     46                $theme_support = get_theme_support( 'twentyfourteen-featured-content' );
    4747
    4848                // Return early if theme does not support Featured Content.
    4949                if ( ! $theme_support ) {
     
    9696        /**
    9797         * Get featured posts
    9898         *
    99          * @uses Featured_Content::get_featured_post_ids()
     99         * @uses Twenty_Fourteen_Featured_Content::get_featured_post_ids()
    100100         *
    101101         * @return array
    102102         */
     
    122122         * This function will return the an array containing the
    123123         * post IDs of all featured posts.
    124124         *
    125          * Sets the "featured_content_ids" transient.
     125         * Sets the "twentyfourteen_featured_content_ids" transient.
    126126         *
    127127         * @return array Array of post IDs
    128128         */
    129129        public static function get_featured_post_ids() {
    130130                // Return array of cached results if they exist.
    131                 $featured_ids = get_transient( 'featured_content_ids' );
     131                $featured_ids = get_transient( 'twentyfourteen_featured_content_ids' );
    132132                if ( ! empty( $featured_ids ) ) {
    133133                        return array_map( 'absint', (array) $featured_ids );
    134134                }
     
    164164                $featured_ids = wp_list_pluck( (array) $featured, 'ID' );
    165165                $featured_ids = array_map( 'absint', $featured_ids );
    166166
    167                 set_transient( 'featured_content_ids', $featured_ids );
     167                set_transient( 'twentyfourteen_featured_content_ids', $featured_ids );
    168168
    169169                return $featured_ids;
    170170        }
     
    183183         * Delete transient
    184184         *
    185185         * Hooks in the "save_post" action.
    186          * @see Featured_Content::validate_settings().
     186         * @see Twenty_Fourteen_Featured_Content::validate_settings().
    187187         */
    188188        public static function delete_transient() {
    189                 delete_transient( 'featured_content_ids' );
     189                delete_transient( 'twentyfourteen_featured_content_ids' );
    190190        }
    191191
    192192        /**
     
    196196         * onto the 'pre_get_posts' action, this changes the parameters of the query
    197197         * before it gets any posts.
    198198         *
    199          * @uses Featured_Content::get_featured_post_ids();
     199         * @uses Twenty_Fourteen_Featured_Content::get_featured_post_ids();
    200200         * @param WP_Query $query
    201201         * @return WP_Query Possibly modified WP_Query
    202202         */
     
    237237         *
    238238         * It's important to mention that the transient needs to be deleted, too.
    239239         * While it may not be obvious by looking at the function alone, the transient
    240          * is deleted by Featured_Content::validate_settings().
     240         * is deleted by Twenty_Fourteen_Featured_Content::validate_settings().
    241241         *
    242242         * Hooks in the "delete_post_tag" action.
    243          * @see Featured_Content::validate_settings().
     243         * @see Twenty_Fourteen_Featured_Content::validate_settings().
    244244         *
    245245         * @param int $tag_id The term_id of the tag that has been deleted.
    246246         * @return void
     
    254254
    255255                $settings['tag-id'] = 0;
    256256                $settings = self::validate_settings( $settings );
    257                 update_option( 'featured-content', $settings );
     257                update_option( 'twentyfourteen-featured-content', $settings );
    258258        }
    259259
    260260        /**
     
    266266         * @param array $taxonomies An array of taxonomy slugs.
    267267         * @return array $terms
    268268         *
    269          * @uses Featured_Content::get_setting()
     269         * @uses Twenty_Fourteen_Featured_Content::get_setting()
    270270         */
    271271        public static function hide_featured_term( $terms, $taxonomies ) {
    272272
     
    304304         * @param array $taxonomy An array of taxonomy slugs.
    305305         * @return array $terms
    306306         *
    307          * @uses Featured_Content::get_setting()
     307         * @uses Twenty_Fourteen_Featured_Content::get_setting()
    308308         */
    309309        public static function hide_the_featured_term( $terms, $id, $taxonomy ) {
    310310
     
    335335        /**
    336336         * Register custom setting on the Settings -> Reading screen
    337337         *
    338          * @uses Featured_Content::render_form()
    339          * @uses Featured_Content::validate_settings()
     338         * @uses Twenty_Fourteen_Featured_Content::render_form()
     339         * @uses Twenty_Fourteen_Featured_Content::validate_settings()
    340340         *
    341341         * @return void
    342342         */
    343343        public static function register_setting() {
    344                 register_setting( 'featured-content', 'featured-content', array( __CLASS__, 'validate_settings' ) );
     344                register_setting( 'twentyfourteen-featured-content', 'twentyfourteen-featured-content', array( __CLASS__, 'validate_settings' ) );
    345345        }
    346346
    347347        /**
     
    350350         * @param WP_Customize_Manager $wp_customize Theme Customizer object.
    351351         */
    352352        public static function customize_register( $wp_customize ) {
    353                 $wp_customize->add_section( 'featured_content', array(
     353                $wp_customize->add_section( 'twentyfourteen_featured_content', array(
    354354                        'title'          => __( 'Featured Content', 'twentyfourteen' ),
    355355                        'description'    => sprintf( __( 'Use the <a href="%1$s">"featured" tag</a> to feature your posts. You can change this to a tag of your choice; if no posts match the tag, <a href="%2$s">sticky posts</a> will be displayed instead.', 'twentyfourteen' ), admin_url( '/edit.php?tag=featured' ), admin_url( '/edit.php?show_sticky=1' ) ),
    356356                        'priority'       => 130,
    357                         'theme_supports' => 'featured-content',
     357                        'theme_supports' => 'twentyfourteen-featured-content',
    358358                ) );
    359359
    360360                // Add Featured Content settings.
    361                 $wp_customize->add_setting( 'featured-content[tag-name]', array(
     361                $wp_customize->add_setting( 'twentyfourteen-featured-content[tag-name]', array(
    362362                        'default'              => 'featured',
    363363                        'type'                 => 'option',
    364364                        'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ),
    365365                ) );
    366                 $wp_customize->add_setting( 'featured-content[hide-tag]', array(
     366                $wp_customize->add_setting( 'twentyfourteen-featured-content[hide-tag]', array(
    367367                        'default'              => true,
    368368                        'type'                 => 'option',
    369369                        'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ),
    370370                ) );
    371371
    372372                // Add Featured Content controls.
    373                 $wp_customize->add_control( 'featured-content[tag-name]', array(
     373                $wp_customize->add_control( 'twentyfourteen-featured-content[tag-name]', array(
    374374                        'label'    => __( 'Tag Name', 'twentyfourteen' ),
    375                         'section'  => 'featured_content',
     375                        'section'  => 'twentyfourteen_featured_content',
    376376                        'priority' => 20,
    377377                ) );
    378                 $wp_customize->add_control( 'featured-content[hide-tag]', array(
     378                $wp_customize->add_control( 'twentyfourteen-featured-content[hide-tag]', array(
    379379                        'label'    => __( 'Don&rsquo;t display tag on front end.', 'twentyfourteen' ),
    380                         'section'  => 'featured_content',
     380                        'section'  => 'twentyfourteen_featured_content',
    381381                        'type'     => 'checkbox',
    382382                        'priority' => 30,
    383383                ) );
     
    389389         * @since Twenty Fourteen 1.0
    390390         */
    391391        public static function enqueue_scripts() {
    392                 wp_enqueue_script( 'featured-content-suggest', get_template_directory_uri() . '/js/featured-content-admin.js', array( 'jquery', 'suggest' ), '20131022', true );
     392                wp_enqueue_script( 'twentyfourteen-featured-content-suggest', get_template_directory_uri() . '/js/featured-content-admin.js', array( 'jquery', 'suggest' ), '20131022', true );
    393393        }
    394394
    395395        /**
     
    402402         * In the event that you only require one setting, you may pass its name
    403403         * as the first parameter to the function and only that value will be returned.
    404404         *
    405          * @uses Featured_Content::sanitize_quantity()
     405         * @uses Twenty_Fourteen_Featured_Content::sanitize_quantity()
    406406         *
    407407         * @param string $key The key of a recognized setting.
    408408         * @return mixed Array of all settings by default. A single value if passed as first parameter.
    409409         */
    410410        public static function get_setting( $key = 'all' ) {
    411                 $saved = (array) get_option( 'featured-content' );
     411                $saved = (array) get_option( 'twentyfourteen-featured-content' );
    412412
    413413                $defaults = array(
    414414                        'hide-tag' => 1,
     
    434434         * Make sure that all user supplied content is in an
    435435         * expected format before saving to the database. This
    436436         * function will also delete the transient set in
    437          * Featured_Content::get_featured_content().
     437         * Twenty_Fourteen_Featured_Content::get_featured_content().
    438438         *
    439          * @uses Featured_Content::self::sanitize_quantity()
    440          * @uses Featured_Content::self::delete_transient()
     439         * @uses Twenty_Fourteen_Featured_Content::self::sanitize_quantity()
     440         * @uses Twenty_Fourteen_Featured_Content::self::delete_transient()
    441441         *
    442442         * @param array $input
    443443         * @return array $output
     
    480480         * @param int $input The value to sanitize.
    481481         * @return int A number between 1 and FeaturedContent::$max_posts.
    482482         *
    483          * @uses Featured_Content::$max_posts
     483         * @uses Twenty_Fourteen_Featured_Content::$max_posts
    484484         */
    485485        public static function sanitize_quantity( $input ) {
    486486                $quantity = absint( $input );
     
    495495        }
    496496}
    497497
    498 Featured_Content::setup();
     498Twenty_Fourteen_Featured_Content::setup();
     499 No newline at end of file