PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
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 13.8.3 All 506 releases
← All changes | extensions/blocks/premium-content/premium-content.php +71 -18 12.5.2 → 16.3-a.7 View file →
@@ -8,8 +8,10 @@
8 8 namespace Automattic\Jetpack\Extensions\Premium_Content;
9 9
10 10 use Automattic\Jetpack\Blocks;
11 11 use Jetpack_Gutenberg;
12 +use WP_Post;
13 +use const Automattic\Jetpack\Extensions\Subscriptions\META_NAME_CONTAINS_PAID_CONTENT;
12 14
13 15 require_once __DIR__ . '/_inc/access-check.php';
14 16 require_once __DIR__ . '/logged-out-view/logged-out-view.php';
15 17 require_once __DIR__ . '/subscriber-view/subscriber-view.php';
@@ -14,11 +16,10 @@
14 16 require_once __DIR__ . '/logged-out-view/logged-out-view.php';
15 17 require_once __DIR__ . '/subscriber-view/subscriber-view.php';
16 18 require_once __DIR__ . '/buttons/buttons.php';
17 19 require_once __DIR__ . '/login-button/login-button.php';
20 +require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/subscriptions/constants.php';
18 21
19 -const FEATURE_NAME = 'premium-content/container';
20 -
21 22 /**
22 23 * Registers the block for use in Gutenberg
23 24 * This is done via an action so that we can disable
24 25 * registration if we need to.
@@ -23,30 +24,54 @@
23 24 * This is done via an action so that we can disable
24 25 * registration if we need to.
25 26 */
26 27 function register_block() {
27 - // Determine required `context` key based on Gutenberg version.
28 - $deprecated = function_exists( 'gutenberg_get_post_from_context' );
29 - $provides = $deprecated ? 'providesContext' : 'provides_context';
30 28
31 - Blocks::jetpack_register_block(
32 - FEATURE_NAME,
29 + require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php';
30 + if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) {
31 + Blocks::jetpack_register_block(
32 + __DIR__,
33 + array(
34 + 'render_callback' => __NAMESPACE__ . '\render_block',
35 + 'provides_context' => array(
36 + 'premium-content/planId' => 'selectedPlanId', // Deprecated.
37 + 'premium-content/planIds' => 'selectedPlanIds',
38 + 'isPremiumContentChild' => 'isPremiumContentChild',
39 + ),
40 + )
41 + );
42 + }
43 +
44 + register_post_meta(
45 + 'post',
46 + META_NAME_CONTAINS_PAID_CONTENT,
33 47 array(
34 - 'render_callback' => __NAMESPACE__ . '\render_block',
35 - 'attributes' => array(
36 - 'isPremiumContentChild' => array(
37 - 'type' => 'boolean',
38 - 'default' => true,
39 - ),
40 - ),
41 - $provides => array(
42 - 'premium-content/planId' => 'selectedPlanId',
43 - 'isPremiumContentChild' => 'isPremiumContentChild',
44 - ),
48 + 'show_in_rest' => true,
49 + 'single' => true,
50 + 'type' => 'boolean',
51 + 'auth_callback' => function () {
52 + return wp_get_current_user()->has_cap( 'edit_posts' );
53 + },
45 54 )
46 55 );
56 +
57 + // This ensures Jetpack will sync this post meta to WPCOM.
58 + add_filter(
59 + 'jetpack_sync_post_meta_whitelist',
60 + function ( $allowed_meta ) {
61 + return array_merge(
62 + $allowed_meta,
63 + array(
64 + META_NAME_CONTAINS_PAID_CONTENT,
65 + )
66 + );
67 + }
68 + );
69 +
70 + add_action( 'wp_after_insert_post', __NAMESPACE__ . '\add_paid_content_post_meta', 99, 2 );
47 71 }
48 72 add_action( 'init', __NAMESPACE__ . '\register_block' );
73 +add_action( 'template_redirect', __NAMESPACE__ . '\prewarm_premium_content_session_cookie' );
49 74
50 75 /**
51 76 * Render callback.
52 77 *
@@ -116,5 +141,33 @@
116 141 'description' => $description,
117 142 'buttonText' => $button_text,
118 143 )
119 144 );
145 +}
146 +
147 +/**
148 + * Add a meta to prevent publication on firehose, ES AI or Reader
149 + *
150 + * @param int $post_id Post id.
151 + * @param WP_Post $post Post being saved.
152 + * @return void
153 + */
154 +function add_paid_content_post_meta( int $post_id, WP_Post $post ) {
155 + if ( $post->post_type !== 'post' && $post->post_type !== 'page' ) {
156 + return;
157 + }
158 +
159 + $contains_paid_content = has_block( 'premium-content/container', $post );
160 + if ( $contains_paid_content ) {
161 + update_post_meta(
162 + $post_id,
163 + META_NAME_CONTAINS_PAID_CONTENT,
164 + $contains_paid_content
165 + );
166 + }
167 + if ( ! $contains_paid_content ) {
168 + delete_post_meta(
169 + $post_id,
170 + META_NAME_CONTAINS_PAID_CONTENT
171 + );
172 + }
120 173 }