PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
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 13.9.2 14.0.1 All 504 releases
← All changes | extensions/blocks/paywall/paywall.php +39 -3 12.5.2 → 16.3-a.1 View file →
@@ -10,11 +10,17 @@
10 10 namespace Automattic\Jetpack\Extensions\Paywall;
11 11
12 12 use Automattic\Jetpack\Blocks;
13 13
14 -const FEATURE_NAME = 'paywall';
15 -const BLOCK_NAME = 'jetpack/' . FEATURE_NAME;
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit( 0 );
16 +}
16 17
18 +const FEATURE_NAME = 'paywall';
19 +const BLOCK_NAME = 'jetpack/' . FEATURE_NAME;
20 +const BLOCK_HTML = '<!-- wp:' . BLOCK_NAME . ' /-->';
21 +const THE_EXCERPT_BLOCK = '[[[[[' . BLOCK_NAME . ']]]]]';
22 +
17 23 /**
18 24 * Registers the block for use in Gutenberg
19 25 * This is done via an action so that we can disable
20 26 * registration if we need to.
@@ -27,8 +33,38 @@
27 33 return;
28 34 }
29 35
30 36 Blocks::jetpack_register_block(
31 - BLOCK_NAME
37 + __DIR__,
38 + array(
39 + 'render_callback' => __NAMESPACE__ . '\render_block',
40 + )
32 41 );
33 42 }
34 43 add_action( 'init', __NAMESPACE__ . '\register_block' );
44 +
45 +/**
46 + * Paywall block render callback.
47 + *
48 + * @return string
49 + */
50 +function render_block() {
51 + if ( doing_filter( 'get_the_excerpt' ) ) {
52 + if ( \Jetpack_Memberships::user_can_view_post() ) {
53 + return '';
54 + }
55 + return THE_EXCERPT_BLOCK;
56 + }
57 + return '';
58 +}
59 +
60 +/**
61 + * Adds the Paywall block to excerpt allowed blocks.
62 + *
63 + * @param array $allowed_blocks The allowed blocks.
64 + *
65 + * @return array The allowed blocks.
66 + */
67 +function excerpt_allowed_blocks( $allowed_blocks ) {
68 + return array_merge( $allowed_blocks, array( Blocks::get_block_name( __DIR__ ) ) );
69 +}
70 +add_filter( 'excerpt_allowed_blocks', __NAMESPACE__ . '\excerpt_allowed_blocks' );