abstracts
6 years ago
admin
6 years ago
export
6 years ago
fields
6 years ago
interfaces
8 years ago
libraries
7 years ago
log-handlers
8 years ago
shortcodes
6 years ago
templates
7 years ago
class-everest-forms.php
6 years ago
class-evf-ajax.php
6 years ago
class-evf-autoloader.php
7 years ago
class-evf-background-updater.php
7 years ago
class-evf-cache-helper.php
8 years ago
class-evf-deprecated-action-hooks.php
7 years ago
class-evf-deprecated-filter-hooks.php
7 years ago
class-evf-emails.php
7 years ago
class-evf-fields.php
7 years ago
class-evf-form-block.php
6 years ago
class-evf-form-handler.php
6 years ago
class-evf-form-task.php
6 years ago
class-evf-forms-features.php
7 years ago
class-evf-frontend-scripts.php
7 years ago
class-evf-install.php
6 years ago
class-evf-integrations.php
7 years ago
class-evf-log-levels.php
8 years ago
class-evf-logger.php
8 years ago
class-evf-post-types.php
7 years ago
class-evf-privacy.php
7 years ago
class-evf-session-handler.php
7 years ago
class-evf-shortcodes.php
7 years ago
class-evf-smart-tags.php
7 years ago
class-evf-template-loader.php
7 years ago
class-evf-validation.php
8 years ago
evf-conditional-functions.php
7 years ago
evf-core-functions.php
6 years ago
evf-deprecated-functions.php
7 years ago
evf-entry-functions.php
6 years ago
evf-formatting-functions.php
7 years ago
evf-notice-functions.php
6 years ago
evf-template-functions.php
7 years ago
evf-template-hooks.php
7 years ago
evf-update-functions.php
6 years ago
class-evf-fields.php
169 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Form Fields |
| 4 | * |
| 5 | * Loads form fields via hooks for use in the builder. |
| 6 | * |
| 7 | * @package EverestForms\Classes\Fields |
| 8 | * @version 1.2.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | /** |
| 14 | * Form fields class. |
| 15 | */ |
| 16 | class EVF_Fields { |
| 17 | |
| 18 | /** |
| 19 | * Form fields classes. |
| 20 | * |
| 21 | * @var array |
| 22 | */ |
| 23 | public $form_fields = array(); |
| 24 | |
| 25 | /** |
| 26 | * The single instance of the class. |
| 27 | * |
| 28 | * @var EVF_Fields |
| 29 | */ |
| 30 | protected static $_instance = null; |
| 31 | |
| 32 | /** |
| 33 | * Main EVF_Fields Instance. |
| 34 | * |
| 35 | * Ensures only one instance of EVF_Fields is loaded or can be loaded. |
| 36 | * |
| 37 | * @return EVF_Fields Main instance. |
| 38 | */ |
| 39 | public static function instance() { |
| 40 | if ( is_null( self::$_instance ) ) { |
| 41 | self::$_instance = new self(); |
| 42 | } |
| 43 | return self::$_instance; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Cloning is forbidden. |
| 48 | * |
| 49 | * @since 1.2.0 |
| 50 | */ |
| 51 | public function __clone() { |
| 52 | evf_doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'everest-forms' ), '1.2.0' ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Unserializing instances of this class is forbidden. |
| 57 | * |
| 58 | * @since 1.2.0 |
| 59 | */ |
| 60 | public function __wakeup() { |
| 61 | evf_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'everest-forms' ), '1.2.0' ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Initialize form fields. |
| 66 | */ |
| 67 | public function __construct() { |
| 68 | $this->init(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Load fields and hook in functions. |
| 73 | */ |
| 74 | public function init() { |
| 75 | $load_fields = apply_filters( |
| 76 | 'everest_forms_fields', |
| 77 | array( |
| 78 | 'EVF_Field_First_Name', |
| 79 | 'EVF_Field_Last_Name', |
| 80 | 'EVF_Field_Text', |
| 81 | 'EVF_Field_Textarea', |
| 82 | 'EVF_Field_Select', |
| 83 | 'EVF_Field_Radio', |
| 84 | 'EVF_Field_Checkbox', |
| 85 | 'EVF_Field_Number', |
| 86 | 'EVF_Field_Email', |
| 87 | 'EVF_Field_URL', |
| 88 | 'EVF_Field_Date_Time', |
| 89 | ) |
| 90 | ); |
| 91 | |
| 92 | // Get sort order. |
| 93 | $order_end = 999; |
| 94 | |
| 95 | // Load form fields. |
| 96 | foreach ( $load_fields as $field ) { |
| 97 | $load_field = is_string( $field ) ? new $field() : $field; |
| 98 | |
| 99 | if ( isset( $load_field->order ) && is_numeric( $load_field->order ) ) { |
| 100 | // Add in position. |
| 101 | $this->form_fields[ $load_field->group ][ $load_field->order ] = $load_field; |
| 102 | } else { |
| 103 | // Add to end of the array. |
| 104 | $this->form_fields[ $load_field->group ][ $order_end ] = $load_field; |
| 105 | $order_end++; |
| 106 | } |
| 107 | |
| 108 | ksort( $this->form_fields[ $load_field->group ] ); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Get fields. |
| 114 | * |
| 115 | * @return array |
| 116 | */ |
| 117 | public function form_fields() { |
| 118 | $_available_fields = array(); |
| 119 | |
| 120 | if ( count( $this->form_fields ) > 0 ) { |
| 121 | foreach ( $this->form_fields as $group => $field ) { |
| 122 | $_available_fields[ $group ] = $field; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | return $_available_fields; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Get array of registered field types. |
| 131 | * |
| 132 | * @return array of strings |
| 133 | */ |
| 134 | public function get_form_field_types() { |
| 135 | $_available_fields = array(); |
| 136 | |
| 137 | if ( count( $this->form_fields ) > 0 ) { |
| 138 | foreach ( array_values( $this->form_fields ) as $form_field ) { |
| 139 | foreach ( $form_field as $field ) { |
| 140 | $_available_fields[] = $field->type; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | return $_available_fields; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Get array of registered "Pro" field types. |
| 150 | * |
| 151 | * @return array of strings |
| 152 | */ |
| 153 | public function get_pro_form_field_types() { |
| 154 | $_available_fields = array(); |
| 155 | |
| 156 | if ( count( $this->form_fields ) > 0 ) { |
| 157 | foreach ( array_values( $this->form_fields ) as $form_field ) { |
| 158 | foreach ( $form_field as $field ) { |
| 159 | if ( $field->is_pro ) { |
| 160 | $_available_fields[] = $field->type; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return $_available_fields; |
| 167 | } |
| 168 | } |
| 169 |