payment-buttons.php
64 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 | /** |
| 15 | * Registers the block for use in Gutenberg |
| 16 | * This is done via an action so that we can disable |
| 17 | * registration if we need to. |
| 18 | */ |
| 19 | function register_block() { |
| 20 | require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php'; |
| 21 | if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) { |
| 22 | Blocks::jetpack_register_block( |
| 23 | __DIR__, |
| 24 | array( |
| 25 | 'render_callback' => __NAMESPACE__ . '\render_block', |
| 26 | 'supports' => array( |
| 27 | 'layout' => array( |
| 28 | 'allowSwitching' => false, |
| 29 | 'allowInheriting' => false, |
| 30 | 'default' => array( |
| 31 | 'type' => 'flex', |
| 32 | ), |
| 33 | ), |
| 34 | ), |
| 35 | ) |
| 36 | ); |
| 37 | } else { |
| 38 | $required_plan = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? 'personal-bundle' : 'jetpack_personal'; |
| 39 | \Jetpack_Gutenberg::set_extension_unavailable( |
| 40 | Blocks::get_block_name( __DIR__ ), |
| 41 | 'missing_plan', |
| 42 | array( |
| 43 | 'required_feature' => 'memberships', |
| 44 | 'required_plan' => $required_plan, |
| 45 | ) |
| 46 | ); |
| 47 | } |
| 48 | } |
| 49 | add_action( 'init', __NAMESPACE__ . '\register_block' ); |
| 50 | |
| 51 | /** |
| 52 | * Render callback. |
| 53 | * |
| 54 | * @param array $attributes Array containing the block attributes. |
| 55 | * @param string $content String containing the block content. |
| 56 | * |
| 57 | * @return string |
| 58 | */ |
| 59 | function render_block( $attributes, $content ) { |
| 60 | \Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); |
| 61 | |
| 62 | return $content; |
| 63 | } |
| 64 |