PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
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 14.1.1 All 503 releases
jetpack / extensions / blocks / paywall / paywall.php

paywall.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.1, at extensions/blocks/paywall/paywall.php

71 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Paywall Block.
4 *
5 * @since 12.5
6 *
7 * @package automattic/jetpack
8 */
9
10 namespace Automattic\Jetpack\Extensions\Paywall;
11
12 use Automattic\Jetpack\Blocks;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 0 );
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
23 /**
24 * Registers the block for use in Gutenberg
25 * This is done via an action so that we can disable
26 * registration if we need to.
27 */
28 function register_block() {
29 if ( ! \Jetpack::is_module_active( 'subscriptions' ) ) {
30 return;
31 }
32 if ( ! class_exists( '\Jetpack_Memberships' ) ) {
33 return;
34 }
35
36 Blocks::jetpack_register_block(
37 __DIR__,
38 array(
39 'render_callback' => __NAMESPACE__ . '\render_block',
40 )
41 );
42 }
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' );
71