PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 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 All 508 releases
jetpack / extensions / blocks / premium-content / logged-out-view / logged-out-view.php

logged-out-view.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3, at extensions/blocks/premium-content/logged-out-view/logged-out-view.php

66 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Premium Content Logged Out View Child Block.
4 *
5 * @package automattic/jetpack
6 */
7
8 namespace Automattic\Jetpack\Extensions\Premium_Content;
9
10 use Automattic\Jetpack\Blocks;
11 use Jetpack_Gutenberg;
12
13 const LOGGEDOUT_VIEW_NAME = 'premium-content/logged-out-view';
14
15 require_once dirname( __DIR__ ) . '/_inc/access-check.php';
16
17 /**
18 * Registers the block for use in Gutenberg
19 * This is done via an action so that we can disable
20 * registration if we need to.
21 */
22 function register_loggedout_view_block() {
23 Blocks::jetpack_register_block(
24 LOGGEDOUT_VIEW_NAME,
25 array(
26 'render_callback' => __NAMESPACE__ . '\render_loggedout_view_block',
27 'uses_context' => array( 'premium-content/planId', 'premium-content/planIds' ),
28 )
29 );
30 }
31 add_action( 'init', __NAMESPACE__ . '\register_loggedout_view_block' );
32
33 /**
34 * Render callback.
35 *
36 * @param array $attributes Array containing the block attributes.
37 * @param string $content String containing the block content.
38 * @param object $block Object containing block details.
39 *
40 * @return string
41 */
42 function render_loggedout_view_block( $attributes, $content, $block = null ) {
43 if ( ! pre_render_checks() ) {
44 return '';
45 }
46
47 $visitor_has_access = current_visitor_can_access( $attributes, $block );
48
49 if ( $visitor_has_access ) {
50 // The viewer has access to premium content, so the viewer shouldn't see the logged out view.
51 return '';
52 }
53
54 Jetpack_Gutenberg::load_styles_as_required( LOGGEDOUT_VIEW_NAME );
55
56 // Old versions of the block were rendering the subscribe/login button server-side, so we need to still support them.
57 if ( ! empty( $attributes['buttonClasses'] ) ) {
58 require_once __DIR__ . '/../_inc/legacy-buttons.php';
59
60 $buttons = create_legacy_buttons_markup( $attributes, $content, $block );
61 return $content . $buttons;
62 }
63
64 return $content;
65 }
66