- |
\ No newline at end of file
+ |
diff --git a/includes/fields/class-base.php b/includes/fields/class-base.php
index 6d568b3..baf29f7 100644
--- a/includes/fields/class-base.php
+++ b/includes/fields/class-base.php
@@ -7,7 +7,7 @@
* @since 1.0.0
* @license GPL-2.0+
* @copyright Copyright (c) 2016, WPForms LLC
-*/
+ */
abstract class WPForms_Field {
/**
@@ -48,7 +48,7 @@ abstract class WPForms_Field {
* @since 1.0.0
* @var string
*/
- public $group = 'standard';
+ public $group = 'standard';
/**
* Placeholder to hold default value(s) for some field types.
@@ -78,6 +78,8 @@ abstract class WPForms_Field {
* Primary class constructor.
*
* @since 1.0.0
+ *
+ * @param bool $init
*/
public function __construct( $init = true ) {
@@ -85,32 +87,32 @@ public function __construct( $init = true ) {
return;
}
- // The form ID is to be accessed in the builder
+ // The form ID is to be accessed in the builder.
$this->form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false;
- // Bootstrap
+ // Bootstrap.
$this->init();
- // Add fields tab
+ // Add fields tab.
add_filter( 'wpforms_builder_fields_buttons', array( $this, 'field_button' ), 15 );
- // Field options tab
+ // Field options tab.
add_action( "wpforms_builder_fields_options_{$this->type}", array( $this, 'field_options' ), 10 );
- // Preview fields
+ // Preview fields.
add_action( "wpforms_builder_fields_previews_{$this->type}", array( $this, 'field_preview' ), 10 );
- // AJAX Add new field
- add_action( "wp_ajax_wpforms_new_field_{$this->type}", array( $this,'field_new' ) );
+ // AJAX Add new field.
+ add_action( "wp_ajax_wpforms_new_field_{$this->type}", array( $this, 'field_new' ) );
- // Display fields on front-end
+ // Display field input elements on front-end.
add_action( "wpforms_display_field_{$this->type}", array( $this, 'field_display' ), 10, 3 );
- // Validation on submit
- add_action( "wpforms_process_validate_{$this->type}", array( $this, 'validate'), 10, 3 );
+ // Validation on submit.
+ add_action( "wpforms_process_validate_{$this->type}", array( $this, 'validate' ), 10, 3 );
- // Format
- add_action( "wpforms_process_format_{$this->type}", array( $this, 'format'), 10, 3 );
+ // Format.
+ add_action( "wpforms_process_format_{$this->type}", array( $this, 'format' ), 10, 3 );
}
/**
@@ -125,19 +127,22 @@ public function init() {
* Create the button for the 'Add Fields' tab, inside the form editor.
*
* @since 1.0.0
+ *
* @param array $fields
+ *
* @return array
*/
public function field_button( $fields ) {
- // Add field information to fields array
- $fields[$this->group]['fields'][] = array(
+ // Add field information to fields array.
+ $fields[ $this->group ]['fields'][] = array(
'order' => $this->order,
'name' => $this->name,
'type' => $this->type,
'icon' => $this->icon,
);
- // Wipe hands clean
+
+ // Wipe hands clean.
return $fields;
}
@@ -145,6 +150,8 @@ public function field_button( $fields ) {
* Creates the field options panel. Used by subclasses.
*
* @since 1.0.0
+ *
+ * @param array $field
*/
public function field_options( $field ) {
}
@@ -153,6 +160,8 @@ public function field_options( $field ) {
* Creates the field preview. Used by subclasses.
*
* @since 1.0.0
+ *
+ * @param array $field
*/
public function field_preview( $field ) {
}
@@ -160,101 +169,106 @@ public function field_preview( $field ) {
/**
* Helper function to create field option elements.
*
- * Field option elements are peices that help create a field option. They
- * are used to quickly build field options.
+ * Field option elements are pieces that help create a field option.
+ * They are used to quickly build field options.
*
* @since 1.0.0
+ *
* @param string $option
* @param array $field
* @param array $args
* @param boolean $echo
+ *
* @return mixed echo or return string
*/
public function field_element( $option, $field, $args = array(), $echo = true ) {
$id = (int) $field['id'];
- $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
- $slug = !empty( $args['slug'] ) ? sanitize_title( $args['slug'] ) : '';
+ $class = ! empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
+ $slug = ! empty( $args['slug'] ) ? sanitize_title( $args['slug'] ) : '';
$data = '';
+ $output = '';
- if ( !empty( $args['data'] ) ) {
+ if ( ! empty( $args['data'] ) ) {
foreach ( $args['data'] as $key => $val ) {
- $data .= ' data-' . $key . '="' . $val . '"';
+ if ( is_array( $val ) ) {
+ $val = wp_json_encode( $val );
+ }
+ $data .= ' data-' . $key . '=\'' . $val . '\'';
}
}
switch ( $option ) {
- // Row
+ // Row.
case 'row':
$output = sprintf( ' %s ', $slug, $class, $id, $slug, $id, $args['content'] );
break;
- // Label
+ // Label.
case 'label':
$output = sprintf( '';
break;
- // Text input
+ // Text input.
case 'text':
- $type = !empty( $args['type'] ) ? esc_attr( $args['type'] ) : 'text';
- $placeholder = !empty( $args['placeholder'] ) ? esc_attr( $args['placeholder'] ) : '';
- $before = !empty( $args['before'] ) ? '' . esc_html( $args['before'] ) . '' : '';
- if ( !empty( $before ) ) {
+ $type = ! empty( $args['type'] ) ? esc_attr( $args['type'] ) : 'text';
+ $placeholder = ! empty( $args['placeholder'] ) ? esc_attr( $args['placeholder'] ) : '';
+ $before = ! empty( $args['before'] ) ? '' . esc_html( $args['before'] ) . '' : '';
+ if ( ! empty( $before ) ) {
$class .= ' has-before';
}
$output = sprintf( '%s', $before, $type, $class, $id, $slug, $id, $slug, esc_attr( $args['value'] ), $placeholder, $data );
break;
- // Textarea
+ // Textarea.
case 'textarea':
- $rows = !empty( $args['rows'] ) ? (int) $args['rows'] : '3';
+ $rows = ! empty( $args['rows'] ) ? (int) $args['rows'] : '3';
$output = sprintf( '', $class, $id, $slug, $id, $slug, $rows, $data, $args['value'] );
break;
- // Checkbox
+ // Checkbox.
case 'checkbox':
$checked = checked( '1', $args['value'], false );
- $desc = !empty( $args['desc'] ) ? $args['desc'] : '';
$output = sprintf( '', $class, $id, $slug, $id, $slug, $checked, $data );
$output .= sprintf( '';
break;
- // Toggle
+ // Toggle.
case 'toggle':
$checked = checked( '1', $args['value'], false );
$icon = $args['value'] ? 'fa-toggle-on' : 'fa-toggle-off';
$cls = $args['value'] ? 'wpforms-on' : 'wpforms-off';
- $status = $args['value'] ? __( 'On', 'wpforms' ) : __( 'Off', 'wpforms' );
+ $status = $args['value'] ? esc_html__( 'On', 'wpforms' ) : esc_html__( 'Off', 'wpforms' );
$output = sprintf( ' %s', $cls, $icon, $status );
$output .= sprintf( '', $class, $id, $slug, $id, $slug, $checked, $data );
break;
- // Select
+ // Select.
case 'select':
$options = $args['options'];
- $value = isset( $args['value'] ) ? $args['value'] : '';
+ $value = isset( $args['value'] ) ? $args['value'] : '';
$output = sprintf( '';
break;
- }
+ } // End switch().
if ( $echo ) {
- echo $output;
+ echo $output; // WPCS: XSS ok.
} else {
return $output;
}
@@ -264,26 +278,28 @@ public function field_element( $option, $field, $args = array(), $echo = true )
* Helper function to create common field options that are used frequently.
*
* @since 1.0.0
+ *
* @param string $option
* @param array $field
* @param array $args
* @param boolean $echo
+ *
* @return mixed echo or return string
*/
public function field_option( $option, $field, $args = array(), $echo = true ) {
switch ( $option ) {
- //----------------------------------------------------------------//
- // Basic Fields
- //----------------------------------------------------------------//
+ // --------------------------------------------------------------//
+ // Basic Fields.
+ // --------------------------------------------------------------//
- // Basic Options markup ------------------------------------------//
+ // Basic Options markup. ------------------------------------------//
case 'basic-options':
- $markup = !empty( $args['markup'] ) ? $args['markup'] : 'open';
- $class = !empty( $args['class'] ) ? esc_html( $args['class'] ) : '';
- if ( $markup == 'open' ) {
+ $markup = ! empty( $args['markup'] ) ? $args['markup'] : 'open';
+ $class = ! empty( $args['class'] ) ? esc_html( $args['class'] ) : '';
+ if ( 'open' === $markup ) {
$output = sprintf( ' |