Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 46 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| Archive_Provider | |
0.00% |
0 / 46 |
|
0.00% |
0 / 7 |
240 | |
0.00% |
0 / 1 |
| get_critical_source_urls | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| get_current_storage_keys | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| get_keys | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_edit_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| describe_key | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| get_post_types | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
6 | |||
| get_success_ratio | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Archive provider class. |
| 4 | * |
| 5 | * @package automattic/jetpack-boost |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack_Boost\Lib\Critical_CSS\Source_Providers\Providers; |
| 9 | |
| 10 | /** |
| 11 | * Class Archive_Provider |
| 12 | * |
| 13 | * @package Automattic\Jetpack_Boost\Modules\Critical_CSS\Providers |
| 14 | */ |
| 15 | class Archive_Provider extends Provider { |
| 16 | |
| 17 | /** |
| 18 | * Provider name. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | protected static $name = 'archive'; |
| 23 | |
| 24 | // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 25 | /** @inheritdoc */ |
| 26 | public static function get_critical_source_urls( $context_posts = array() ) { // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 27 | $links = array(); |
| 28 | $context_post_types = wp_list_pluck( $context_posts, 'post_type' ); |
| 29 | |
| 30 | $post_types = self::get_post_types(); |
| 31 | if ( ! empty( $context_post_types ) ) { |
| 32 | $post_types = array_intersect( $post_types, $context_post_types ); |
| 33 | } |
| 34 | foreach ( $post_types as $post_type ) { |
| 35 | $link = get_post_type_archive_link( $post_type ); |
| 36 | |
| 37 | if ( ! empty( $link ) ) { |
| 38 | $links[ $post_type ][] = $link; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return $links; |
| 43 | } |
| 44 | |
| 45 | // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 46 | /** @inheritdoc */ |
| 47 | public static function get_current_storage_keys() { |
| 48 | if ( ! is_archive() ) { |
| 49 | return array(); |
| 50 | } |
| 51 | |
| 52 | // For example: "archive_post". |
| 53 | return array( self::$name . '_' . get_post_type() ); |
| 54 | } |
| 55 | |
| 56 | // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 57 | /** @inheritdoc */ |
| 58 | public static function get_keys() { // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 59 | return self::get_post_types(); |
| 60 | } |
| 61 | |
| 62 | // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 63 | /** @inheritdoc */ |
| 64 | public static function get_edit_url( $_provider_key ) { // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 65 | return null; |
| 66 | } |
| 67 | |
| 68 | // phpcs:ignore |
| 69 | /** @inheritdoc */ |
| 70 | public static function describe_key( $provider_key ) { // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 71 | $post_type = substr( $provider_key, strlen( static::$name ) + 1 ); |
| 72 | |
| 73 | switch ( $post_type ) { |
| 74 | case 'post': |
| 75 | return __( 'Post archive view', 'jetpack-boost' ); |
| 76 | |
| 77 | case 'page': |
| 78 | return __( 'Page archive view', 'jetpack-boost' ); |
| 79 | |
| 80 | default: |
| 81 | return __( 'Archive page for custom post type', 'jetpack-boost' ); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Get post types that need Critical CSS. |
| 87 | * |
| 88 | * @return mixed|void |
| 89 | */ |
| 90 | public static function get_post_types() { |
| 91 | $post_types = get_post_types( |
| 92 | array( |
| 93 | 'public' => true, |
| 94 | 'has_archive' => true, |
| 95 | ), |
| 96 | 'objects' |
| 97 | ); |
| 98 | unset( $post_types['attachment'] ); |
| 99 | |
| 100 | $post_types = array_filter( $post_types, 'is_post_type_viewable' ); |
| 101 | |
| 102 | $provider_post_types = array(); |
| 103 | // Generate a name => name array for backwards compatibility. |
| 104 | foreach ( $post_types as $post_type ) { |
| 105 | $provider_post_types[ $post_type->name ] = $post_type->name; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Filters the post types used for Critical CSS |
| 110 | * |
| 111 | * @param array $post_types The array of post types to be used |
| 112 | * |
| 113 | * @since 1.0.0 |
| 114 | */ |
| 115 | return apply_filters( |
| 116 | 'jetpack_boost_critical_css_post_types_archives', |
| 117 | apply_filters_deprecated( |
| 118 | 'jetpack_boost_critical_css_post_types', |
| 119 | array( |
| 120 | $provider_post_types, |
| 121 | ), |
| 122 | '3.4.0', |
| 123 | 'jetpack_boost_critical_css_post_types_archives' |
| 124 | ), |
| 125 | $post_types |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 130 | /** @inheritdoc */ |
| 131 | public static function get_success_ratio() { // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 132 | return 1; |
| 133 | } |
| 134 | } |