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 +33 -20 13.3.3 → 16.3-a.7 View file →
@@ -24,23 +24,23 @@
24 24 * This is done via an action so that we can disable
25 25 * registration if we need to.
26 26 */
27 27 function register_block() {
28 - // Determine required `context` key based on Gutenberg version.
29 - $deprecated = function_exists( 'gutenberg_get_post_from_context' );
30 - $provides = $deprecated ? 'providesContext' : 'provides_context';
31 28
32 - Blocks::jetpack_register_block(
33 - __DIR__,
34 - array(
35 - 'render_callback' => __NAMESPACE__ . '\render_block',
36 - $provides => array(
37 - 'premium-content/planId' => 'selectedPlanId', // Deprecated.
38 - 'premium-content/planIds' => 'selectedPlanIds',
39 - 'isPremiumContentChild' => 'isPremiumContentChild',
40 - ),
41 - )
42 - );
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 43
44 44 register_post_meta(
45 45 'post',
46 46 META_NAME_CONTAINS_PAID_CONTENT,
@@ -66,11 +66,12 @@
66 66 );
67 67 }
68 68 );
69 69
70 - add_action( 'save_post_post', __NAMESPACE__ . '\add_paid_content_post_meta', 99, 2 );
70 + add_action( 'wp_after_insert_post', __NAMESPACE__ . '\add_paid_content_post_meta', 99, 2 );
71 71 }
72 72 add_action( 'init', __NAMESPACE__ . '\register_block' );
73 +add_action( 'template_redirect', __NAMESPACE__ . '\prewarm_premium_content_session_cookie' );
73 74
74 75 /**
75 76 * Render callback.
76 77 *
@@ -150,11 +151,23 @@
150 151 * @param WP_Post $post Post being saved.
151 152 * @return void
152 153 */
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 +
154 159 $contains_paid_content = has_block( 'premium-content/container', $post );
155 - update_post_meta(
156 - $post_id,
157 - META_NAME_CONTAINS_PAID_CONTENT,
158 - $contains_paid_content
159 - );
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 + }
160 173 }