PHP Класс 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.
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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.

Открытые методы

Метод Описание
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.

Описание методов

customize_register() публичный статический Метод

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() публичный статический Метод

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.
Результат void

delete_transient() публичный статический Метод

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

enqueue_scripts() публичный статический Метод

Enqueue the tag suggestion script.
public static enqueue_scripts ( )

get_featured_post_ids() публичный статический Метод

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
Результат array Array of post IDs.

get_setting() публичный статический Метод

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.
Результат mixed Array of all settings by default. A single value if passed as first parameter.

init() публичный статический Метод

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() публичный статический Метод

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
Результат WP_Query Possibly modified WP_Query

register_setting() публичный статический Метод

Register custom setting on the Settings -> Reading screen.
public static register_setting ( ) : void
Результат void

render_form() публичный статический Метод

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

setup() публичный статический Метод

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

switch_theme() публичный статический Метод

Removes the quantity setting from the options array.
public static switch_theme ( ) : void
Результат void

validate_settings() публичный статический Метод

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
Результат array $output

wp_loaded() публичный статический Метод

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 ( )

Описание свойств

$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' ).
См. также: Featured_Content::init()
public static $max_posts

$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' ).
См. также: Featured_Content::init()
public static $post_types

$tag публичное статическое свойство

The tag that is used to mark featured content. Users can define a custom tag name that will be stored in this variable.
См. также: Featured_Content::hide_featured_term
public static $tag