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-wpcom-offline-subscription-service.php

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

71 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This subscription service is used when a subscriber is offline and a token is not available.
4 *
5 * @package Automattic\Jetpack\Extensions\Premium_Content
6 */
7
8 namespace Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service;
9
10 use const Automattic\Jetpack\Extensions\Subscriptions\META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit( 0 );
14 }
15
16 /**
17 * Class WPCOM_Offline_Subscription_Service
18 * This subscription service is used when a subscriber is offline and a token is not available.
19 * This subscription service will be used when sending emails to subscribers
20 *
21 * @package Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service
22 */
23 class WPCOM_Offline_Subscription_Service extends WPCOM_Online_Subscription_Service {
24
25 /**
26 * Is available()
27 *
28 * @return bool
29 */
30 public static function available() {
31 // Return available if the user is logged in and we are on WPCOM.
32 return false;
33 }
34
35 /**
36 * Check if the subscriber can receive the newsletter.
37 * This is the only method where is user does not need to be logged in.
38 *
39 * @param int $user_id User id.
40 * @param int $post_id Post id.
41 *
42 * @return bool
43 * @throws \Exception Throws an exception when used outside of WPCOM.
44 */
45 public function subscriber_can_receive_post_by_mail( $user_id, $post_id ) {
46
47 if ( 0 === $user_id || empty( $user_id ) ) {
48 // Email cannot be sent to non-users
49 return false;
50 }
51
52 $previous_user = wp_get_current_user();
53 wp_set_current_user( $user_id );
54
55 $access_level = get_post_meta( $post_id, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true );
56
57 if ( ! $access_level || self::POST_ACCESS_LEVEL_EVERYBODY === $access_level ) {
58 // The post is not gated, we return early
59 return true;
60 }
61
62 $valid_plan_ids = \Jetpack_Memberships::get_all_newsletter_plan_ids();
63 $is_blog_subscriber = true; // it is a subscriber as this is used in async when lopping through subscribers...
64 $allowed = $this->user_can_view_content( $valid_plan_ids, $access_level, $is_blog_subscriber, $post_id );
65
66 wp_set_current_user( $previous_user->ID );
67
68 return $allowed;
69 }
70 }
71