← All changes
|
extensions/blocks/payment-buttons/payment-buttons.php
+31
-10
13.5.2
→
16.3-a.7
View file →
| @@ -10,8 +10,12 @@ | ||
| 10 | 10 | namespace Automattic\Jetpack\Extensions\PaymentButtons; |
| 11 | 11 | |
| 12 | 12 | use Automattic\Jetpack\Blocks; |
| 13 | 13 | |
| 14 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 15 | + exit( 0 ); | |
| 16 | +} | |
| 17 | + | |
| 14 | 18 | /** |
| 15 | 19 | * Registers the block for use in Gutenberg |
| 16 | 20 | * This is done via an action so that we can disable |
| 17 | 21 | * registration if we need to. |
| @@ -16,19 +20,17 @@ | ||
| 16 | 20 | * This is done via an action so that we can disable |
| 17 | 21 | * registration if we need to. |
| 18 | 22 | */ |
| 19 | 23 | function register_block() { |
| 20 | - if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) && ! \Jetpack::is_connection_ready() ) { | |
| 21 | - return; | |
| 22 | - } | |
| 23 | - | |
| 24 | 24 | require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php'; |
| 25 | - if ( \Jetpack_Memberships::is_enabled_jetpack_recurring_payments() ) { | |
| 25 | + if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) { | |
| 26 | 26 | Blocks::jetpack_register_block( |
| 27 | 27 | __DIR__, |
| 28 | 28 | array( |
| 29 | - 'render_callback' => __NAMESPACE__ . '\render_block', | |
| 30 | - 'supports' => array( | |
| 29 | + 'render_callback' => __NAMESPACE__ . '\render_block', | |
| 30 | + 'render_email_callback' => __NAMESPACE__ . '\render_block_email', | |
| 31 | + 'plan_check' => true, | |
| 32 | + 'supports' => array( | |
| 31 | 33 | 'layout' => array( |
| 32 | 34 | 'allowSwitching' => false, |
| 33 | 35 | 'allowInheriting' => false, |
| 34 | 36 | 'default' => array( |
| @@ -40,9 +42,9 @@ | ||
| 40 | 42 | ); |
| 41 | 43 | } else { |
| 42 | 44 | $required_plan = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? 'personal-bundle' : 'jetpack_personal'; |
| 43 | 45 | \Jetpack_Gutenberg::set_extension_unavailable( |
| 44 | - Blocks::get_block_name( __DIR__ ), | |
| 46 | + 'payment-buttons', | |
| 45 | 47 | 'missing_plan', |
| 46 | 48 | array( |
| 47 | 49 | 'required_feature' => 'memberships', |
| 48 | 50 | 'required_plan' => $required_plan, |
| @@ -54,8 +56,11 @@ | ||
| 54 | 56 | |
| 55 | 57 | /** |
| 56 | 58 | * Render callback. |
| 57 | 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 | + * | |
| 58 | 63 | * @param array $attributes Array containing the block attributes. |
| 59 | 64 | * @param string $content String containing the block content. |
| 60 | 65 | * |
| 61 | 66 | * @return string |
| @@ -60,8 +65,24 @@ | ||
| 60 | 65 | * |
| 61 | 66 | * @return string |
| 62 | 67 | */ |
| 63 | 68 | function render_block( $attributes, $content ) { |
| 64 | - \Jetpack_Gutenberg::load_styles_as_required( __DIR__ ); | |
| 69 | + require_once __DIR__ . '/render.php'; | |
| 70 | + return render_block_implementation( $attributes, $content ); | |
| 71 | +} | |
| 65 | 72 | |
| 66 | - return $content; | |
| 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 ); | |
| 67 | 88 | } |