Helpers
11 months ago
Integrations
2 weeks ago
RestApi
4 days ago
abilities
3 weeks ago
abstracts
4 days ago
admin
4 days ago
blocks
1 year ago
elementor
2 years ago
export
2 months ago
fields
3 weeks ago
interfaces
8 years ago
libraries
2 years ago
log-handlers
1 year ago
shortcodes
3 weeks ago
stats
5 months ago
templates
3 months ago
traits
3 weeks ago
class-everest-forms.php
4 days ago
class-evf-addon-upsell.php
3 weeks ago
class-evf-ajax.php
3 weeks ago
class-evf-autoloader.php
7 years ago
class-evf-background-process-import-entries.php
2 years ago
class-evf-background-updater.php
7 years ago
class-evf-cache-helper.php
2 months ago
class-evf-cron.php
2 years ago
class-evf-deprecated-action-hooks.php
6 years ago
class-evf-deprecated-filter-hooks.php
5 years ago
class-evf-email-entries-report.php
3 months ago
class-evf-emails.php
3 weeks ago
class-evf-fields.php
3 weeks ago
class-evf-form-handler.php
3 weeks ago
class-evf-form-task.php
3 weeks ago
class-evf-forms-features.php
3 weeks ago
class-evf-frontend-scripts.php
3 weeks ago
class-evf-install.php
2 months ago
class-evf-integrations.php
3 months ago
class-evf-log-levels.php
8 years ago
class-evf-logger.php
5 years ago
class-evf-post-types.php
1 year ago
class-evf-privacy.php
6 years ago
class-evf-report-cron.php
2 months ago
class-evf-reporting.php
2 months ago
class-evf-session-handler.php
7 years ago
class-evf-shortcodes.php
1 year ago
class-evf-smart-tags.php
9 months ago
class-evf-template-loader.php
1 year ago
class-evf-validation.php
6 years ago
evf-conditional-functions.php
6 years ago
evf-core-functions.php
3 weeks ago
evf-deprecated-functions.php
6 years ago
evf-entry-functions.php
4 months ago
evf-formatting-functions.php
4 years ago
evf-notice-functions.php
4 years ago
evf-template-functions.php
4 years ago
evf-template-hooks.php
7 years ago
evf-update-functions.php
5 years ago
class-evf-fields.php
214 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 | 'EVF_Field_Recaptcha', |
| 90 | 'EVF_Field_Hcaptcha', |
| 91 | 'EVF_Field_Turnstile', |
| 92 | 'EVF_Field_AI', |
| 93 | 'EVF_Field_File_Upload', |
| 94 | 'EVF_Field_Private_Note' |
| 95 | ) |
| 96 | ); |
| 97 | if ( ! class_exists( '\EverestForms\AI' ) ) { |
| 98 | $load_fields = array_diff( $load_fields, array( 'EVF_Field_AI' ) ); |
| 99 | } |
| 100 | |
| 101 | // Get sort order. |
| 102 | $order_end = 999; |
| 103 | |
| 104 | // Load form fields. |
| 105 | foreach ( $load_fields as $field ) { |
| 106 | $load_field = is_string( $field ) ? new $field() : $field; |
| 107 | |
| 108 | if ( isset( $load_field->order ) && is_numeric( $load_field->order ) ) { |
| 109 | // Add in position. |
| 110 | $this->form_fields[ $load_field->group ][ $load_field->order ] = $load_field; |
| 111 | } else { |
| 112 | // Add to end of the array. |
| 113 | $this->form_fields[ $load_field->group ][ $order_end ] = $load_field; |
| 114 | ++$order_end; |
| 115 | } |
| 116 | |
| 117 | ksort( $this->form_fields[ $load_field->group ] ); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Get fields. |
| 123 | * |
| 124 | * @return array |
| 125 | */ |
| 126 | public function form_fields() { |
| 127 | $_available_fields = array(); |
| 128 | |
| 129 | if ( count( $this->form_fields ) > 0 ) { |
| 130 | foreach ( $this->form_fields as $group => $field ) { |
| 131 | $_available_fields[ $group ] = $field; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return $_available_fields; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Get array of registered field types. |
| 140 | * |
| 141 | * @return array of strings |
| 142 | */ |
| 143 | public function get_form_field_types() { |
| 144 | $_available_fields = array(); |
| 145 | |
| 146 | if ( count( $this->form_fields ) > 0 ) { |
| 147 | foreach ( array_values( $this->form_fields ) as $form_field ) { |
| 148 | foreach ( $form_field as $field ) { |
| 149 | $_available_fields[] = $field->type; |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return $_available_fields; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Get array of registered "Pro" field types. |
| 159 | * |
| 160 | * @return array of strings |
| 161 | */ |
| 162 | public function get_pro_form_field_types() { |
| 163 | $_available_fields = array(); |
| 164 | |
| 165 | if ( count( $this->form_fields ) > 0 ) { |
| 166 | foreach ( array_values( $this->form_fields ) as $form_field ) { |
| 167 | foreach ( $form_field as $field ) { |
| 168 | if ( $field->is_pro ) { |
| 169 | $_available_fields[] = $field->type; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | return $_available_fields; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Get metadata for all registered "Pro" (lockable) field types. |
| 180 | * |
| 181 | * Used by the upsell UI (builder locked-field overlay, AI preview) and as |
| 182 | * the canonical list of Pro fields the AI form generator may surface. |
| 183 | * |
| 184 | * @since 3.2.0 |
| 185 | * |
| 186 | * @return array Map of field type => metadata ( name, icon, group, addon, plan, links ). |
| 187 | */ |
| 188 | public function get_pro_fields_meta() { |
| 189 | $meta = array(); |
| 190 | |
| 191 | if ( count( $this->form_fields ) > 0 ) { |
| 192 | foreach ( array_values( $this->form_fields ) as $form_field ) { |
| 193 | foreach ( $form_field as $field ) { |
| 194 | if ( empty( $field->is_pro ) ) { |
| 195 | continue; |
| 196 | } |
| 197 | |
| 198 | $meta[ $field->type ] = array( |
| 199 | 'type' => $field->type, |
| 200 | 'name' => isset( $field->name ) ? $field->name : $field->type, |
| 201 | 'icon' => isset( $field->icon ) ? $field->icon : '', |
| 202 | 'group' => isset( $field->group ) ? $field->group : '', |
| 203 | 'addon' => isset( $field->addon ) ? $field->addon : '', |
| 204 | 'plan' => isset( $field->plan ) ? $field->plan : '', |
| 205 | 'links' => isset( $field->links ) ? $field->links : array(), |
| 206 | ); |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | return apply_filters( 'everest_forms_pro_fields_meta', $meta ); |
| 212 | } |
| 213 | } |
| 214 |