namespace WPForms\Integrations\Square\Admin\Builder;
use WPForms\Integrations\Square\Helpers;
* Square Form Builder related functionality.
* Slug of the integration.
private $slug = 'square';
* Name of the integration.
private $name = 'Square';
private $icon = WPFORMS_PLUGIN_URL . 'assets/images/addon-icon-square.png';
$this->form_data = $this->get_form_data();
private function hooks() {
add_filter( 'wpforms_payments_available', [ $this, 'register_payment' ] );
add_action( 'wpforms_payments_panel_content', [ $this, 'builder_output' ], 1 );
add_action( 'wpforms_payments_panel_sidebar', [ $this, 'builder_sidebar' ], 1 );
add_filter( 'wpforms_admin_education_addons_item_base_display_single_addon_hide', [ $this, 'should_hide_educational_menu_item' ], 10, 2 );
* Register the payment gateway.
* @param array $payments_available List of available payment gateways.
public function register_payment( $payments_available ): array {
$payments_available = (array) $payments_available;
$payments_available[ $this->slug ] = $this->name;
return $payments_available;
* Output the gateway menu item.
public function builder_sidebar() {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'builder/payment/sidebar',
'configured' => $this->is_payments_enabled() ? 'configured' : '',
* Output the gateway settings.
public function builder_output() {
<div class="wpforms-panel-content-section wpforms-panel-content-section-<?php echo esc_attr( $this->slug ); ?>"
id="<?php echo esc_attr( $this->slug ); ?>-provider" data-provider="<?php echo esc_attr( $this->slug ); ?>" data-provider-name="<?php echo esc_attr( $this->name ); ?>">
<div class="wpforms-panel-content-section-title">
<?php echo esc_html( $this->name ); ?>
<div class="wpforms-payment-settings wpforms-clear">
<?php $this->builder_content(); ?>
* Check if it is going to be displayed Square educational menu item and hide it.
* @param bool $hide Whether to hide the menu item.
* @param array $addon Addon data.
public function should_hide_educational_menu_item( $hide, array $addon ): bool {
return isset( $addon['clear_slug'] ) && $this->slug === $addon['clear_slug'] ? true : (bool) $hide;
private function get_form_data(): array {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
$form_data = wpforms()->obj( 'form' )->get(
return is_array( $form_data ) ? $form_data : [];
* Check if payments enabled.
private function is_payments_enabled(): bool {
return ! empty( $this->form_data['payments'][ $this->slug ]['enable'] ) || ! empty( $this->form_data['payments'][ $this->slug ]['enable_one_time'] );
* Get single payments conditional logic for the Square settings panel.
private function single_payments_conditional_logic_section(): string {
return $this->get_conditional_logic_toggle();
* Get education toggle for the conditional logic.
* @param bool $is_recurring Is recurring section.
private function get_conditional_logic_toggle( bool $is_recurring = false ): string {
return wpforms_panel_field(
esc_html__( 'Enable Conditional Logic', 'wpforms-lite' ),
'input_class' => 'education-modal',
'subsection' => $is_recurring ? 'recurring' : '',
'pro_badge' => ! Helpers::is_allowed_license_type(),
'data' => $this->get_conditional_logic_section_data(),
'disabled' => 'disabled',
* Get conditional logic section data.
private function get_conditional_logic_section_data(): array {
$addon = wpforms()->obj( 'addons' )->get_addon( $this->slug );
empty( $addon['action'] ) ||
empty( $addon['status'] ) || (
$addon['status'] === 'active' &&
$addon['action'] !== 'upgrade'
if ( $addon['plugin_allow'] && $addon['action'] === 'install' ) {
'message' => esc_html__( 'The Square Pro addon is required to enable conditional logic for payments. Would you like to install and activate it?', 'wpforms-lite' ),
'nonce' => wp_create_nonce( 'wpforms-admin' ),
if ( $addon['plugin_allow'] && $addon['action'] === 'activate' ) {
'message' => esc_html__( 'The Square Pro addon is required to enable conditional logic for payments. Would you like to activate it?', 'wpforms-lite' ),
'path' => $addon['path'],
'nonce' => wp_create_nonce( 'wpforms-admin' ),
'name' => esc_html__( 'Smart Conditional Logic', 'wpforms-lite' ),
'utm-content' => 'Builder Square Conditional Logic',
* Get recurring payments conditional logic for the Square settings panel.
* @param string $plan_id Plan ID.
private function recurring_payments_conditional_logic_section( string $plan_id ): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
return $this->get_conditional_logic_toggle( true );