PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.2
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.2
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/fields/class-field-checkbox.php +35 -44 1.6.211.2.2 View file →
@@ -4,9 +4,9 @@
4 4 * Text Field Class
5 5 */
6 6 class WeForms_Form_Field_Checkbox extends WeForms_Field_Contract {
7 7
8 - public function __construct() {
8 + function __construct() {
9 9 $this->name = __( 'Checkbox', 'weforms' );
10 10 $this->input_type = 'checkbox_field';
11 11 $this->icon = 'check-square-o';
12 12 }
@@ -13,32 +13,35 @@
13 13
14 14 /**
15 15 * Render the text field
16 16 *
17 - * @param array $field_settings
18 - * @param int $form_id
17 + * @param array $field_settings
18 + * @param integer $form_id
19 19 *
20 20 * @return void
21 21 */
22 22 public function render( $field_settings, $form_id ) {
23 - $selected = !empty( $field_settings['selected'] ) ? $field_settings['selected'] : []; ?>
23 + $selected = !empty( $field_settings['selected'] ) ? $field_settings['selected'] : array();
24 + ?>
24 25 <li <?php $this->print_list_attributes( $field_settings ); ?>>
25 26 <?php $this->print_label( $field_settings, $form_id ); ?>
26 27
27 - <?php do_action( 'weforms_checkbox_field_after_label', $field_settings ); ?>
28 - <div class="wpuf-fields" data-required="<?php echo esc_attr( $field_settings['required'] ) ?>" data-type="radio">
28 + <div class="wpuf-fields" data-required="<?php echo $field_settings['required'] ?>" data-type="radio">
29 29
30 30 <?php
31 31 if ( $field_settings['options'] && count( $field_settings['options'] ) > 0 ) {
32 - foreach ( $field_settings['options'] as $value => $option ) {
32 +
33 + foreach ($field_settings['options'] as $value => $option) {
34 +
33 35 ?>
34 36 <label <?php echo $field_settings['inline'] == 'yes' ? 'class="wpuf-checkbox-inline"' : 'class="wpuf-checkbox-block"'; ?>>
35 - <input type="checkbox" class="<?php echo 'wpuf_' . esc_attr( $field_settings['name'] ). '_'. esc_attr($form_id); ?>" name="<?php echo esc_attr( $field_settings['name'] ); ?>[]" value="<?php echo esc_attr( $value ); ?>"<?php echo in_array( $value, $selected ) ? ' checked="checked"' : ''; ?> />
36 - <?php echo $option; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
37 + <input type="checkbox" class="<?php echo 'wpuf_' . $field_settings['name']. '_'. $form_id; ?>" name="<?php echo $field_settings['name']; ?>[]" value="<?php echo esc_attr( $value ); ?>"<?php echo in_array( $value, $selected ) ? ' checked="checked"' : ''; ?> />
38 + <?php echo $option; ?>
37 39 </label>
38 40 <?php
39 41 }
40 - } ?>
42 + }
43 + ?>
41 44
42 45 <?php $this->help_text( $field_settings ); ?>
43 46
44 47 </div>
@@ -51,30 +54,28 @@
51 54 *
52 55 * @return array
53 56 */
54 57 public function get_options_settings() {
55 - $default_options = $this->get_default_option_settings( true, [ 'width' ] );
56 - $dropdown_options = [
58 + $default_options = $this->get_default_option_settings( true, array( 'width' ) );
59 + $dropdown_options = array(
57 60 $this->get_default_option_dropdown_settings( true ),
58 61
59 - [
62 + array(
60 63 'name' => 'inline',
61 - 'title' => __( 'Show in inline list', 'weforms' ),
64 + 'title' => __( 'Show in inline list', 'wpuf' ),
62 65 'type' => 'radio',
63 - 'options' => [
64 - 'yes' => __( 'Yes', 'weforms' ),
65 - 'no' => __( 'No', 'weforms' ),
66 - ],
66 + 'options' => array(
67 + 'yes' => __( 'Yes', 'wpuf' ),
68 + 'no' => __( 'No', 'wpuf' ),
69 + ),
67 70 'default' => 'no',
68 71 'inline' => true,
69 72 'section' => 'advanced',
70 73 'priority' => 23,
71 - 'help_text' => __( 'Show this option in an inline list', 'weforms' ),
72 - ],
73 - ];
74 + 'help_text' => __( 'Show this option in an inline list', 'wpuf' ),
75 + ),
76 + );
74 77
75 - $dropdown_options = apply_filters( 'weforms_checkbox_field_option_settings', $dropdown_options );
76 -
77 78 return array_merge( $default_options, $dropdown_options );
78 79 }
79 80
80 81 /**
@@ -83,16 +84,14 @@
83 84 * @return array
84 85 */
85 86 public function get_field_props() {
86 87 $defaults = $this->default_attributes();
87 - $props = [
88 - 'selected' => [],
89 - 'inline' => 'no',
90 - 'options' => [ 'Option' => __( 'Option', 'weforms' ) ],
91 - ];
88 + $props = array(
89 + 'selected' => array(),
90 + 'inline' => 'no',
91 + 'options' => array( 'Option' => __( 'Option', 'wpuf' ) ),
92 + );
92 93
93 - $props = apply_filters( 'weforms_checkbox_field_props', $props );
94 -
95 94 return array_merge( $defaults, $props );
96 95 }
97 96
98 97 /**
@@ -101,25 +100,17 @@
101 100 * @param $field
102 101 *
103 102 * @return mixed
104 103 */
105 - public function prepare_entry( $field, $args = [] ) {
106 - if( empty( $_POST['_wpnonce'] ) ) {
107 - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
108 - }
104 + public function prepare_entry( $field ) {
109 105
110 - if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) {
111 - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
112 - }
106 + $entry_value = ( is_array( $_POST[$field['name']] ) && $_POST[$field['name']] ) ? $_POST[$field['name']] : array();
113 107
114 - $args = ! empty( $args ) ? $args : weforms_clean( $_POST );
115 - $entry_value = ( is_array( $args[ $field[ 'name' ] ] ) && $args[ $field[ 'name' ] ] ) ? $args[ $field[ 'name' ] ] : array();
116 -
117 108 if ( $entry_value ) {
118 - $new_val = [];
109 + $new_val = array();
119 110
120 - foreach ( $entry_value as $option_key ) {
121 - $new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] : $option_key;
111 + foreach ($entry_value as $option_key) {
112 + $new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] : '';
122 113 }
123 114
124 115 $entry_value = implode( WeForms::$field_separator, $new_val );
125 116 } else {
@@ -127,5 +118,5 @@
127 118 }
128 119
129 120 return $entry_value;
130 121 }
131 -}
122 +}