Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
45.45% |
5 / 11 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_Token_Subscription_Service | |
55.56% |
5 / 9 |
|
25.00% |
1 / 4 |
13.62 | |
0.00% |
0 / 1 |
| available | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| get_site_id | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_key | |
66.67% |
4 / 6 |
|
0.00% |
0 / 1 |
4.59 | |||
| is_current_user_pending_subscriber | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * A paywall that exchanges JWT tokens from WordPress.com to allow |
| 4 | * a current visitor to view content that has been deemed "Premium content". |
| 5 | * |
| 6 | * @package Automattic\Jetpack\Extensions\Premium_Content |
| 7 | */ |
| 8 | |
| 9 | namespace Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service; |
| 10 | |
| 11 | use Automattic\Jetpack\Connection\Tokens; |
| 12 | use Automattic\Jetpack\Status\Host; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit( 0 ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class Jetpack_Token_Subscription_Service |
| 20 | * |
| 21 | * @package Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service |
| 22 | */ |
| 23 | class Jetpack_Token_Subscription_Service extends Abstract_Token_Subscription_Service { |
| 24 | |
| 25 | /** |
| 26 | * Is the Jetpack_Options class available? |
| 27 | * |
| 28 | * @return bool Whether Jetpack_Options class exists. |
| 29 | */ |
| 30 | public static function available() { |
| 31 | return ( new Host() )->is_wpcom_simple() || class_exists( '\Jetpack_Options' ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get the site ID. |
| 36 | * |
| 37 | * @return int The site ID. |
| 38 | */ |
| 39 | public function get_site_id() { |
| 40 | return \Jetpack_Options::get_option( 'id' ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get the key. |
| 45 | * |
| 46 | * @return string The key. |
| 47 | */ |
| 48 | public function get_key() { |
| 49 | if ( ( new Host() )->is_wpcom_simple() ) { |
| 50 | // phpcs:ignore ImportDetection.Imports.RequireImports.Symbol |
| 51 | return defined( 'EARN_JWT_SIGNING_KEY' ) ? EARN_JWT_SIGNING_KEY : false; |
| 52 | } |
| 53 | $token = ( new Tokens() )->get_access_token(); |
| 54 | if ( ! isset( $token->secret ) ) { |
| 55 | return false; |
| 56 | } |
| 57 | return $token->secret; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns true if the current authenticated user has a pending subscription to the current site. |
| 62 | * |
| 63 | * @return bool |
| 64 | */ |
| 65 | public function is_current_user_pending_subscriber(): bool { |
| 66 | |
| 67 | return self::BLOG_SUB_PENDING === $this->get_token_property( 'blog_sub' ); |
| 68 | } |
| 69 | } |