taxonomy ); } // phpcs:ignore Generic.Commenting.DocComment.MissingShort /** @inheritdoc */ public static function get_keys() { return array_keys( array_filter( self::get_available_taxonomies(), function ( $taxonomy ) { return ! empty( Taxonomy_Provider::get_terms( $taxonomy ) ); } ) ); } // phpcs:ignore /** @inheritdoc */ public static function describe_key( $provider_key ) { // phpcs:ignore Generic.Commenting.DocComment.MissingShort $taxonomy = substr( $provider_key, strlen( static::$name ) + 1 ); switch ( $taxonomy ) { case 'category': return __( 'Category view', 'jetpack-boost' ); default: return __( 'View for custom taxonomy', 'jetpack-boost' ); } } // phpcs:ignore Generic.Commenting.DocComment.MissingShort /** @inheritdoc */ public static function get_edit_url( $_provider_key ) { // phpcs:ignore Generic.Commenting.DocComment.MissingShort return null; } /** * Which taxonomies should Critical CSS be generated for. * * @return array */ public static function get_available_taxonomies() { $taxonomies = get_taxonomies( array( 'public' => true, 'show_in_rest' => true, ), 'objects' ); $taxonomies = array_filter( $taxonomies, 'is_taxonomy_viewable' ); $provider_taxonomies = array(); // Generate a name => name array for backwards compatibility. foreach ( $taxonomies as $taxonomy ) { $provider_taxonomies[ $taxonomy->name ] = $taxonomy->name; } return $provider_taxonomies; } /** * Get a couple sample terms for a taxonomy. * * @param string $taxonomy Taxonomy. * * @return array */ public static function get_terms( $taxonomy ) { /** * Filters the WP_Term_Query args to get a sample of terms for a taxonomy * * @param array $args The arguments that will be used by WP_Term_Query * * @since 1.0.0 */ $args = apply_filters( 'jetpack_boost_critical_css_terms_query', array( 'fields' => 'ids', 'taxonomy' => $taxonomy, 'orderby' => 'term_order', 'number' => static::MAX_URLS, 'hide_empty' => true, 'hierarchical' => false, 'update_term_meta_cache' => false, ) ); return ( new \WP_Term_Query( $args ) )->terms; } // phpcs:ignore Generic.Commenting.DocComment.MissingShort /** @inheritdoc */ public static function get_success_ratio() { return static::MIN_SUCCESS_URLS / static::MAX_URLS; } }