This module allows you to define a subset of posts to be displayed
in the theme's Featured Content area.
For maximum compatibility with different methods of posting users
will designate a featured post tag to associate posts with. Since
this tag now has special meaning beyond that of a normal tags, users
will have the ability to hide it from the front-end of their site.
/** * Conditionally hook into WordPress. * * Theme must declare that they support this module by adding * add_theme_support( 'featured-content' ); during after_setup_theme. * * If no theme support is found there is no need to hook into WordPress. * We'll just return early instead. * * @static * @access public * @since Twenty Fourteen 1.0 */ public static function init() { $theme_support = get_theme_support('featured-content'); // Return early if theme does not support Featured Content. if (!$theme_support) { return; } /* * An array of named arguments must be passed as the second parameter * of add_theme_support(). */ if (!isset($theme_support[0])) { return; } // Return early if "featured_content_filter" has not been defined. if (!isset($theme_support[0]['featured_content_filter'])) { return; } $filter = $theme_support[0]['featured_content_filter']; // Theme can override the number of max posts. if (isset($theme_support[0]['max_posts'])) { self::$max_posts = absint($theme_support[0]['max_posts']); } add_filter($filter, array(__CLASS__, 'get_featured_posts')); add_action('customize_register', array(__CLASS__, 'customize_register'), 9); add_action('admin_init', array(__CLASS__, 'register_setting')); add_action('switch_theme', array(__CLASS__, 'delete_transient')); add_action('save_post', array(__CLASS__, 'delete_transient')); add_action('delete_post_tag', array(__CLASS__, 'delete_post_tag')); add_action('customize_controls_enqueue_scripts', array(__CLASS__, 'enqueue_scripts')); add_action('pre_get_posts', array(__CLASS__, 'pre_get_posts')); add_action('wp_loaded', array(__CLASS__, 'wp_loaded')); }
/** * Conditionally Hook into WordPress. * * Themes must declare that they support this module by adding * add_theme_support( 'featured-content' ); during after_setup_theme. * * If no theme support is found there is no need to hook into * WordPress. We'll just return early instead. * * @uses Featured_Content::$max_posts */ public static function init() { $theme_support = get_theme_support('featured-content'); // Return early if theme does not support featured content. if (!$theme_support) { return; } // An array of named arguments must be passed as // the second parameter of add_theme_support(). if (!isset($theme_support[0])) { return; } // Return early if "featured_content_filter" has not been defined. if (!isset($theme_support[0]['featured_content_filter'])) { return; } $filter = $theme_support[0]['featured_content_filter']; // Themes can override the number of max posts. if (isset($theme_support[0]['max_posts'])) { self::$max_posts = absint($theme_support[0]['max_posts']); } add_filter($filter, array(__CLASS__, 'get_featured_posts')); add_action('admin_init', array(__CLASS__, 'register_setting')); add_action('save_post', array(__CLASS__, 'delete_transient')); add_action('delete_post_tag', array(__CLASS__, 'delete_post_tag')); add_action('pre_get_posts', array(__CLASS__, 'pre_get_posts')); // Hide "featured" tag from the front-end. if (self::get_setting('hide-tag')) { add_filter('get_terms', array(__CLASS__, 'hide_featured_term'), 10, 2); add_filter('get_the_terms', array(__CLASS__, 'hide_the_featured_term'), 10, 3); } }
public static function get_jetpack_featured_content_term_id() { if (!method_exists('Featured_Content', 'get_setting')) { return 0; } $term = get_term_by('name', Featured_Content::get_setting('tag-name'), 'post_tag'); if (!$term) { return 0; } return $term->term_id; }
/** * Conditionally hook into WordPress. * * Themes must declare that they support this module by adding * add_theme_support( 'featured-content' ); during after_setup_theme. * * If no theme support is found there is no need to hook into WordPress. We'll * just return early instead. * * @uses Featured_Content::$max_posts */ public static function init() { $theme_support = get_theme_support('featured-content'); // Return early if theme does not support featured content. if (!$theme_support) { return; } /* * An array of named arguments must be passed as the second parameter * of add_theme_support(). */ if (!isset($theme_support[0])) { return; } if (isset($theme_support[0]['featured_content_filter'])) { $theme_support[0]['filter'] = $theme_support[0]['featured_content_filter']; unset($theme_support[0]['featured_content_filter']); } // Return early if "filter" has not been defined. if (!isset($theme_support[0]['filter'])) { return; } // Theme can override the number of max posts. if (isset($theme_support[0]['max_posts'])) { self::$max_posts = absint($theme_support[0]['max_posts']); } add_filter($theme_support[0]['filter'], array(__CLASS__, 'get_featured_posts')); add_action('customize_register', array(__CLASS__, 'customize_register'), 9); add_action('admin_init', array(__CLASS__, 'register_setting')); add_action('save_post', array(__CLASS__, 'delete_transient')); add_action('delete_post_tag', array(__CLASS__, 'delete_post_tag')); add_action('customize_controls_enqueue_scripts', array(__CLASS__, 'enqueue_scripts')); add_action('pre_get_posts', array(__CLASS__, 'pre_get_posts')); add_action('switch_theme', array(__CLASS__, 'switch_theme')); add_action('switch_theme', array(__CLASS__, 'delete_transient')); add_action('wp_loaded', array(__CLASS__, 'wp_loaded')); add_action('split_shared_term', array(__CLASS__, 'jetpack_update_featured_content_for_split_terms', 10, 4)); if (isset($theme_support[0]['additional_post_types'])) { $theme_support[0]['post_types'] = array_merge(array('post'), (array) $theme_support[0]['additional_post_types']); unset($theme_support[0]['additional_post_types']); } // Themes can allow Featured Content pages if (isset($theme_support[0]['post_types'])) { self::$post_types = array_merge(self::$post_types, (array) $theme_support[0]['post_types']); // register post_tag support for each post type foreach (self::$post_types as $post_type) { register_taxonomy_for_object_type('post_tag', $post_type); } } }
/** * Twenty Fourteen * Rewrites the function Featured_Content::get_featured_post_ids() * * @since 1.4 * * @param array $ids featured posts ids * @return array modified featured posts ids ( include all languages ) */ public function twenty_fourteen_featured_content_ids($featured_ids) { if (!did_action('pll_init') || false !== $featured_ids) { return $featured_ids; } $settings = Featured_Content::get_setting(); if (!($term = get_term_by('name', $settings['tag-name'], 'post_tag'))) { return $featured_ids; } // Get featured tag translations $tags = PLL()->model->term->get_translations($term->term_id); $ids = array(); // Query for featured posts in all languages // One query per language to get the correct number of posts per language foreach ($tags as $tag) { $_ids = get_posts(array('lang' => 0, 'fields' => 'ids', 'numberposts' => Featured_Content::$max_posts, 'tax_query' => array(array('taxonomy' => 'post_tag', 'terms' => (int) $tag)))); $ids = array_merge($ids, $_ids); } $ids = array_map('absint', $ids); set_transient('featured_content_ids', $ids); return $ids; }
/** * Hide "featured" tag from the front-end. * * Has to run on wp_loaded so that the preview filters of the customizer * have a chance to alter the value. */ public static function wp_loaded() { if (self::get_setting('hide-tag')) { $settings = self::get_setting(); // This is done before setting filters for get_terms in order to avoid an infinite filter loop self::$tag = get_term_by('name', $settings['tag-name'], 'post_tag'); add_filter('get_terms', array(__CLASS__, 'hide_featured_term'), 10, 3); add_filter('get_the_terms', array(__CLASS__, 'hide_the_featured_term'), 10, 3); } }