payment-buttons.php
89 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Payment Buttons Block. |
| 4 | * |
| 5 | * @since 11.3 |
| 6 | * |
| 7 | * @package automattic/jetpack |
| 8 | */ |
| 9 | |
| 10 | namespace Automattic\Jetpack\Extensions\PaymentButtons; |
| 11 | |
| 12 | use Automattic\Jetpack\Blocks; |
| 13 | |
| 14 | if ( ! 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 | */ |
| 23 | function 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 | } |
| 55 | add_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 | */ |
| 68 | function 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 | */ |
| 85 | function 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 | } |
| 89 |