PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
jetpack / extensions / blocks / premium-content / _inc / subscription-service / class-jetpack-token-subscription-service.php

class-jetpack-token-subscription-service.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at extensions/blocks/premium-content/_inc/subscription-service/class-jetpack-token-subscription-service.php

69 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 return defined( 'EARN_JWT_SIGNING_KEY' ) ? EARN_JWT_SIGNING_KEY : false;
51 }
52 $token = ( new Tokens() )->get_access_token();
53 if ( ! isset( $token->secret ) ) {
54 return false;
55 }
56 return $token->secret;
57 }
58
59 /**
60 * Returns true if the current authenticated user has a pending subscription to the current site.
61 *
62 * @return bool
63 */
64 public function is_current_user_pending_subscriber(): bool {
65
66 return self::BLOG_SUB_PENDING === $this->get_token_property( 'blog_sub' );
67 }
68 }
69