Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
5.71% covered (danger)
5.71%
2 / 35
33.33% covered (danger)
33.33%
1 / 3
CRAP
n/a
0 / 0
Automattic\Jetpack\Extensions\PaymentButtons\register_block
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
20
Automattic\Jetpack\Extensions\PaymentButtons\render_block
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
Automattic\Jetpack\Extensions\PaymentButtons\render_block_email
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Payment Buttons Block.
4 *
5 * @since 11.3
6 *
7 * @package automattic/jetpack
8 */
9
10namespace Automattic\Jetpack\Extensions\PaymentButtons;
11
12use Automattic\Jetpack\Blocks;
13
14if ( ! defined( 'ABSPATH' ) ) {
15    exit( 0 );
16}
17
18/**
19 * Registers the block for use in Gutenberg
20 * This is done via an action so that we can disable
21 * registration if we need to.
22 */
23function register_block() {
24    require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php';
25    if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) {
26        Blocks::jetpack_register_block(
27            __DIR__,
28            array(
29                'render_callback'       => __NAMESPACE__ . '\render_block',
30                'render_email_callback' => __NAMESPACE__ . '\render_block_email',
31                'plan_check'            => true,
32                'supports'              => array(
33                    'layout' => array(
34                        'allowSwitching'  => false,
35                        'allowInheriting' => false,
36                        'default'         => array(
37                            'type' => 'flex',
38                        ),
39                    ),
40                ),
41            )
42        );
43    } else {
44        $required_plan = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? 'personal-bundle' : 'jetpack_personal';
45        \Jetpack_Gutenberg::set_extension_unavailable(
46            'payment-buttons',
47            'missing_plan',
48            array(
49                'required_feature' => 'memberships',
50                'required_plan'    => $required_plan,
51            )
52        );
53    }
54}
55add_action( 'init', __NAMESPACE__ . '\register_block' );
56
57/**
58 * Render callback.
59 *
60 * The render implementation lives in render.php and is only loaded when the
61 * block is actually rendered, keeping it out of the eager front-end path.
62 *
63 * @param array  $attributes Array containing the block attributes.
64 * @param string $content    String containing the block content.
65 *
66 * @return string
67 */
68function render_block( $attributes, $content ) {
69    require_once __DIR__ . '/render.php';
70    return render_block_implementation( $attributes, $content );
71}
72
73/**
74 * Render email callback.
75 *
76 * The render implementation lives in render.php and is only loaded when the
77 * block is actually rendered, keeping it out of the eager front-end path.
78 *
79 * @param string $block_content The block content.
80 * @param array  $parsed_block  The parsed block data.
81 * @param object $rendering_context The email rendering context.
82 *
83 * @return string
84 */
85function render_block_email( $block_content, array $parsed_block, $rendering_context ) {
86    require_once __DIR__ . '/render.php';
87    return render_block_email_implementation( $block_content, $parsed_block, $rendering_context );
88}