'<label for="%s" class="wpforms-toggle-control-label">%s</label>',
$label_html .= isset( $args['tooltip'] ) ?
'<i class="fa fa-question-circle-o wpforms-help-tooltip" title="%s"></i>',
esc_attr( $args['tooltip'] )
$label_left = ! empty( $args['label-left'] ) ? $label_html . $status : '';
$label_right = empty( $args['label-left'] ) ? $status . $label_html : '';
$title = isset( $args['title'] ) ? ' title="' . esc_attr( $args['title'] ) . '"' : '';
$control_class = ! empty( $args['control-class'] ) ? $args['control-class'] : '';
$input_class = ! empty( $args['input-class'] ) ? $args['input-class'] : '';
'<span class="wpforms-toggle-control %8$s" %9$s>
<input type="checkbox" id="%2$s" name="%3$s" class="%7$s" value="1" %4$s %5$s %10$s>
<label class="wpforms-toggle-control-icon" for="%2$s"></label>
wpforms_sanitize_classes( $input_class ),
wpforms_sanitize_classes( $control_class ),
! empty( $args['disabled'] ) ? 'disabled' : ''
* Get a settings block state, whether it's opened or closed.
* @param int $form_id Form ID.
* @param int $block_id Block ID.
* @param string $block_type Block type.
function wpforms_builder_settings_block_get_state( $form_id, $block_id, $block_type ): string {
$form_id = absint( $form_id );
$block_id = absint( $block_id );
$block_type = sanitize_key( $block_type );
$all_states = get_user_meta( get_current_user_id(), 'wpforms_builder_settings_collapsable_block_states', true );
if ( empty( $all_states ) ) {
is_array( $all_states ) &&
! empty( $all_states[ $form_id ][ $block_type ][ $block_id ] ) &&
$all_states[ $form_id ][ $block_type ][ $block_id ] === 'closed'
// Backward compatibility for notifications.
if ( $block_type === 'notification' && $state !== 'closed' ) {
$notification_states = get_user_meta( get_current_user_id(), 'wpforms_builder_notification_states', true );
! empty( $notification_states[ $form_id ][ $block_id ] ) &&
$notification_states[ $form_id ][ $block_id ] === 'closed'
if ( $block_type === 'notification' ) {
// Backward compatibility for notifications.
* Filters notification get state.
* @param string $state Notification get state.
* @param int $form_id Form ID.
* @param int $block_id Block ID.
return (string) apply_filters( 'wpforms_builder_notification_get_state', $state, $form_id, $block_id ); // phpcs:ignore WPForms.Formatting.EmptyLineBeforeReturn.RemoveEmptyLineBeforeReturnStatement
* Filters settings block state.
* @param string $state Settings block state.
* @param int $form_id Form ID.
* @param int $block_id Block ID.
* @param string $block_type Block type.
return apply_filters( 'wpforms_builder_settings_block_get_state', $state, $form_id, $block_id, $block_type );
* Get the list of allowed tags, used in a pair with the wp_kses () function.
* This allows removing of all potentially harmful HTML tags and attributes.
* @return array Allowed Tags.
function wpforms_builder_preview_get_allowed_tags(): array {
if ( ! empty( $allowed_tags ) ) {
$atts = [ 'align', 'class', 'type', 'id', 'for', 'style', 'src', 'rel', 'href', 'target', 'value', 'width', 'height' ];
$tags = [ 'label', 'iframe', 'style', 'button', 'strong', 'small', 'table', 'span', 'abbr', 'code', 'pre', 'div', 'img', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'li', 'em', 'hr', 'br', 'th', 'tr', 'td', 'p', 'a', 'b', 'i' ];
$allowed_atts = array_fill_keys( $atts, [] );
$allowed_tags = array_fill_keys( $tags, $allowed_atts );
* Output builder panel fields group wrapper.
* @param string $inner Inner HTML to wrap.
* @param array $args Array of arguments.
* @param bool $do_echo Flag to display.
* @noinspection HtmlUnknownAttribute
function wpforms_panel_fields_group( $inner, $args = [], $do_echo = true ): ?string { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
$group = ! empty( $args['group'] ) ? $args['group'] : '';
$unfoldable = ! empty( $args['unfoldable'] );
$default = ( ! empty( $args['default'] ) && $args['default'] === 'opened' ) ? ' opened' : '';
$opened = ! empty( $_COOKIE[ 'wpforms_fields_group_' . $group ] ) && $_COOKIE[ 'wpforms_fields_group_' . $group ] === 'true' ? ' opened' : $default;
$class = ! empty( $args['class'] ) ? wpforms_sanitize_classes( $args['class'] ) : '';
'<div class="wpforms-panel-fields-group %1$s%2$s" %3$s>',
$unfoldable ? ' unfoldable' . $opened : '',
$unfoldable ? ' data-group="' . $group . '"' : ''
if ( ! empty( $args['borders'] ) && in_array( 'top', $args['borders'], true ) ) {
$output .= '<div class="wpforms-panel-fields-group-border-top"></div>';
if ( ! empty( $args['title'] ) ) {
$chevron = $unfoldable ? '<i class="fa fa-chevron-circle-right"></i>' : '';
$output .= '<div class="wpforms-panel-fields-group-title">' . esc_html( $args['title'] ) . $chevron . '</div>';
if ( ! empty( $args['description'] ) ) {
$output .= '<div class="wpforms-panel-fields-group-description">' . wp_kses_post( $args['description'] ) . '</div>';
'<div class="wpforms-panel-fields-group-inner" %s>%s</div>',
empty( $opened ) && $unfoldable ? ' style="display: none;"' : '',
if ( ! empty( $args['borders'] ) && in_array( 'bottom', $args['borders'], true ) ) {
$output .= '<div class="wpforms-panel-fields-group-border-bottom"></div>';
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
* Get the pages for the "Show Page" dropdown selection in Confirmations Settings in Builder.
* @param array $form_data Form data.
* @param int $confirmation_id Confirmation ID.
function wpforms_builder_form_settings_confirmation_get_pages( $form_data, $confirmation_id ): array {
$pre_selected_page_id = empty( $form_data['settings']['confirmations'][ $confirmation_id ]['page'] ) ? 0 : absint( $form_data['settings']['confirmations'][ $confirmation_id ]['page'] );
$pages = wp_list_pluck( wpforms_search_posts(), 'post_title', 'ID' );
if ( empty( $pre_selected_page_id ) || isset( $pages[ $pre_selected_page_id ] ) ) {
// If the pre-selected page isn't in `$pages`, we manually fetch it include it in `$pages`.
$pre_selected_page = get_post( $pre_selected_page_id );
if ( empty( $pre_selected_page ) ) {
$pages[ $pre_selected_page->ID ] = wpforms_get_post_title( $pre_selected_page );
* Generates an image upload control for WPForms builder panels.
* @param string $option Field type.
* @param array $args Arguments for the control:
* - default_id - Default image ID if no value is set.
* - default_size - Default image size ('full', 'large', 'medium', 'small').
* - default_position - Default image position ('left', 'center', 'right').
* - default_url - Default image URL if no value is set.
* @param string $panel Panel name.
* @param string $parent_name Parent field name.
* @param string $field Field name.
* @param array $form Form data.
* @param string $field_name Field name attribute.
* @param string $input_id Input ID attribute.
* @return string HTML markup for the image upload control.
function wpforms_panel_field_image_upload_control( // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
// Handle subsection, which is the primary use case.
$subsection = ! empty( $args['subsection'] ) ? $args['subsection'] : '';
// Set default values from args if they exist.
$image_id = ! empty( $args['default_id'] ) ? $args['default_id'] : 0;
$image_size = ! empty( $args['default_size'] ) ? $args['default_size'] : 'medium';
$image_position = ! empty( $args['default_position'] ) ? $args['default_position'] : 'left';
$image_url = ! empty( $args['default_url'] ) ? $args['default_url'] : '';
$hidden_fields = ! empty( $args['hidden_fields'] ) ? $args['hidden_fields'] : [];
$key_id = $field . '_id';
$key_size = $field . '_size';
$key_position = $field . '_position';
$key_url = $field . '_url';
// Get stored values if they exist.
isset( $form[ $parent_name ][ $panel ][ $subsection ][ $key_url ] )
$image_id = absint( $form[ $parent_name ][ $panel ][ $subsection ][ $key_id ] ?? $image_id );
$image_size = $form[ $parent_name ][ $panel ][ $subsection ][ $key_size ] ?? $image_size;
$image_position = $form[ $parent_name ][ $panel ][ $subsection ][ $key_position ] ?? $image_position;
$image_url = $form[ $parent_name ][ $panel ][ $subsection ][ $key_url ];
// Check if we have an image.
$has_image = ! empty( $image_id ) || ! empty( $image_url );
if ( ! empty( $image_id ) && empty( $image_url ) ) {
$image_attributes = wp_get_attachment_image_src( $image_id, 'full' );
if ( $image_attributes ) {
$image_url = $image_attributes[0];
// The image doesn't exist or is invalid.
// Determine button visibility classes.
$upload_button_class = $has_image ? 'wpforms-image-upload-button wpforms-hidden' : 'wpforms-image-upload-button';
$remove_button_class = $has_image ? 'wpforms-image-remove-button' : 'wpforms-image-remove-button wpforms-hidden';
// Set preview image source.
$preview_src = $has_image && $image_url ? $image_url : '';
// Define standard sizes.
'full' => esc_html__( 'Full', 'wpforms-lite' ),
'large' => esc_html__( 'Large', 'wpforms-lite' ),
'medium' => esc_html__( 'Medium', 'wpforms-lite' ),
'small' => esc_html__( 'Small', 'wpforms-lite' ),
// Define standard positions.
'left' => esc_html__( 'Left', 'wpforms-lite' ),
'center' => esc_html__( 'Center', 'wpforms-lite' ),
'right' => esc_html__( 'Right', 'wpforms-lite' ),
// Prepare the field name prefix. Remove the square bracket at the end if present.
$field_name_prefix = preg_replace( '/]$/', '', $field_name );
// Start output buffering to capture HTML.
class="wpforms-setting-field wpforms-setting-field-image-upload <?php echo sanitize_html_class( $option ); ?>"
id="wpforms-setting-field-<?php echo esc_attr( $input_id ); ?>">
<div class="wpforms-setting-content">
<div class="wpforms-image-upload-control" id="<?php echo esc_attr( $input_id ); ?>-control">
<div class="wpforms-image-preview" aria-live="polite">
src="<?php echo esc_url( $preview_src ); ?>"
alt="<?php echo $has_image ? esc_attr__( 'Preview of selected image', 'wpforms-lite' ) : esc_attr__( 'No image selected', 'wpforms-lite' ); ?>">
<div class="wpforms-image-controls">
<?php if ( ! in_array( 'size', $hidden_fields, true ) ) : ?>
<div class="wpforms-image-control-group">
<label for="<?php echo esc_attr( $input_id ); ?>_size"><?php echo esc_html__( 'Size', 'wpforms-lite' ); ?></label>
<select id="<?php echo esc_attr( $input_id ); ?>_size" name="<?php echo esc_attr( $field_name_prefix . '_size]' ); ?>">
<?php foreach ( $sizes as $value => $label ) : ?>
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $image_size, $value ); ?>>
<?php echo esc_html( $label ); ?>
<?php if ( ! in_array( 'position', $hidden_fields, true ) ) : ?>
<div class="wpforms-image-control-group">
<label for="<?php echo esc_attr( $input_id ); ?>_position"><?php echo esc_html__( 'Position', 'wpforms-lite' ); ?></label>
<select id="<?php echo esc_attr( $input_id ); ?>_position" name="<?php echo esc_attr( $field_name_prefix . '_position]' ); ?>">
<?php foreach ( $positions as $value => $label ) : ?>
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $image_position, $value ); ?>>
<?php echo esc_html( $label ); ?>
<div class="wpforms-image-buttons">
class="<?php echo esc_attr( $upload_button_class ); ?> wpforms-btn wpforms-btn-sm wpforms-btn-light-grey"
aria-label="<?php esc_attr_e( 'Upload an image', 'wpforms-lite' ); ?>">
<?php echo esc_html__( 'Upload Image', 'wpforms-lite' ); ?>
class="<?php echo esc_attr( $remove_button_class ); ?> wpforms-btn wpforms-btn-sm wpforms-btn-light-grey"
aria-label="<?php esc_attr_e( 'Remove the selected image', 'wpforms-lite' ); ?>">
<?php echo esc_html__( 'Remove Image', 'wpforms-lite' ); ?>
class="wpforms-image-upload-id"
id="<?php echo esc_attr( $input_id ); ?>_id"
name="<?php echo esc_attr( $field_name_prefix . '_id]' ); ?>"
value="<?php echo esc_attr( $image_id ); ?>">
class="wpforms-image-upload-url"
id="<?php echo esc_attr( $input_id ); ?>_url"
name="<?php echo esc_attr( $field_name_prefix . '_url]' ); ?>"
value="<?php echo esc_attr( $image_url ); ?>">
// Return the captured HTML.