Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| WP_Core_Provider | |
0.00% |
0 / 40 |
|
0.00% |
0 / 6 |
650 | |
0.00% |
0 / 1 |
| get_critical_source_urls | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
132 | |||
| get_keys | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| get_current_storage_keys | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| get_edit_url | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| describe_key | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| get_success_ratio | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Provides core support for critical CSS |
| 4 | * |
| 5 | * @package automattic/jetpack-boost |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack_Boost\Lib\Critical_CSS\Source_Providers\Providers; |
| 9 | |
| 10 | /** |
| 11 | * Class WP_Core_Provider. |
| 12 | * |
| 13 | * @package Automattic\Jetpack_Boost\Modules\Critical_CSS\Providers |
| 14 | */ |
| 15 | class WP_Core_Provider extends Provider { |
| 16 | |
| 17 | /** |
| 18 | * Provider name. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | protected static $name = 'core'; |
| 23 | |
| 24 | // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 25 | /** @inheritdoc */ |
| 26 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 27 | public static function get_critical_source_urls( $context_posts = array() ) { |
| 28 | $urls = array(); |
| 29 | |
| 30 | $front_page = (int) get_option( 'page_on_front' ); |
| 31 | $posts_page = (int) get_option( 'page_for_posts' ); |
| 32 | |
| 33 | if ( ! empty( $front_page ) && empty( $context_posts ) ) { |
| 34 | $permalink = get_permalink( $front_page ); |
| 35 | if ( ! empty( $permalink ) ) { |
| 36 | $urls['front_page'] = array( $permalink ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | $context_post_types = wp_list_pluck( $context_posts, 'post_type' ); |
| 41 | $context_post_ids = wp_list_pluck( $context_posts, 'ID' ); |
| 42 | |
| 43 | // The blog page is only in context if the context posts include a 'post' post_type. |
| 44 | // Or, if the blog page itself is in context. |
| 45 | if ( empty( $context_post_types ) || in_array( 'post', $context_post_types, true ) || in_array( $posts_page, $context_post_ids, true ) ) { |
| 46 | if ( ! empty( $posts_page ) ) { |
| 47 | $permalink = get_permalink( $posts_page ); |
| 48 | if ( ! empty( $permalink ) ) { |
| 49 | $urls['posts_page'] = array( $permalink ); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if ( ! $front_page && ! isset( $urls['posts_page'] ) ) { |
| 55 | $urls['posts_page'] = array( home_url( '/' ) ); |
| 56 | } |
| 57 | |
| 58 | return $urls; |
| 59 | } |
| 60 | |
| 61 | // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 62 | /** @inheritdoc */ |
| 63 | public static function get_keys() { |
| 64 | $keys = array( 'posts_page' ); |
| 65 | |
| 66 | if ( ! empty( get_option( 'page_on_front' ) ) ) { |
| 67 | $keys[] = 'front_page'; |
| 68 | } |
| 69 | |
| 70 | return $keys; |
| 71 | } |
| 72 | |
| 73 | // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 74 | /** @inheritdoc */ |
| 75 | public static function get_current_storage_keys() { |
| 76 | if ( is_home() ) { |
| 77 | $key = 'posts_page'; |
| 78 | } elseif ( is_front_page() ) { |
| 79 | $key = 'front_page'; |
| 80 | } |
| 81 | |
| 82 | if ( ! isset( $key ) ) { |
| 83 | return array(); |
| 84 | } |
| 85 | |
| 86 | // For example: "core_posts_page". |
| 87 | return array( self::$name . '_' . $key ); |
| 88 | } |
| 89 | |
| 90 | // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 91 | /** @inheritdoc */ |
| 92 | public static function get_edit_url( $provider_key ) { // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 93 | if ( $provider_key === 'core_front_page' ) { |
| 94 | $front_page_id = get_option( 'page_on_front' ); |
| 95 | if ( ! empty( $front_page_id ) ) { |
| 96 | return get_edit_post_link( $front_page_id, 'link' ); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | return null; |
| 101 | } |
| 102 | |
| 103 | // phpcs:ignore |
| 104 | /** @inheritdoc */ |
| 105 | public static function describe_key( $provider_key ) { // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 106 | $page = substr( $provider_key, strlen( static::$name ) + 1 ); |
| 107 | |
| 108 | switch ( $page ) { |
| 109 | case 'posts_page': |
| 110 | return __( 'Posts page', 'jetpack-boost' ); |
| 111 | |
| 112 | case 'front_page': |
| 113 | return __( 'Front page', 'jetpack-boost' ); |
| 114 | |
| 115 | default: |
| 116 | return $provider_key; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // phpcs:ignore Generic.Commenting.DocComment.MissingShort |
| 121 | /** @inheritdoc */ |
| 122 | public static function get_success_ratio() { |
| 123 | return 1; |
| 124 | } |
| 125 | } |