diff options
Diffstat (limited to 'plugins/jetpack/modules/theme-tools/featured-content.php')
-rw-r--r-- | plugins/jetpack/modules/theme-tools/featured-content.php | 74 |
1 files changed, 55 insertions, 19 deletions
diff --git a/plugins/jetpack/modules/theme-tools/featured-content.php b/plugins/jetpack/modules/theme-tools/featured-content.php index 5eca3369..d6b17a10 100644 --- a/plugins/jetpack/modules/theme-tools/featured-content.php +++ b/plugins/jetpack/modules/theme-tools/featured-content.php @@ -1,4 +1,9 @@ -<?php +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName +/** + * Theme Tools: functions for Featured Content enhancements. + * + * @package automattic/jetpack + */ use Automattic\Jetpack\Constants; @@ -34,6 +39,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl * add_theme_support( 'featured-content' ). * * @see Featured_Content::init() + * @var int */ public static $max_posts = 15; @@ -44,6 +50,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl * add_theme_support( 'featured-content' ). * * @see Featured_Content::init() + * @var array */ public static $post_types = array( 'post' ); @@ -52,6 +59,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl * a custom tag name that will be stored in this variable. * * @see Featured_Content::hide_featured_term + * @var string */ public static $tag; @@ -125,12 +133,12 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl unset( $theme_support[0]['additional_post_types'] ); } - // Themes can allow Featured Content pages + // 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'] ); self::$post_types = array_unique( self::$post_types ); - // register post_tag support for each post type + // register post_tag support for each post type. foreach ( self::$post_types as $post_type ) { register_taxonomy_for_object_type( 'post_tag', $post_type ); } @@ -147,7 +155,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl 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 + // 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 ); @@ -178,7 +186,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl $featured_posts = get_posts( array( 'include' => $post_ids, - 'posts_per_page' => count( $post_ids ), + 'posts_per_page' => count( $post_ids ), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page 'post_type' => self::$post_types, 'suppress_filters' => false, ) @@ -280,6 +288,9 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl * Flush the Post Tag relationships cache. * * Hooks in the "update_option_featured-content" action. + * + * @param array $prev Previous option data. + * @param array $opts New option data. */ public static function flush_post_tag_cache( $prev, $opts ) { if ( ! empty( $opts ) && ! empty( $opts['tag-id'] ) ) { @@ -305,7 +316,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl * * @uses Featured_Content::get_featured_post_ids(); * @uses Featured_Content::get_setting(); - * @param WP_Query $query + * @param WP_Query $query WP_Query object. * @return WP_Query Possibly modified WP_Query */ public static function pre_get_posts( $query ) { @@ -330,7 +341,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl $settings = self::get_setting(); // Bail if the user wants featured posts always displayed. - if ( true == $settings['show-all'] ) { + if ( $settings['show-all'] ) { return; } @@ -362,7 +373,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl public static function delete_post_tag( $tag_id ) { $settings = self::get_setting(); - if ( empty( $settings['tag-id'] ) || $tag_id != $settings['tag-id'] ) { + if ( empty( $settings['tag-id'] ) || $tag_id != $settings['tag-id'] ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual return; } @@ -381,6 +392,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl * * @param array $terms A list of term objects. This is the return value of get_terms(). * @param array $taxonomies An array of taxonomy slugs. + * @param array $args Array of get_terms() arguments. * @return array $terms */ public static function hide_featured_term( $terms, $taxonomies, $args ) { @@ -397,7 +409,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl } // We only want to hide the featured tag. - if ( ! in_array( 'post_tag', $taxonomies ) ) { + if ( ! in_array( 'post_tag', $taxonomies, true ) ) { return $terms; } @@ -407,7 +419,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl } // Bail if term objects are unavailable. - if ( 'all' != $args['fields'] ) { + if ( 'all' !== $args['fields'] ) { return $terms; } @@ -451,7 +463,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl } // Make sure we are in the correct taxonomy. - if ( 'post_tag' != $taxonomy ) { + if ( 'post_tag' !== $taxonomy ) { return $terms; } @@ -499,7 +511,12 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl 'featured_content', array( 'title' => esc_html__( 'Featured Content', 'jetpack' ), - 'description' => sprintf( __( 'Easily feature all posts with the <a href="%1$s">"featured" tag</a> or a tag of your choice. Your theme supports up to %2$s posts in its featured content area.', 'jetpack' ), admin_url( '/edit.php?tag=featured' ), absint( self::$max_posts ) ), + 'description' => sprintf( + /* translators: %1$s: Link to 'featured' admin tag view. %2$s: Max number of posts shown by theme in featured content area. */ + __( 'Easily feature all posts with the <a href="%1$s">"featured" tag</a> or a tag of your choice. Your theme supports up to %2$s posts in its featured content area.', 'jetpack' ), + admin_url( '/edit.php?tag=featured' ), + absint( self::$max_posts ) + ), 'priority' => 130, 'theme_supports' => 'featured-content', ) @@ -578,7 +595,16 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl * Renders all form fields on the Settings -> Reading screen. */ public static function render_form() { - printf( __( 'The settings for Featured Content have <a href="%s">moved to Appearance → Customize</a>.', 'jetpack' ), admin_url( 'customize.php?#accordion-section-featured_content' ) ); + printf( + wp_kses( + /* translators: %s: Link to the Featured Content settings in the Customizer. */ + __( 'The settings for Featured Content have <a href="%s">moved to Appearance → Customize</a>.', 'jetpack' ), + array( + 'a' => array( 'href' => array() ), + ) + ), + esc_url( admin_url( 'customize.php?#accordion-section-featured_content' ) ) + ); } /** @@ -626,7 +652,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl $options = wp_parse_args( $saved, $defaults ); $options = array_intersect_key( $options, $defaults ); - if ( 'all' != $key ) { + if ( 'all' !== $key ) { return isset( $options[ $key ] ) ? $options[ $key ] : false; } @@ -642,7 +668,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl * * @uses Featured_Content::delete_transient() * - * @param array $input + * @param array $input Array of settings input. * @return array $output */ public static function validate_settings( $input ) { @@ -689,11 +715,19 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl } } + /** + * Update Featured Content term data as necessary when a shared term is split. + * + * @param int $old_term_id ID of the formerly shared term. + * @param int $new_term_id ID of the new term created for the $term_taxonomy_id. + * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. + * @param string $taxonomy Taxonomy for the split term. + */ public static function jetpack_update_featured_content_for_split_terms( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { $featured_content_settings = get_option( 'featured-content', array() ); // Check to see whether the stored tag ID is the one that's just been split. - if ( isset( $featured_content_settings['tag-id'] ) && $old_term_id == $featured_content_settings['tag-id'] && 'post_tag' == $taxonomy ) { + if ( isset( $featured_content_settings['tag-id'] ) && $old_term_id == $featured_content_settings['tag-id'] && 'post_tag' === $taxonomy ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual // We have a match, so we swap out the old tag ID for the new one and resave the option. $featured_content_settings['tag-id'] = $new_term_id; update_option( 'featured-content', $featured_content_settings ); @@ -705,7 +739,7 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl * Adds the featured content plugin to the set of files for which action * handlers should be copied when the theme context is loaded by the REST API. * - * @param array $copy_dirs Copy paths with actions to be copied + * @param array $copy_dirs Copy paths with actions to be copied. * @return array Copy paths with featured content plugin */ function wpcom_rest_api_featured_content_copy_plugin_actions( $copy_dirs ) { @@ -716,6 +750,8 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl /** * Delayed initialization for API Requests. + * + * @param object $request REST request object. */ function wpcom_rest_request_before_callbacks( $request ) { Featured_Content::init(); @@ -723,8 +759,8 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'pl } if ( Constants::is_true( 'IS_WPCOM' ) && Constants::is_true( 'REST_API_REQUEST' ) ) { - add_filter( 'rest_request_before_callbacks', 'wpcom_rest_request_before_callbacks'); + add_filter( 'rest_request_before_callbacks', 'wpcom_rest_request_before_callbacks' ); } Featured_Content::setup(); -} // end if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'plugins.php' !== $GLOBALS['pagenow'] ) { +} |