PHP Class Featured_Content, jetpack

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.
Afficher le fichier Open project: automattic/jetpack Class Usage Examples

Méthodes publiques

Свойство Type Description
$max_posts The maximum number of posts that a Featured Content area can contain. We define a default value here but themes can override this by defining a "max_posts" entry in the second parameter passed in the call to add_theme_support( 'featured-content' ).
$post_types The registered post types supported by Featured Content. Themes can add Featured Content support for registered post types by defining a 'post_types' argument (string|array) in the call to add_theme_support( 'featured-content' ).
$tag The tag that is used to mark featured content. Users can define a custom tag name that will be stored in this variable.

Méthodes publiques

Méthode Description
customize_register ( WP_Customize_Manager $wp_customize ) Add settings to the Customizer.
delete_post_tag ( integer $tag_id ) : void Reset tag option when the saved tag is deleted.
delete_transient ( ) Delete Transient.
enqueue_scripts ( ) Enqueue the tag suggestion script.
get_featured_post_ids ( ) : array Get featured post IDs
get_featured_posts ( ) : array Get featured posts
get_setting ( string $key = 'all' ) : mixed Get settings
hide_featured_term ( array $terms, array $taxonomies, $args ) : array Hide featured tag from displaying when global terms are queried from the front-end.
hide_the_featured_term ( array $terms, integer $id, array $taxonomy ) : array Hide featured tag from displaying when terms associated with a post object are queried from the front-end.
init ( ) Conditionally hook into WordPress.
jetpack_update_featured_content_for_split_terms ( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy )
pre_get_posts ( WP_Query $query ) : WP_Query Exclude featured posts from the blog query when the blog is the front-page, and user has not checked the "Display tag content in all listings" checkbox.
register_setting ( ) : void Register custom setting on the Settings -> Reading screen.
render_form ( ) Renders all form fields on the Settings -> Reading screen.
setup ( ) Instantiate.
switch_theme ( ) : void Removes the quantity setting from the options array.
validate_settings ( array $input ) : array Validate settings
wp_loaded ( ) Hide "featured" tag from the front-end.

Method Details

customize_register() public static méthode

Add settings to the Customizer.
public static customize_register ( WP_Customize_Manager $wp_customize )
$wp_customize WP_Customize_Manager Theme Customizer object.

delete_post_tag() public static méthode

It's important to mention that the transient needs to be deleted, too. While it may not be obvious by looking at the function alone, the transient is deleted by Featured_Content::validate_settings(). Hooks in the "delete_post_tag" action.
public static delete_post_tag ( integer $tag_id ) : void
$tag_id integer The term_id of the tag that has been deleted.
Résultat void

delete_transient() public static méthode

Hooks in the "save_post" action.
public static delete_transient ( )

enqueue_scripts() public static méthode

Enqueue the tag suggestion script.
public static enqueue_scripts ( )

get_featured_post_ids() public static méthode

This function will return the an array containing the post IDs of all featured posts. Sets the "featured_content_ids" transient.
public static get_featured_post_ids ( ) : array
Résultat array Array of post IDs.

get_setting() public static méthode

Get all settings recognized by this module. This function will return all settings whether or not they have been stored in the database yet. This ensures that all keys are available at all times. In the event that you only require one setting, you may pass its name as the first parameter to the function and only that value will be returned.
public static get_setting ( string $key = 'all' ) : mixed
$key string The key of a recognized setting.
Résultat mixed Array of all settings by default. A single value if passed as first parameter.

init() public static méthode

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.
public static init ( )

pre_get_posts() public static méthode

Filter the home page posts, and remove any featured post ID's from it. Hooked onto the 'pre_get_posts' action, this changes the parameters of the query before it gets any posts.
public static pre_get_posts ( WP_Query $query ) : WP_Query
$query WP_Query
Résultat WP_Query Possibly modified WP_Query

register_setting() public static méthode

Register custom setting on the Settings -> Reading screen.
public static register_setting ( ) : void
Résultat void

render_form() public static méthode

Renders all form fields on the Settings -> Reading screen.
public static render_form ( )

setup() public static méthode

All custom functionality will be hooked into the "init" action.
public static setup ( )

switch_theme() public static méthode

Removes the quantity setting from the options array.
public static switch_theme ( ) : void
Résultat void

validate_settings() public static méthode

Make sure that all user supplied content is in an expected format before saving to the database. This function will also delete the transient set in Featured_Content::get_featured_content().
public static validate_settings ( array $input ) : array
$input array
Résultat array $output

wp_loaded() public static méthode

Has to run on wp_loaded so that the preview filters of the customizer have a chance to alter the value.
public static wp_loaded ( )

Property Details

$max_posts public_oe static_oe property

The maximum number of posts that a Featured Content area can contain. We define a default value here but themes can override this by defining a "max_posts" entry in the second parameter passed in the call to add_theme_support( 'featured-content' ).
See also: Featured_Content::init()
public static $max_posts

$post_types public_oe static_oe property

The registered post types supported by Featured Content. Themes can add Featured Content support for registered post types by defining a 'post_types' argument (string|array) in the call to add_theme_support( 'featured-content' ).
See also: Featured_Content::init()
public static $post_types

$tag public_oe static_oe property

The tag that is used to mark featured content. Users can define a custom tag name that will be stored in this variable.
See also: Featured_Content::hide_featured_term
public static $tag