use WPForms\Admin\Education\Helpers as EducationHelpers;
* Settings output wrapper.
* @param array $args Arguments.
function wpforms_settings_output_field( array $args ): string {
// Define default callback for this field type.
$callback = ! empty( $args['type'] ) && function_exists( 'wpforms_settings_' . $args['type'] . '_callback' ) ? 'wpforms_settings_' . $args['type'] . '_callback' : 'wpforms_settings_missing_callback';
// Allow custom callback to be provided via arg.
if ( ! empty( $args['callback'] ) && function_exists( $args['callback'] ) ) {
$callback = $args['callback'];
// Store returned markup from callback.
$field = $callback( $args );
// Allow arg to bypass standard field wrap for custom display.
if ( ! empty( $args['wrap'] ) ) {
"wpforms-setting-row-{$args['type']}",
$wrapper_attributes = wpforms_html_attributes(
'wpforms-setting-row-' . wpforms_sanitize_key( $args['id'] ),
! empty( $args['class'] ) ? array_merge( $class, (array) $args['class'] ) : $class,
! empty( $args['data_attributes'] ) && is_array( $args['data_attributes'] ) ? $args['data_attributes'] : [],
! empty( $args['is_hidden'] ) ? [ 'style' => 'display:none;' ] : []
// Build standard field markup and return.
$output = "<div {$wrapper_attributes}>";
if ( ! empty( $args['name'] ) && empty( $args['no_label'] ) ) {
$output .= '<span class="wpforms-setting-label">';
$output .= '<label for="wpforms-setting-' . wpforms_sanitize_key( $args['id'] ) . '">' . esc_html( $args['name'] );
// Add education badge, if needed.
// The badge should be added after the label text, but before the label closing tag.
if ( ! empty( $args['education_badge'] ) ) {
$output .= wp_kses( $args['education_badge'], [ 'span' => [ 'class' => [] ] ] );
$output .= '<span class="wpforms-setting-field">';
if ( ! empty( $args['desc_after'] ) ) {
$output .= '<div class="wpforms-clear">' . $args['desc_after'] . '</div>';
* If a function is missing for settings, callbacks alert the user.
* @param array $args Arguments passed by the setting.
function wpforms_settings_missing_callback( array $args ): string {
/* translators: %s - ID of a setting. */
esc_html__( 'The callback function used for the %s setting is missing.', 'wpforms-lite' ),
'<strong>' . wpforms_sanitize_key( $args['id'] ) . '</strong>'
* Settings content field callback.
* @param array $args Arguments.
function wpforms_settings_content_callback( array $args ): string {
return ! empty( $args['content'] ) ? $args['content'] : '';
* Settings license field callback.
* @param array $args Settings arguments.
* @noinspection HtmlUnknownTarget
* @noinspection PhpUnusedParameterInspection
function wpforms_settings_license_callback( array $args ): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
$output = '<p>' . esc_html__( 'You\'re using WPForms Lite - no license needed. Enjoy!', 'wpforms-lite' ) . ' 🙂</p>';
wp_kses( /* translators: %s - WPForms.com upgrade URL. */
__( 'To unlock more features consider <strong><a href="%s" target="_blank" rel="noopener noreferrer" class="wpforms-upgrade-modal">upgrading to PRO</a></strong>.', 'wpforms-lite' ),
esc_url( wpforms_admin_upgrade_link( 'settings-license', 'Upgrade to WPForms Pro text Link' ) )
'<p class="discount-note">' .
__( 'As a valued WPForms Lite user you receive <strong>50% off</strong>, automatically applied at checkout!', 'wpforms-lite' ),
$output .= '<hr><p>' . esc_html__( 'Already purchased? Simply enter your license key below to enable WPForms PRO!', 'wpforms-lite' ) . '</p>';
$output .= '<input type="password" spellcheck="false" id="wpforms-settings-upgrade-license-key" placeholder="' . esc_attr__( 'Paste license key here', 'wpforms-lite' ) . '" value="">';
$output .= '<button class="wpforms-btn wpforms-btn-md wpforms-btn-blue" id="wpforms-settings-connect-btn">' . esc_html__( 'Verify Key', 'wpforms-lite' ) . '</button>';
* Filter license settings HTML output.
* @param string $output HTML markup to be rendered in place of license settings.
return (string) apply_filters( 'wpforms_settings_license_output', $output );
* Settings text input field callback.
* @param array $args Settings arguments.
function wpforms_settings_text_callback( array $args ): string {
if ( ! in_array( $args['type'], [ 'text', 'password' ], true ) ) {
$default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
$value = wpforms_setting( $args['id'], $default );
$id = wpforms_sanitize_key( $args['id'] );
$output = '<input type="' . esc_attr( $args['type'] ) . '" id="wpforms-setting-' . $id . '" name="' . $id . '" value="' . esc_attr( $value ) . '">';
if ( ! empty( $args['desc'] ) ) {
$output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
* Settings password input field callback.
* @param array $args Setting field arguments.
function wpforms_settings_password_callback( array $args ): string {
return wpforms_settings_text_callback( $args );
* Settings number input field callback.
* @param array $args Setting field arguments.
* @noinspection HtmlUnknownAttribute
function wpforms_settings_number_callback( array $args ): string {
$default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
$id = 'wpforms-setting-' . wpforms_sanitize_key( $args['id'] );
'value' => wpforms_setting( $args['id'], $default ),
'name' => wpforms_sanitize_key( $args['id'] ),
$data = ! empty( $args['data'] ) ? $args['data'] : [];
if ( ! empty( $args['attr'] ) ) {
$attr = array_merge( $attr, $args['attr'] );
'<input type="number" %s>',
wpforms_html_attributes( $id, [], $data, $attr )
if ( ! empty( $args['desc'] ) ) {
$output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
* Settings select field callback.
* @param array $args Arguments.
function wpforms_settings_select_callback( array $args ): string { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
$default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
$value = wpforms_setting( $args['id'], $default );
$id = wpforms_sanitize_key( $args['id'] );
$class = ! empty( $args['choicesjs'] ) ? 'choicesjs-select' : '';
$choices = ! empty( $args['choicesjs'] );
$data = isset( $args['data'] ) ? (array) $args['data'] : [];
$attr = isset( $args['attr'] ) ? (array) $args['attr'] : [];
if ( $choices && ! empty( $args['search'] ) ) {
$data['search'] = 'true';
if ( ! empty( $args['placeholder'] ) ) {
$data['placeholder'] = $args['placeholder'];
if ( $choices && ! empty( $args['multiple'] ) ) {
$select_name = $id . '[]';
$size_attr = ' size="1"';
foreach ( $data as $name => $val ) {
$data[ $name ] = 'data-' . sanitize_html_class( $name ) . '="' . esc_attr( $val ) . '"';
$data = implode( ' ', $data );
$attr = implode( ' ', array_map( 'sanitize_html_class', $attr ) );
$output = $choices ? '<span class="choicesjs-select-wrap">' : '';
$output .= '<select id="wpforms-setting-' . $id . '" name="' . $select_name . '" class="' . $class . '"' . $data . $attr . $size_attr . '>';
foreach ( $args['options'] as $option => $name ) {
if ( empty( $args['selected'] ) ) {
$selected = selected( $value, $option, false );
$selected = is_array( $args['selected'] ) && in_array( $option, $args['selected'], true ) ? 'selected' : '';
$output .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
$output .= $choices ? '</span>' : '';
if ( ! empty( $args['desc'] ) ) {
$output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
* Settings checkbox field callback.
* @param array $args Arguments.
function wpforms_settings_checkbox_callback( array $args ): string {
$value = wpforms_setting( $args['id'] );
$id = wpforms_sanitize_key( $args['id'] );
$checked = ! empty( $value ) ? checked( 1, $value, false ) : '';
$disabled = ! empty( $args['disabled'] ) ? ' disabled' : '';
$output = '<input type="checkbox" id="wpforms-setting-' . $id . '" name="' . $id . '" ' . $checked . $disabled . '>';
if ( ! empty( $args['desc'] ) ) {
$output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
if ( ! empty( $args['disabled_desc'] ) ) {
$output .= '<p class="disabled-desc">' . wp_kses_post( $args['disabled_desc'] ) . '</p>';
* Settings radio field callback.
* @param array $args Arguments.
function wpforms_settings_radio_callback( array $args ): string {
$default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
$value = wpforms_setting( $args['id'], $default );
$id = wpforms_sanitize_key( $args['id'] );
foreach ( $args['options'] as $option => $name ) {
$checked = checked( $value, $option, false );
$output .= '<span class="wpforms-settings-field-radio-wrapper">';
$output .= '<input type="radio" id="wpforms-setting-' . $id . '[' . $x . ']" name="' . $id . '" value="' . esc_attr( $option ) . '" ' . $checked . '>';
$output .= '<label for="wpforms-setting-' . $id . '[' . $x . ']" class="option-' . sanitize_html_class( $option ) . '">';
$output .= esc_html( $name );
if ( ! empty( $args['desc'] ) ) {
$output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
* Email template endpoint field callback.
* @param array $args Field arguments.
function wpforms_settings_email_template_callback( array $args ): string {
$id = wpforms_sanitize_key( $args['id'] );
$is_pro = wpforms()->is_pro();
'name' => esc_html__( 'Email Templates', 'wpforms-lite' ),
foreach ( $args['options'] as $option => $attrs ) {
$checked = checked( $args['value'], $option, false );
$has_education = ! $is_pro && isset( $attrs['is_pro'] ) && $attrs['is_pro'];
$class = [ 'wpforms-settings-field-radio-wrapper', 'wpforms-card-image' ];
// Add class and data attributes for education modal, if needed.
$class[] = 'education-modal'; // This class is used for JS.
$data = $education_args; // This data is used for JS.
$output .= '<span ' . wpforms_html_attributes( '', $class, $data ) . '>';
$output .= '<input type="radio" id="wpforms-setting-' . $id . '[' . $x . ']" name="' . $id . '" value="' . esc_attr( $option ) . '" ' . $checked . '>';
$output .= '<label for="wpforms-setting-' . $id . '[' . $x . ']" class="option-' . sanitize_html_class( $option ) . '">';
$output .= esc_html( $attrs['name'] );
// Add class and data attributes for education modal, if needed.
$output .= EducationHelpers::get_badge( 'Pro' );
$output .= '<span class="wpforms-card-image-overlay">';
$output .= '<span class="wpforms-btn-choose wpforms-btn wpforms-btn-md wpforms-btn-orange">';
$output .= esc_html__( 'Choose', 'wpforms-lite' ) . '</span>';
// Only add the preview action button if provided.
if ( ! empty( $attrs['preview'] ) ) {
$output .= '<a href="' . esc_url( $attrs['preview'] ) . '" class="wpforms-btn-preview wpforms-btn wpforms-btn-md wpforms-btn-light-grey" target="_blank">';
$output .= esc_html__( 'Preview', 'wpforms-lite' );
if ( ! empty( $args['desc'] ) ) {
$output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
* Settings toggle field callback.
* @param array $args Arguments.
function wpforms_settings_toggle_callback( array $args ): string { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
$value = ! empty( $args['value'] ) ? $args['value'] : wpforms_setting( $args['id'] );
$id = wpforms_sanitize_key( $args['id'] );
$class = ! empty( $args['control-class'] ) ? $args['control-class'] : '';
$class .= ! empty( $args['is-important'] ) ? ' wpforms-important' : '';
$input_attr = ! empty( $args['input-attr'] ) ? $args['input-attr'] : '';
'control-class' => $class,
$args = wp_parse_args( $args, $default_args );
$output = wpforms_panel_field_toggle_control(
'wpforms-setting-' . $id,
! empty( $args['label'] ) ? $args['label'] : '',
$desc_on = ! empty( $args['desc'] ) ? $args['desc'] : '';
$desc_on = ! empty( $args['desc-on'] ) ? $args['desc-on'] : $desc_on;
$desc_off = ! empty( $args['desc-off'] ) ? $args['desc-off'] : '';
'<p class="desc desc-on wpforms-toggle-desc%1$s">%2$s</p>',
empty( $value ) && ! empty( $desc_off ) ? ' wpforms-hidden' : '',
if ( ! empty( $desc_off ) ) {
'<p class="desc desc-off wpforms-toggle-desc%1$s">%2$s</p>',
empty( $value ) ? '' : ' wpforms-hidden',
wp_kses_post( $desc_off )