← All changes
|
extensions/blocks/premium-content/_inc/subscription-service/interface-subscription-service.php
+72
-0
16.2-beta
→
16.3
View file →
| @@ -1,0 +1,72 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * The Subscription Service represents the entity responsible for making sure a visitor | |
| 4 | + * can see blocks that are considered premium content. | |
| 5 | + * | |
| 6 | + * If a visitor is not allowed to see they need to be given a way gain access. | |
| 7 | + * | |
| 8 | + * It is assumed that it will be a monetary exchange but that is up to the host | |
| 9 | + * that brokers the content exchange. | |
| 10 | + * | |
| 11 | + * @package Automattic\Jetpack\Extensions\Premium_Content; | |
| 12 | + */ | |
| 13 | + | |
| 14 | +namespace Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service; | |
| 15 | + | |
| 16 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 17 | + exit( 0 ); | |
| 18 | +} | |
| 19 | + | |
| 20 | +interface Subscription_Service { | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * The subscription service can be used. | |
| 24 | + * | |
| 25 | + * @return bool | |
| 26 | + */ | |
| 27 | + public static function available(); | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Allows a Subscription Service to setup anything it needs to provide its features. | |
| 31 | + * | |
| 32 | + * This is called during an `init` action hook callback. | |
| 33 | + * | |
| 34 | + * Examples of things a Service may want to do here: | |
| 35 | + * - Determine a visitor is arriving with a new token to unlock content and | |
| 36 | + * store the token for future browsing (e.g. in a cookie) | |
| 37 | + * - Set up WP-API endpoints necessary for the function to work | |
| 38 | + * - Token refreshes | |
| 39 | + * | |
| 40 | + * @return void | |
| 41 | + */ | |
| 42 | + public function initialize(); | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Given a token (this could be from a cookie, a querystring, or some other means) | |
| 46 | + * can the visitor see the premium content? | |
| 47 | + * | |
| 48 | + * Implementations may accept an optional third `$post_id` for checks outside the loop. It is not | |
| 49 | + * declared here because existing two-argument implementers would then fatal as incompatible. | |
| 50 | + * | |
| 51 | + * @param array $valid_plan_ids . | |
| 52 | + * @param string $access_level . | |
| 53 | + * | |
| 54 | + * @return bool | |
| 55 | + */ | |
| 56 | + public function visitor_can_view_content( $valid_plan_ids, $access_level ); | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Is the current user a pending subscriber for the current site? | |
| 60 | + * | |
| 61 | + * @return bool | |
| 62 | + */ | |
| 63 | + public function is_current_user_pending_subscriber(): bool; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * The current visitor would like to obtain access. Where do they go? | |
| 67 | + * | |
| 68 | + * @param string $mode . | |
| 69 | + * @return string | |
| 70 | + */ | |
| 71 | + public function access_url( $mode = 'subscribe' ); | |
| 72 | +} | |