namespace WPForms\Integrations\Square\Integrations;
use WPForms\Integrations\Square\Connection;
use WPForms\Integrations\Square\Helpers;
* Integration with Block Editor.
class BlockEditor implements IntegrationInterface {
* Handle name for wp_register_styles handle.
const HANDLE = 'wpforms-square-card-placeholder';
* Indicate whether current integration is allowed to load.
public function allow_load(): bool {
public function hooks() {
// Field styles for Gutenberg.
add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_assets' ] );
// Set editor style for block type editor. Must run at 20 in add-ons.
add_filter( 'register_block_type_args', [ $this, 'block_editor_assets' ], 20, 2 );
* Determine whether editor page is loaded.
public function is_editor_page(): bool {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
return defined( 'REST_REQUEST' ) && REST_REQUEST && ! empty( $_REQUEST['context'] ) && $_REQUEST['context'] === 'edit';
public function enqueue_assets() {
private function enqueue_css() {
// Do not include styles if the "Include Form Styling > No Styles" is set.
if ( wpforms_setting( 'disable-css', '1' ) === '3' ) {
$min = wpforms_get_min_suffix();
WPFORMS_PLUGIN_URL . "assets/css/integrations/square/wpforms-square{$min}.css",
WPFORMS_PLUGIN_URL . "assets/css/integrations/square/wpforms-square-card-placeholder{$min}.css",
* Set editor style for block type editor.
* @param array $args Array of arguments for registering a block type.
* @param string $block_type Block type name including namespace.
public function block_editor_assets( $args, string $block_type ): array {
if ( $block_type !== 'wpforms/form-selector' || ! is_admin() ) {
// Do not include styles if the "Include Form Styling > No Styles" is set.
if ( wpforms_setting( 'disable-css', '1' ) === '3' ) {
$min = wpforms_get_min_suffix();
WPFORMS_PLUGIN_URL . "assets/css/integrations/square/wpforms-square-card-placeholder{$min}.css",
[ $args['editor_style'] ],
$args['editor_style'] = self::HANDLE;