core = $core;
if ( ! empty( $_GET['form_id'] ) ) { // phpcs:ignore
$this->form_data = \wpforms()->form->get(
\absint( $_GET['form_id'] ), // phpcs:ignore
array(
'content_only' => true,
)
);
}
$this->init_hooks();
}
/**
* Register all hooks (actions and filters) here.
*
* @since 1.4.7
*/
protected function init_hooks() {
// Register builder HTML template(s).
\add_action( 'wpforms_builder_print_footer_scripts', array( $this, 'builder_templates' ), 10 );
\add_action( 'wpforms_builder_print_footer_scripts', array( $this, 'builder_custom_templates' ), 11 );
// Process builder AJAX requests.
\add_action( "wp_ajax_wpforms_builder_provider_ajax_{$this->core->slug}", array( $this, 'process_ajax' ) );
/*
* Enqueue assets.
*/
if (
( ! empty( $_GET['page'] ) && $_GET['page'] === 'wpforms-builder' ) && // phpcs:ignore
! empty( $_GET['form_id'] ) && // phpcs:ignore
\is_admin()
) {
\add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
}
}
/**
* Used to register generic templates for all providers inside form builder.
*
* @since 1.4.7
* @since 1.6.2 Added sub-templates for conditional logic based on provider.
*/
public function builder_templates() {
$cl_builder_block = wpforms_conditional_logic()->builder_block(
array(
'form' => $this->form_data,
'type' => 'panel',
'parent' => 'providers',
'panel' => esc_attr( $this->core->slug ),
'subsection' => '%connection_id%',
'reference' => esc_html__( 'Marketing provider connection', 'wpforms-lite' ),
),
false
);
?>
\esc_html__( 'You do not have permission to perform this action.', 'wpforms-lite' ),
)
);
}
// Process required values.
$error = array( 'error' => \esc_html__( 'Something went wrong while performing an AJAX request.', 'wpforms-lite' ) );
if (
empty( $_POST['id'] ) ||
empty( $_POST['task'] )
) {
\wp_send_json_error( $error );
}
$form_id = (int) $_POST['id'];
$task = \sanitize_key( $_POST['task'] );
$data = null;
// Setup form data based on the ID, that we got from AJAX request.
$this->form_data = \wpforms()->form->get(
$form_id,
array(
'content_only' => true,
)
);
// Do not allow to proceed further, as form_id may be incorrect.
if ( empty( $this->form_data ) ) {
\wp_send_json_error( $error );
}
$data = \apply_filters(
'wpforms_providers_settings_builder_ajax_' . $task . '_' . $this->core->slug,
null
);
if ( null !== $data ) {
\wp_send_json_success( $data );
}
\wp_send_json_error( $error );
}
/**
* Display content inside the panel sidebar area.
*
* @since 1.4.7
*/
public function display_sidebar() {
$configured = '';
if ( ! empty( $this->form_data['id'] ) && Status::init( $this->core->slug )->is_ready( $this->form_data['id'] ) ) {
$configured = 'configured';
}
$classes = array(
'wpforms-panel-sidebar-section',
'icon',
$configured,
'wpforms-panel-sidebar-section-' . $this->core->slug,
);
?>
core->name ); ?>