Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UR-1035 Compatibility custom captcha #604

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/css/_fonts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ $field-icons: (
total: "\e02f",
quantity: "\e032",
hidden-field:"\e035",
captcha-field: "\e036",
);

/* For each key in the map, creating own class */
Expand Down
Binary file modified assets/fonts/UserRegistration.eot
Binary file not shown.
1 change: 1 addition & 0 deletions assets/fonts/UserRegistration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/fonts/UserRegistration.ttf
Binary file not shown.
Binary file modified assets/fonts/UserRegistration.woff
Binary file not shown.
46 changes: 43 additions & 3 deletions assets/js/admin/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,34 @@
}
general_setting_data["options"] = array_value;
});
} else if (
"captcha" ===
$(this).attr("data-field-name")) {
var li_elements = $(this).closest("ul").find("li");
var captcha_value = [];

li_elements.each(function (index, element) {

var question = $(element)
.find("input.ur-type-captcha-question")
.val();

var answer = $(element)
.find(".ur-type-captcha-answer")
.val();
if (
captcha_value.every(function (each_value) {
return each_value.question !== question;
})
) {
general_setting_data["options"] =
captcha_value.push({
question: question,
answer: answer,
});
}
general_setting_data["options"] = captcha_value;
});
} else {
var choice_value = URFormBuilder.get_ur_data(
$(this)
Expand Down Expand Up @@ -3082,6 +3110,7 @@
});
break;
}
$(document.body).trigger('ur_general_field_settings_to_update_form_fields_in_builder',[$this_obj]);
});
var advance_settings = $(
"#ur-setting-form .ur_advance_setting"
Expand Down Expand Up @@ -3642,6 +3671,7 @@
URFormBuilder.render_multiple_choice(value);
break;
}
$(document.body).trigger("ur_sync_textarea_field_settings_in_selected_field_of_form_builder",[field_type,value]);
},
/**
* Reflects changes in select field of field settings into selected field in form builder area.
Expand Down Expand Up @@ -3939,6 +3969,16 @@
'"]'
)
.val($label.val());
} else if ( "captcha" === $label.attr("data-field-name") ) {
wrapper
.find(
".ur-general-setting-block li:nth(" +
index +
') input[name="' +
$label.attr("name") +
'"]'
)
.val($label.val());
} else {
wrapper
.find(
Expand Down Expand Up @@ -4178,19 +4218,19 @@
handle_options_sort: function ($this_obj) {
URFormBuilder.ur_clone_options($this_obj);
if (
$this
$this_obj
.closest(".ur-general-setting-block")
.hasClass("ur-general-setting-radio")
) {
URFormBuilder.render_radio($this_obj);
} else if (
$this
$this_obj
.closest(".ur-general-setting-block")
.hasClass("ur-general-setting-checkbox")
) {
URFormBuilder.render_check_box($this_obj);
} else if (
$this
$this_obj
.closest(".ur-general-setting-block")
.hasClass("ur-general-setting-multiple_choice")
) {
Expand Down
38 changes: 38 additions & 0 deletions includes/abstracts/abstract-ur-form-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,23 @@ public function frontend_includes( $form_id, $field_type, $field_key, $data = ar
$form_data['choice_limit'] = isset( $data['advance_setting']->choice_limit ) ? $data['advance_setting']->choice_limit : '';
}

if ( 'captcha' === $field_key ) {
$choices = isset( $data['advance_setting']->choices ) ? explode( ',', $data['advance_setting']->choices ) : array(); // Backward compatibility. Modified since 1.5.7.
$option_data = isset( $data['general_setting']->options ) ? $data['general_setting']->options : $choices;
$options = array();

if ( is_array( $option_data ) ) {
foreach ( $option_data as $index_data => $option ) {
$options[ $option->question ] = array(
'question' => ur_string_translation( $form_id, 'user_registration_' . $data['general_setting']->field_name . '_option_' . ( ++$index_data ), $option->question ),
'answer' => $option->answer,
);
}

$form_data['options'] = $options;
}
}

if ( 'user_login' === $field_key ) {
$form_data['username_length'] = isset( $data['advance_setting']->username_length ) ? $data['advance_setting']->username_length : '';

Expand Down Expand Up @@ -664,6 +681,27 @@ public function get_field_general_settings() {

$general_setting_wrapper .= '/>';
break;
case 'captcha' :
$default_options = isset( $this->field_defaults['default_options'] ) ? $this->field_defaults['default_options'] : array();
$old_options = isset( $this->admin_data->advance_setting->choices ) ? explode( ',', trim( $this->admin_data->advance_setting->choices, ',' ) ) : $default_options;
$options = isset( $this->admin_data->general_setting->options ) ? $this->admin_data->general_setting->options : $old_options;
$general_setting_wrapper .= '<ul class="ur-options-list">';

foreach ( $options as $key => $option ) {
$label = is_array( $option ) ? $option['question'] : $option->question;
$answer = is_array( $option ) ? $option['answer'] : $option->answer;
$general_setting_wrapper .= '<li class="ur-custom-captcha">';
$general_setting_wrapper .= '<div class="editor-block-mover__control-drag-handle editor-block-mover__control">
<svg width="18" height="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" role="img" aria-hidden="true" focusable="false"><path d="M13,8c0.6,0,1-0.4,1-1s-0.4-1-1-1s-1,0.4-1,1S12.4,8,13,8z M5,6C4.4,6,4,6.4,4,7s0.4,1,1,1s1-0.4,1-1S5.6,6,5,6z M5,10 c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S5.6,10,5,10z M13,10c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S13.6,10,13,10z M9,6 C8.4,6,8,6.4,8,7s0.4,1,1,1s1-0.4,1-1S9.6,6,9,6z M9,10c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S9.6,10,9,10z"></path></svg>
</div>';
$general_setting_wrapper .= '<input value="' . esc_attr( $label ) . '" data-field="' . esc_attr( $setting_key ) . '" data-field-name="' . esc_attr( $strip_prefix ) . '" class="ur-general-setting-field ur-type-' . esc_attr( $setting_value['type'] ) . '-question" type="text" name="' . esc_attr( $setting_value['name'] ) . '_captcha_question">';
$general_setting_wrapper .= '<input value="' . esc_attr( $answer ) . '" data-field="' . esc_attr( $setting_key ) . '" data-field-name="' . esc_attr( $strip_prefix ) . '" class="ur-general-setting-field ur-type-' . esc_attr( $setting_value['type'] ) . '-answer" type="text" name="' . esc_attr( $setting_value['name'] ) . '_captcha_answer">';
$general_setting_wrapper .= '<a class="add" href="#"><i class="dashicons dashicons-plus"></i></a>';
$general_setting_wrapper .= '<a class="remove" href="#"><i class="dashicons dashicons-minus"></i></a>';
$general_setting_wrapper .= '</li>';
}
$general_setting_wrapper .= '</ul>';
break;

default:
$general_setting_wrapper .= apply_filters( 'user_registration_form_field_general_setting_' . $setting_value['type'], $this );
Expand Down
3 changes: 2 additions & 1 deletion templates/myaccount/form-edit-profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@
}

// Unset multiple choice and single item.
if ( 'multiple_choice' === $single_item->field_key || 'single_item' === $single_item->field_key ) {
// Unset multiple choice and single item.
if ( 'multiple_choice' === $single_item->field_key || 'single_item' === $single_item->field_key || 'captcha' === $single_item->field_key ) {
continue;
}

Expand Down
Loading