kollapsminoriteten/wp-content/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php

102 lines
2.9 KiB
PHP
Raw Normal View History

2022-12-15 17:41:53 +01:00
<?php
/**
* Payment Buttons Block.
*
* @since 11.3
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Extensions\PaymentButtons;
use Automattic\Jetpack\Blocks;
2025-12-12 13:13:07 +01:00
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
2022-12-15 17:41:53 +01:00
/**
* Registers the block for use in Gutenberg
* This is done via an action so that we can disable
* registration if we need to.
*/
function register_block() {
require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php';
2025-02-28 08:42:11 +01:00
if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) {
2022-12-15 17:41:53 +01:00
Blocks::jetpack_register_block(
2023-12-07 09:44:11 +01:00
__DIR__,
2022-12-15 17:41:53 +01:00
array(
2025-12-12 13:13:07 +01:00
'render_callback' => __NAMESPACE__ . '\render_block',
'render_email_callback' => __NAMESPACE__ . '\render_block_email',
2026-03-31 11:30:59 +02:00
'plan_check' => true,
2025-12-12 13:13:07 +01:00
'supports' => array(
2023-12-07 09:44:11 +01:00
'layout' => array(
2022-12-15 17:41:53 +01:00
'allowSwitching' => false,
'allowInheriting' => false,
'default' => array(
'type' => 'flex',
),
),
),
)
);
} else {
$required_plan = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? 'personal-bundle' : 'jetpack_personal';
\Jetpack_Gutenberg::set_extension_unavailable(
2025-02-28 08:42:11 +01:00
'payment-buttons',
2022-12-15 17:41:53 +01:00
'missing_plan',
array(
'required_feature' => 'memberships',
'required_plan' => $required_plan,
)
);
}
}
add_action( 'init', __NAMESPACE__ . '\register_block' );
/**
* Render callback.
*
* @param array $attributes Array containing the block attributes.
* @param string $content String containing the block content.
*
* @return string
*/
function render_block( $attributes, $content ) {
2025-02-28 08:42:11 +01:00
\Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
2022-12-15 17:41:53 +01:00
return $content;
}
2025-12-12 13:13:07 +01:00
/**
* Render email callback.
*
* @param string $block_content The block content.
* @param array $parsed_block The parsed block data.
* @param object $rendering_context The email rendering context.
*
* @return string
*/
function render_block_email( $block_content, array $parsed_block, $rendering_context ) {
if ( ! class_exists( '\Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer\Layout\Flex_Layout_Renderer' ) ) {
return '';
}
// Ignore font size set on the buttons block.
// We rely on TypographyPreprocessor to set the font size on the buttons.
// Rendering font size on the wrapper causes unwanted whitespace below the buttons.
if ( isset( $parsed_block['attrs']['style']['typography']['fontSize'] ) ) {
unset( $parsed_block['attrs']['style']['typography']['fontSize'] );
}
// We are checking for the class existence above, so we know it exists.
$flex_layout_renderer = new \Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer\Layout\Flex_Layout_Renderer();
if ( ! method_exists( $flex_layout_renderer, 'render_inner_blocks_in_layout' ) ) {
return '';
}
// We are checking for the method existence above, so we know it exists.
return $flex_layout_renderer->render_inner_blocks_in_layout( $parsed_block, $rendering_context );
}