PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.2
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.2
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / admin / manage-fields.php

manage-fields.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.2, at admin/manage-fields.php

2,105 lines 114.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 // Define the default values.
4 define( 'WPPB_DEFAULTS_MAP_LAT', 48 );
5 define( 'WPPB_DEFAULTS_MAP_LNG', 12 );
6 define( 'WPPB_DEFAULTS_MAP_ZOOM', 4 );
7
8 /**
9 * Function that creates the Manage Fields submenu and populates it with a repeater field form
10 *
11 * @since v.2.0
12 *
13 * @return void
14 */
15 function wppb_manage_fields_submenu(){
16 // create a new sub_menu page which holds the data for the default + extra fields
17 $args = array(
18 'menu_title' => __('Form Fields', 'profile-builder'),
19 'page_title' => __('Manage Form Fields', 'profile-builder'),
20 'menu_slug' => 'manage-fields',
21 'page_type' => 'submenu_page',
22 'capability' => 'manage_options',
23 'priority' => 5,
24 'parent_slug' => 'profile-builder'
25 );
26 $manage_fields_page = new WCK_Page_Creator_PB($args);
27 }
28 add_action( 'admin_menu', 'wppb_manage_fields_submenu', 1 );
29
30 function wppb_populate_manage_fields(){
31
32 $manage_field_types = array(
33 'optgroups' => array(
34 'default' =>
35 array(
36 'label' => __('Default', 'profile-builder'),
37 'options' => array(
38 'Default - Name (Heading)',
39 'Default - Contact Info (Heading)',
40 'Default - About Yourself (Heading)',
41 'Default - Username',
42 'Default - First Name',
43 'Default - Last Name',
44 'Default - Nickname',
45 'Default - E-mail',
46 'Default - Website',
47 'Default - Password',
48 'Default - Repeat Password',
49 'Default - Biographical Info',
50 'Default - Display name publicly as',
51 ),
52 ),
53 'standard' =>
54 array(
55 'label' => __('Standard', 'profile-builder'),
56 'options' => array(
57 // since 3.8.1
58 'Avatar',
59 'Checkbox',
60 'Heading',
61 'Input',
62 'Radio',
63 'Select',
64 'Textarea',
65 ),
66 ),
67 'advanced' =>
68 array(
69 'label' => __('Advanced', 'profile-builder'),
70 'options' => array(
71 'Select2' // since 3.8.1
72 ),
73 ),
74 'other' =>
75 array(
76 'label' => __('Other', 'profile-builder'),
77 'options' => array(
78 'GDPR Checkbox', // since 2.8.2
79 'GDPR Delete Button', // since 3.0.1
80 ),
81 ),
82 ),
83 );
84
85 // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
86 if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){
87 $manage_field_types['optgroups']['default']['options'][] = 'Default - AIM';
88 $manage_field_types['optgroups']['default']['options'][] = 'Default - Yahoo IM';
89 $manage_field_types['optgroups']['default']['options'][] = 'Default - Jabber / Google Talk';
90 }
91
92 if ( wppb_can_users_signup_blog() ) {
93 $manage_field_types['optgroups']['advanced']['options'][] = 'Default - Blog Details';
94 }
95
96 if( PROFILE_BUILDER != 'Profile Builder Free' ) {
97 // $manage_field_types['optgroups']['standard']['options'][] = 'Heading';
98 // $manage_field_types['optgroups']['standard']['options'][] = 'Input';
99 $manage_field_types['optgroups']['standard']['options'][] = 'Number';
100 $manage_field_types['optgroups']['standard']['options'][] = 'Input (Hidden)';
101 $manage_field_types['optgroups']['standard']['options'][] = 'Language';
102 // $manage_field_types['optgroups']['standard']['options'][] = 'Textarea';
103 $manage_field_types['optgroups']['standard']['options'][] = 'WYSIWYG';
104 // $manage_field_types['optgroups']['standard']['options'][] = 'Select';
105 $manage_field_types['optgroups']['standard']['options'][] = 'Select (Multiple)';
106 // $manage_field_types['optgroups']['standard']['options'][] = 'Checkbox';
107 // $manage_field_types['optgroups']['standard']['options'][] = 'Radio';
108 $manage_field_types['optgroups']['standard']['options'][] = 'HTML';
109 $manage_field_types['optgroups']['standard']['options'][] = 'Upload';
110 $manage_field_types['optgroups']['standard']['options'][] = 'International Telephone Input';
111 // $manage_field_types['optgroups']['standard']['options'][] = 'Avatar';
112
113 $manage_field_types['optgroups']['advanced']['options'][] = 'Phone';
114 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (Country)';
115 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (Timezone)';
116 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (Currency)';
117 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (CPT)';
118 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (Taxonomy)';
119 $manage_field_types['optgroups']['advanced']['options'][] = 'Checkbox (Terms and Conditions)';
120 $manage_field_types['optgroups']['advanced']['options'][] = 'Datepicker';
121 $manage_field_types['optgroups']['advanced']['options'][] = 'Timepicker';
122 $manage_field_types['optgroups']['advanced']['options'][] = 'Colorpicker';
123 $manage_field_types['optgroups']['advanced']['options'][] = 'Validation';
124 $manage_field_types['optgroups']['advanced']['options'][] = 'Map';
125 $manage_field_types['optgroups']['advanced']['options'][] = 'Additional Map';
126
127 $manage_field_types['optgroups']['other']['options'][] = 'Email';
128 $manage_field_types['optgroups']['other']['options'][] = 'URL';
129
130 // $manage_field_types['optgroups']['other']['options'][] = 'Select2';
131 $manage_field_types['optgroups']['other']['options'][] = 'Select2 (Multiple)';
132
133 $manage_field_types['optgroups']['other']['options'][] = 'Honeypot';
134
135 }
136
137 $manage_field_types['optgroups']['other']['options'][] = 'Email Confirmation';
138
139 /* added recaptcha field since version 2.6.2 */
140 $manage_field_types['optgroups']['advanced']['options'][] = 'reCAPTCHA';
141
142 /* added turnstile field since version 3.15. */
143 $manage_field_types['optgroups']['advanced']['options'][] = 'Turnstile';
144
145 /* added user role field since version 2.6.2 */
146 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (User Role)';
147
148
149 $manage_field_types['optgroups']['other']['options'] = apply_filters( 'wppb_manage_fields_types', $manage_field_types['optgroups']['other']['options'] );
150
151 $manage_field_types = apply_filters( 'wppb_all_manage_fields_types', $manage_field_types );
152
153 if( PROFILE_BUILDER == 'Profile Builder Free' ) {
154
155 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'Number', 'disabled' => true );
156 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'Input (Hidden)', 'disabled' => true );
157 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'Language', 'disabled' => true );
158 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'WYSIWYG', 'disabled' => true );
159 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'Select (Multiple)', 'disabled' => true );
160 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'HTML', 'disabled' => true );
161 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'Upload', 'disabled' => true );
162 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'International Telephone Input', 'disabled' => true );
163
164 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Phone', 'disabled' => true );
165 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Select (Country)', 'disabled' => true );
166 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Select (Timezone)', 'disabled' => true );
167 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Select (Currency)', 'disabled' => true );
168 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Select (CPT)', 'disabled' => true );
169 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Select (Taxonomy)', 'disabled' => true );
170 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Checkbox (Terms and Conditions)', 'disabled' => true );
171 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Datepicker', 'disabled' => true );
172 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Timepicker', 'disabled' => true );
173 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Colorpicker', 'disabled' => true );
174 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Validation', 'disabled' => true );
175 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Map', 'disabled' => true );
176 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Additional Map', 'disabled' => true );
177
178 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'WooCommerce Customer Billing Address', 'disabled' => true );
179 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'WooCommerce Customer Shipping Address', 'disabled' => true );
180 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'MailChimp Subscribe', 'disabled' => true );
181 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'Email', 'disabled' => true );
182 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'URL', 'disabled' => true );
183 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'Select2 (Multiple)', 'disabled' => true );
184 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'Honeypot', 'disabled' => true );
185
186 }
187
188 if( !is_plugin_active( 'paid-member-subscriptions/index.php' ) )
189 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'Subscription Plans', 'disabled' => true );
190
191 // Free to Pro call to action on Manage Fields page
192 $field_description = __('Choose one of the supported field types','profile-builder');
193 if( PROFILE_BUILDER == 'Profile Builder Free' ) {
194 $field_description .= sprintf( __('. Extra Field Types are available in <a href="%s">Basic or PRO versions</a>.' , 'profile-builder'), esc_url( 'https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-form-fields&utm_medium=client-site&utm_campaign=pb-extra-fields#pricing' ) );
195 }
196
197 //user roles
198 global $wp_roles;
199
200 // @TODO - The block below could use refactoring, see new function wppb_prepare_key_value_options.
201 $user_roles = array();
202 foreach( $wp_roles->roles as $user_role_slug => $user_role )
203 if( $user_role_slug !== 'administrator' )
204 array_push( $user_roles, '%' . wppb_prepare_wck_labels( $user_role['name'] ) . '%' . $user_role_slug );
205
206
207 // @TODO - The block below could use refactoring, see new function wppb_prepare_key_value_options.
208 // country select
209 $default_country_array = wppb_country_select_options( 'back_end' );
210 foreach( $default_country_array as $iso_country_code => $country_name ) {
211 $default_country_options[] = '%'. wppb_prepare_wck_labels( $country_name ) .'%'.$iso_country_code;
212 }
213
214 // @TODO - The block below could use refactoring, see new function wppb_prepare_key_value_options.
215 // currency select
216 $default_currency_array = wppb_get_currencies( 'back_end' );
217 array_unshift( $default_currency_array, '' );
218 foreach( $default_currency_array as $iso_currency_code => $currency_name ) {
219 $default_currency_options[] = '%'. wppb_prepare_wck_labels( $currency_name ) .'%'.$iso_currency_code;
220 }
221
222 //cpt select
223 $post_types_objects = get_post_types( array( 'public' => true ), 'objects' );
224 $post_types = array();
225
226 if ( !empty( $post_types_objects ) ) {
227 // Loop through the post types objects and extract the labels
228 foreach ( $post_types_objects as $types ) {
229 if ( isset( $types->label ) )
230 array_push( $post_types, '%' . wppb_prepare_wck_labels( $types->label ) . '%' . $types->name );
231 }
232 }
233
234 //taxonomy select
235 $taxonomies_objects = get_taxonomies( array( 'public' => true ), 'objects' );
236 $taxonomies = array();
237
238 if ( !empty( $taxonomies_objects ) ) {
239 // Loop through the taxonomies objects and extract the labels
240 foreach ( $taxonomies_objects as $taxonomy ) {
241 if ( isset( $taxonomy->label ) )
242 array_push( $taxonomies, '%' . wppb_prepare_wck_labels( $taxonomy->label ) . '%' . $taxonomy->name );
243 }
244 }
245
246 if( apply_filters( 'wppb_update_field_meta_key_in_db', false ) ) {
247 $meta_key_description = __( 'Use this in conjunction with WordPress functions to display the value in the page of your choosing<br/>Auto-completed but in some cases editable (in which case it must be unique)<br/>Changing this might take long in case of a very big user-count', 'profile-builder' );
248 }
249 else{
250 $meta_key_description = __( 'Use this in conjunction with WordPress functions to display the value in the page of your choosing<br/>Auto-completed but in some cases editable (in which case it must be unique)<br/>Changing this will only affect subsequent entries', 'profile-builder' );
251 }
252
253 // Initiate the list of available tags for the pin bubble.
254 if( function_exists( 'wppb_generate_userlisting_merge_tags' ) ) {
255 $bubble_meta_tags = wppb_generate_userlisting_merge_tags('meta');
256 $bubble_meta_tags = wp_list_pluck($bubble_meta_tags, 'label', 'name');
257 }
258 else
259 $bubble_meta_tags = array();
260
261 // set up the fields array
262 $fields = apply_filters( 'wppb_manage_fields', array(
263
264 array( 'type' => 'text', 'slug' => 'field-title', 'title' => __( 'Field Title', 'profile-builder' ), 'description' => __( 'Title of the field', 'profile-builder' ) ),
265 array( 'type' => 'select', 'slug' => 'field', 'title' => __( 'Field', 'profile-builder' ), 'options' => apply_filters( 'wppb_manage_fields_types_options', $manage_field_types ), 'default-option' => true, 'description' => $field_description ),
266 array( 'type' => 'text', 'slug' => 'meta-name', 'title' => __( 'Meta-name', 'profile-builder' ), 'default' => wppb_get_meta_name(), 'description' => $meta_key_description ),
267 array( 'type' => 'text', 'slug' => 'id', 'title' => __( 'ID', 'profile-builder' ), 'default' => wppb_get_unique_id(), 'description' => __( "A unique, auto-generated ID for this particular field<br/>You can use this in conjuction with filters to target this element if needed<br/>Can't be edited", 'profile-builder' ), 'readonly' => true ),
268 array( 'type' => 'textarea', 'slug' => 'description', 'title' => __( 'Description', 'profile-builder' ), 'description' => __( 'Enter a (detailed) description of the option for end users to read<br/>Optional', 'profile-builder') ),
269 array( 'type' => 'text', 'slug' => 'row-count', 'title' => __( 'Row Count', 'profile-builder' ), 'default' => 5, 'description' => __( "Specify the number of rows for a 'Textarea' field<br/>If not specified, defaults to 5", 'profile-builder' ) ),
270 array( 'type' => 'text', 'slug' => 'allowed-image-extensions', 'title' => __( 'Allowed Image Extensions', 'profile-builder' ), 'default' => '.*', 'description' => __( 'Specify the extension(s) you want to limit to upload<br/>Example: .ext1,.ext2,.ext3<br/>If not specified, defaults to: .jpg,.jpeg,.gif,.png (.*)', 'profile-builder' ) ),
271 array( 'type' => 'checkbox', 'slug' => 'simple-upload', 'title' => __( 'Use Simple Upload', 'profile-builder' ), 'options' => array( '%'.__('Yes','profile-builder').'%'.'yes' ), 'description' => __( 'Use a simple upload field instead of the WordPress upload', 'profile-builder' ) ),
272 array( 'type' => 'text', 'slug' => 'allowed-upload-extensions', 'title' => __( 'Allowed Upload Extensions', 'profile-builder' ), 'default' => '.*', 'description' => __( 'Specify the extension(s) you want to limit to upload<br/>Example: .ext1,.ext2,.ext3<br/>If not specified, defaults to all WordPress allowed file extensions (.*)', 'profile-builder' ) ),
273 array( 'type' => 'text', 'slug' => 'avatar-size', 'title' => __( 'Avatar Size', 'profile-builder' ), 'default' => 100, 'description' => __( "Enter a value (between 20 and 800) for the size of the 'Avatar'<br/>If not specified, defaults to 100", 'profile-builder' ) ),
274 array( 'type' => 'text', 'slug' => 'max-file-size', 'title' => __( 'Maximum File Size (MB)', 'profile-builder' ), 'description' => __( 'Specify the maximum file size allowed for upload (in MB)<br/>If not specified, defaults to the server maximum upload size', 'profile-builder' ) ),
275 array( 'type' => 'text', 'slug' => 'date-format', 'title' => __( 'Date-format', 'profile-builder' ), 'default' => 'mm/dd/yy', 'description' => __( 'Specify the format of the date when using Datepicker<br/>Valid options: mm/dd/yy, mm/yy/dd, dd/yy/mm, dd/mm/yy, yy/dd/mm, yy/mm/dd, mm-dd-yy, yy-mm-dd, D, dd M yy, D, d M y, DD, dd-M-y, D, d M yy, mm/yy, mm/dd, dd/mm, @<br/>If not specified, defaults to mm/dd/yy<br/>ATTENTION: if you plan to use this field for sorting, please make sure to use year first, then month, and day last.', 'profile-builder' ) ),
276 array( 'type' => 'textarea', 'slug' => 'terms-of-agreement', 'title' => __( 'Terms of Agreement', 'profile-builder' ), 'description' => __( 'Enter a detailed description of the terms of agreement for the user to read.<br/>Links can be inserted by using standard HTML syntax: &lt;a href="custom_url"&gt;custom_text&lt;/a&gt;', 'profile-builder' ) ),
277 array( 'type' => 'text', 'slug' => 'options', 'title' => __( 'Options', 'profile-builder' ), 'description' => __( "Enter a comma separated list of values<br/>This can be anything, as it is hidden from the user, but should not contain special characters or apostrophes", 'profile-builder' ) ),
278 array( 'type' => 'text', 'slug' => 'labels', 'title' => __( 'Labels', 'profile-builder' ), 'description' => __( "Enter a comma separated list of labels<br/>Visible for the user", 'profile-builder' ) ),
279 array( 'type' => 'select', 'slug' => 'recaptcha-type', 'title' => __( 'reCAPTCHA Type', 'profile-builder' ), 'options' => array('%reCAPTCHA V2 Checkbox%v2', '%reCAPTCHA V2 Invisible%invisible', '%reCAPTCHA V3%v3'), 'default' => 'v2', 'description' => __( 'Choose the <a href="https://developers.google.com/recaptcha/docs/versions" target="_blank">type of reCAPTCHA</a> you wish to add to this site.<br/>Please note that the Invisible reCAPTCHA is a type of reCAPTCHA v2.', 'profile-builder' ) ),
280 array( 'type' => 'text', 'slug' => 'public-key', 'title' => __( 'Site Key', 'profile-builder' ), 'description' => __( 'The site key from Google, <a href="https://www.google.com/recaptcha/admin/create" target="_blank">https://www.google.com/recaptcha/admin/create</a>', 'profile-builder' ) ),
281 array( 'type' => 'text', 'slug' => 'private-key', 'title' => __( 'Secret Key', 'profile-builder' ), 'description' => __( 'The secret key from Google, <a href="https://www.google.com/recaptcha/admin/create" target="_blank">https://www.google.com/recaptcha/admin/create</a>', 'profile-builder' ) ),
282 array( 'type' => 'text', 'slug' => 'score-threshold', 'title' => __( 'Score Threshold', 'profile-builder' ), 'default' => 0.5, 'description' => __( 'The required score threshold: 1.0 is very likely a good interaction, 0.0 is very likely a bot<br/>If not specified, defaults to 0.5', 'profile-builder' ) ),
283 array( 'type' => 'checkbox', 'slug' => 'captcha-pb-forms', 'title' => __( 'Display on PB forms', 'profile-builder' ), 'options' => array( '%'.__('PB Login','profile-builder').'%'.'pb_login', '%'.__('PB Register','profile-builder').'%'.'pb_register', '%'.__('PB Recover Password','profile-builder').'%'.'pb_recover_password' ), 'default' => 'pb_register', 'description' => __( "Select on which Profile Builder forms to display reCAPTCHA", 'profile-builder' ) ),
284 array( 'type' => 'checkbox', 'slug' => 'captcha-wp-forms', 'title' => __( 'Display on default WP forms', 'profile-builder' ), 'options' => array( '%'.__('Default WP Login', 'profile-builder').'%'.'default_wp_login', '%'.__('Default WP Register', 'profile-builder').'%'.'default_wp_register', '%'.__('Default WP Recover Password', 'profile-builder').'%'.'default_wp_recover_password', '%'.__('Default WP Comments', 'profile-builder').'%'.'default_wp_comments'), 'default' => 'default_wp_register', 'description' => __( "Select on which default WP forms to display reCAPTCHA", 'profile-builder' ) ),
285 array( 'type' => 'select', 'slug' => 'theme', 'title' => __( 'Turnstile Theme', 'profile-builder' ), 'options' => array('%Auto%auto', '%Light%light', '%Dark%dark'), 'default' => 'auto', 'description' => __( 'Choose the theme for the Turnstile widget. The Auto option conforms to the user system preferences.', 'profile-builder' ) ),
286 array( 'type' => 'text', 'slug' => 'turnstile-site-key', 'title' => __( 'Site Key', 'profile-builder' ), 'description' => __( 'The site key from <a href="https://dash.cloudflare.com/?to=/:account/turnstile" target="_blank">Cloudflare</a>', 'profile-builder' ) ),
287 array( 'type' => 'text', 'slug' => 'turnstile-secret-key', 'title' => __( 'Secret Key', 'profile-builder' ), 'description' => __( 'The secret key from <a href="https://dash.cloudflare.com/?to=/:account/turnstile" target="_blank">Cloudflare</a>', 'profile-builder' ) ),
288 array( 'type' => 'checkbox', 'slug' => 'turnstile-pb-forms', 'title' => __( 'Display on PB forms', 'profile-builder' ), 'options' => array( '%'.__('PB Login','profile-builder').'%'.'pb_login', '%'.__('PB Register','profile-builder').'%'.'pb_register', '%'.__('PB Recover Password','profile-builder').'%'.'pb_recover_password' ), 'default' => 'pb_register', 'description' => __( "Select on which Profile Builder forms to display Turnstile", 'profile-builder' ) ),
289 array( 'type' => 'checkbox', 'slug' => 'turnstile-wp-forms', 'title' => __( 'Display on default WP forms', 'profile-builder' ), 'options' => array( '%'.__('Default WP Login', 'profile-builder').'%'.'default_wp_login', '%'.__('Default WP Register', 'profile-builder').'%'.'default_wp_register', '%'.__('Default WP Recover Password', 'profile-builder').'%'.'default_wp_recover_password', '%'.__('Default WP Comments', 'profile-builder').'%'.'default_wp_comments'), 'default' => 'default_wp_register', 'description' => __( "Select on which default WP forms to display Turnstile", 'profile-builder' ) ),
290 array( 'type' => 'checkbox', 'slug' => 'user-roles', 'title' => __( 'User Roles', 'profile-builder' ), 'options' => $user_roles, 'description' => __( "Select which user roles to show to the user ( drag and drop to re-order )", 'profile-builder' ) ),
291 array( 'type' => 'checkbox', 'slug' => 'user-roles-on-edit-profile', 'title' => __( 'Display on Edit Profile', 'profile-builder' ), 'options' => array('%Yes%yes'), 'description' => __( "Check if you want the select user role field to appear on Edit Profile forms", 'profile-builder' ) ),
292 array( 'type' => 'text', 'slug' => 'user-roles-sort-order', 'title' => __( 'User Roles Order', 'profile-builder' ), 'description' => __( "Save the user role order from the user roles checkboxes", 'profile-builder' ) ),
293 array( 'type' => 'text', 'slug' => 'default-value', 'title' => __( 'Default Value', 'profile-builder' ), 'description' => __( "Default value of the field", 'profile-builder' ) ),
294 array( 'type' => 'text', 'slug' => 'default-option', 'title' => __( 'Default Option', 'profile-builder' ), 'description' => __( "Specify the option which should be selected by default", 'profile-builder' ) ),
295 array( 'type' => 'text', 'slug' => 'default-options', 'title' => __( 'Default Option(s)', 'profile-builder' ), 'description' => __( "Specify the option which should be checked by default<br/>If there are multiple values, separate them with a ',' (comma)", 'profile-builder' ) ),
296 array( 'type' => 'select', 'slug' => 'default-option-country', 'title' => __( 'Default Option', 'profile-builder' ), 'options' => ( isset( $default_country_options ) ) ? $default_country_options : '', 'description' => __( "Default option of the field", 'profile-builder' ) ),
297 array( 'type' => 'select', 'slug' => 'default-option-timezone', 'title' => __( 'Default Option', 'profile-builder' ), 'options' => wppb_timezone_select_options( 'back_end' ), 'description' => __( "Default option of the field", 'profile-builder' ) ),
298 array( 'type' => 'select', 'slug' => 'default-option-currency', 'title' => __( 'Default Option', 'profile-builder' ), 'options' => ( isset( $default_currency_options ) ) ? $default_currency_options : '', 'description' => __( "Default option of the field", 'profile-builder' ) ),
299 array( 'type' => 'select', 'slug' => 'show-currency-symbol', 'title' => __( 'Show Currency Symbol', 'profile-builder' ), 'options' => array( 'No', 'Yes' ), 'default' => 'No', 'description' => __( 'Whether the currency symbol should be displayed after the currency name in the select option.', 'profile-builder' ) ),
300 array( 'type' => 'select', 'slug' => 'cpt', 'title' => __( 'Show Post Type', 'profile-builder' ), 'options' => $post_types, 'default' => 'post', 'description' => __( 'Posts from what post type will be displayed in the select.', 'profile-builder' ) ),
301 array( 'type' => 'select', 'slug' => 'taxonomy', 'title' => __( 'Show Taxonomy Term', 'profile-builder' ), 'options' => $taxonomies, 'default' => 'category', 'description' => __( 'Terms from taxonomies', 'profile-builder' ) ),
302 array( 'type' => 'text', 'slug' => 'validation-possible-values', 'title' => __( 'Allowable Values', 'profile-builder' ), 'description' => __( "Enter a comma separated list of possible values. Upon registration if the value provided by the user does not match one of these values, the user will not be registered.", 'profile-builder' ) ),
303 array( 'type' => 'text', 'slug' => 'custom-error-message', 'title' => __( 'Error Message', 'profile-builder' ), 'description' => __( "Set a custom error message that will be displayed to the user.", 'profile-builder' ) ),
304 array( 'type' => 'select', 'slug' => 'time-format', 'title' => __( 'Time Format', 'profile-builder' ), 'options' => array( '%12 Hours%12', '%24 Hours%24' ), 'description' => __( 'Specify the time format.', 'profile-builder' ) ),
305 array( 'type' => 'text', 'slug' => 'map-api-key', 'title' => __( 'Google Maps API Key', 'profile-builder' ), 'description' => __( 'Enter your Google Maps API key ( <a href="https://console.developers.google.com/flows/enableapi?apiid=maps_backend" target="_blank">Get your API key</a> ). If more than one map fields are added to a form the API key from the first map displayed will be used.', 'profile-builder' ) ),
306
307 array(
308 'type' => 'text',
309 'slug' => 'map-default-lat',
310 'title' => __( 'Default Latitude', 'profile-builder' ),
311 'description' => __( 'The latitude at which the map should be displayed when no pins are attached.', 'profile-builder' ),
312 'default' => WPPB_DEFAULTS_MAP_LAT,
313 ),
314 array(
315 'type' => 'text',
316 'slug' => 'map-default-lng',
317 'title' => __( 'Default Longitude', 'profile-builder' ),
318 'description' => __( 'The longitude at which the map should be displayed when no pins are attached.', 'profile-builder' ),
319 'default' => WPPB_DEFAULTS_MAP_LNG,
320 ),
321 array(
322 'type' => 'text',
323 'slug' => 'map-default-zoom',
324 'title' => __( 'Default Zoom Level', 'profile-builder' ),
325 'description' => __( 'Add a number from 0 to 19. The higher the number the higher the zoom.', 'profile-builder' ),
326 'default' => WPPB_DEFAULTS_MAP_ZOOM,
327 ),
328
329 array( 'type' => 'text', 'slug' => 'map-height', 'title' => __( 'Map Height', 'profile-builder' ), 'description' => __( "The height of the map.", 'profile-builder' ), 'default' => 400 ),
330 array( 'type' => 'textarea', 'slug' => 'default-content', 'title' => __( 'Default Content', 'profile-builder' ), 'description' => __( "Default value of the textarea", 'profile-builder' ) ),
331 array( 'type' => 'textarea', 'slug' => 'html-content', 'title' => __( 'HTML Content', 'profile-builder' ), 'description' => __( "Add your HTML (or text) content", 'profile-builder' ) ),
332 array( 'type' => 'text', 'slug' => 'phone-format', 'title' => __( 'Phone Format', 'profile-builder' ), 'default' => '(###) ###-####', 'description' => __( "You can use: # for numbers, parentheses ( ), - sign, + sign, dot . and spaces.", 'profile-builder' ) .'<br>'. __( "Eg. (###) ###-####", 'profile-builder' ) .'<br>'. __( "Empty field won't check for correct phone number.", 'profile-builder' ) ),
333 array( 'type' => 'select', 'slug' => 'heading-tag', 'title' => __( 'Heading Tag', 'profile-builder' ), 'options' => array( '%h1 - biggest size%h1', 'h2', 'h3', 'h4', 'h5', '%h6 - smallest size%h6' ), 'default' => 'h4', 'description' => __( 'Change heading field size on front-end forms', 'profile-builder' ) ),
334 array( 'type' => 'text', 'slug' => 'min-number-value', 'title' => __( 'Min Number Value', 'profile-builder' ), 'description' => __( "Min allowed number value (0 to allow only positive numbers)", 'profile-builder' ) .'<br>'. __( "Leave it empty for no min value", 'profile-builder' ) ),
335 array( 'type' => 'text', 'slug' => 'max-number-value', 'title' => __( 'Max Number Value', 'profile-builder' ), 'description' => __( "Max allowed number value (0 to allow only negative numbers)", 'profile-builder' ) .'<br>'. __( "Leave it empty for no max value", 'profile-builder' ) ),
336 array( 'type' => 'checkbox', 'slug' => 'ask-current-password', 'title' => __( 'Ask for Current Password', 'profile-builder' ), 'options' => array( '%' . __( 'Yes', 'profile-builder' ) . '%yes' ), 'description' => __( 'On Edit Profile forms, require users to enter their current password before changing it. This applies only when users change their own password.', 'profile-builder' ) ),
337 array( 'type' => 'text', 'slug' => 'number-step-value', 'title' => __( 'Number Step Value', 'profile-builder' ), 'description' => __( "Step value 1 to allow only integers, 0.1 to allow integers and numbers with 1 decimal", 'profile-builder' ) .'<br>'. __( "To allow multiple decimals use for eg. 0.01 (for 2 deciamls) and so on", 'profile-builder' ) .'<br>'. __( "You can also use step value to specify the legal number intervals (eg. step value 2 will allow only -4, -2, 0, 2 and so on)", 'profile-builder' ) .'<br>'. __( "Leave it empty for no restriction", 'profile-builder' ) ),
338 array( 'type' => 'select', 'slug' => 'required', 'title' => __( 'Required', 'profile-builder' ), 'options' => array( 'No', 'Yes' ), 'default' => 'No', 'description' => __( 'Whether the field is required or not', 'profile-builder' ) ),
339 array( 'type' => 'select', 'slug' => 'overwrite-existing', 'title' => __( 'Overwrite Existing', 'profile-builder' ), 'options' => array( 'No', 'Yes' ), 'default' => 'No', 'description' => __( "Selecting 'Yes' will add the field to the list, but will overwrite any other field in the database that has the same meta-name<br/>Use this at your own risk", 'profile-builder' ) ),
340 array( 'type' => 'text', 'slug' => 'initial-country', 'title' => __( 'Initial Country', 'profile-builder' ), 'description' => __( "Set the initial country for the phone field. Use 'auto' to detect it automatically by IP, or enter one ISO 3166-1 alpha-2 country code (e.g. ro, jp, us).", 'profile-builder' ), 'default' => 'auto' ),
341 array( 'type' => 'text', 'slug' => 'preferred-countries', 'title' => __( 'Preferred Countries', 'profile-builder' ), 'description' => __( "Set preferred countries using ISO 3166-1 alpha-2 codes (e.g. ro, jp, us), separated by commas.", 'profile-builder' ), 'default' => '' ),
342 array( 'type' => 'text', 'slug' => 'excluded-countries', 'title' => __( 'Excluded Countries', 'profile-builder' ), 'description' => __( "Exclude countries using ISO 3166-1 alpha-2 codes (e.g. af, ru, us), separated by commas.", 'profile-builder' ), 'default' => '' ),
343 array( 'type' => 'checkbox', 'slug' => 'national-mode', 'title' => __( 'National Mode', 'profile-builder' ), 'options' => array( '%'.__('Yes','profile-builder').'%'.'yes' ), 'description' => __( "Enable National Mode to enter numbers in local format (without country prefix). Disable it to use International Mode (with country prefix).", 'profile-builder' ) ),
344 array( 'type' => 'checkbox', 'slug' => 'hide-flags', 'title' => __( 'Hide Flags', 'profile-builder' ), 'options' => array( '%'.__('Yes','profile-builder').'%'.'yes' ), 'description' => __( "Enable to hide country flags in the phone field.", 'profile-builder' ) ),
345
346 // Added the new option for the map field type, that allows to customize the POIs load type.
347 array(
348 'type' => 'select',
349 'slug' => 'map-pins-load-type',
350 'title' => __( 'POIs Load Type', 'profile-builder' ),
351 'options' => array(
352 '%' . __( 'POIs of the listed users (as filtered & paginated)', 'profile-builder' ) . '%',
353 '%' . __( 'POIs of all the users for the filter* (no pagination)', 'profile-builder' ) . '%all',
354 ),
355 'default' => '',
356 'description' => __( 'This option allows you to load on a single map the POIs for all users, or just these for the listed ones (this will take into account the filters and the faceted menus). *Please use this feature wisely, it will impact the performance.', 'profile-builder' ),
357 ),
358
359 // Added the new option for the map field type, that allows to customize the POI bubble content.
360 array(
361 'type' => 'checkbox',
362 'slug' => 'map-bubble-fields',
363 'title' => __( 'POI Bubble Info', 'profile-builder' ),
364 'options' => wppb_prepare_key_value_options( apply_filters( 'wppb_map_bubble_fields', $bubble_meta_tags ) ),
365 'default' => 'avatar_or_gravatar, meta_display_name',
366 'description' => __( 'Select the attributes to be listed inside the POI bubble.', 'profile-builder' ),
367 'extra_attributes' => array(
368 'dropdown_options' => true,
369 'sortable_options' => true,
370 ),
371 ),
372
373 // Added the new option for the map field type, that allows to customize the number of users per iteration.
374 array(
375 'type' => 'text',
376 'slug' => 'map-pagination-number',
377 'title' => __( 'Number of Users per Map Iteration', 'profile-builder' ),
378 'description' => __( 'When loading the map of all users with no pagination, the map script will iterate multiple times and will expose gradually POIs on the map, until all the POIs for the users that match the criteria will be added on the map (think of this as of pagination for the map POIs). The smaller the number of users per iteration, the fastest the iteration response will be, but for a large number of users, the map script will iterate multiple times. Setting a higher limit will decrease the performance, but might produce a smaller number of iterations. <br><br><b>Please adjust this value to your hosting capabilities, and make sure that the value you set is the best for performance.</b> We recommend a <b>maximum</b> value of 300.', 'profile-builder' ),
379 'default' => 50,
380 ),
381
382 //add Select 2 attributes
383 array( 'type' => 'text', 'slug' => 'select2-multiple-limit', 'title' => __( 'Maximum Selections', 'profile-builder' ), 'description' => __( "Select2 multi-value select boxes can set restrictions regarding the maximum number of options selected.", 'profile-builder' ) ),
384 array( 'type' => 'checkbox', 'slug' => 'select2-multiple-tags', 'title' => __( 'User Inputted Options', 'profile-builder' ), 'options' => array( '%Enable user inputted options%yes' ), 'description' => __( "Check this to allow users to create their own options beside the pre-existing ones.", 'profile-builder' ) ),
385
386 ) );
387
388 // create the new submenu with the above options
389 $args = array(
390 'metabox_id' => 'manage-fields',
391 'metabox_title' => __( 'Form Field Properties', 'profile-builder' ),
392 'post_type' => 'manage-fields',
393 'meta_name' => 'wppb_manage_fields',
394 'meta_array' => $fields,
395 'context' => 'option'
396 );
397 new Wordpress_Creation_Kit_PB( $args );
398
399 /* this is redundant but it should have a very low impact and for comfort we leave it here as well */
400 wppb_prepopulate_fields();
401
402
403 // skip this meta-box for the Repeater Field -> Edit Field Group view
404 if ( !isset( $_GET['wppb_rpf_repeater_meta_name'] ) ) {
405
406 // create the info side meta-box
407 $args = array(
408 'metabox_id' => 'manage-fields-info',
409 'metabox_title' => __( 'Form Shortcodes', 'profile-builder' ),
410 'post_type' => 'manage-fields',
411 'meta_name' => 'wppb_manage_fields_info',
412 'meta_array' => '',
413 'context' => 'option',
414 'mb_context' => 'side'
415 );
416 new Wordpress_Creation_Kit_PB( $args );
417
418 }
419 }
420 add_action( 'admin_init', 'wppb_populate_manage_fields', 1 );
421
422 /**
423 * Function that prepopulates the manage fields list with the default fields of WP
424 *
425 * @since v.2.0
426 *
427 * @return void
428 */
429 function wppb_prepopulate_fields(){
430 $prepopulated_fields[] = array( 'field' => 'Default - Name (Heading)', 'field-title' => __( 'Name', 'profile-builder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '1', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
431 $prepopulated_fields[] = array( 'field' => 'Default - Username', 'field-title' => __( 'Username', 'profile-builder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '2', 'description' => __( 'Usernames cannot be changed.', 'profile-builder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' );
432 $prepopulated_fields[] = array( 'field' => 'Default - First Name', 'field-title' => __( 'First Name', 'profile-builder' ), 'meta-name' => 'first_name', 'overwrite-existing' => 'No', 'id' => '3', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
433 $prepopulated_fields[] = array( 'field' => 'Default - Last Name', 'field-title' => __( 'Last Name', 'profile-builder' ), 'meta-name' => 'last_name', 'overwrite-existing' => 'No', 'id' => '4', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
434 $prepopulated_fields[] = array( 'field' => 'Default - Nickname', 'field-title' => __( 'Nickname', 'profile-builder' ), 'meta-name' => 'nickname', 'overwrite-existing' => 'No', 'id' => '5', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' );
435 $prepopulated_fields[] = array( 'field' => 'Default - Display name publicly as', 'field-title' => __( 'Display name publicly as', 'profile-builder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '6', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
436 $prepopulated_fields[] = array( 'field' => 'Default - Contact Info (Heading)', 'field-title' => __( 'Contact Info', 'profile-builder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '7', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
437 $prepopulated_fields[] = array( 'field' => 'Default - E-mail', 'field-title' => __( 'E-mail', 'profile-builder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '8', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' );
438 $prepopulated_fields[] = array( 'field' => 'Default - Website', 'field-title' => __( 'Website', 'profile-builder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '9', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
439
440 // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
441 if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){
442 $prepopulated_fields[] = array( 'field' => 'Default - AIM', 'field-title' => __( 'AIM', 'profile-builder' ), 'meta-name' => 'aim', 'overwrite-existing' => 'No', 'id' => '10', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
443 $prepopulated_fields[] = array( 'field' => 'Default - Yahoo IM', 'field-title' => __( 'Yahoo IM', 'profile-builder' ), 'meta-name' => 'yim', 'overwrite-existing' => 'No', 'id' => '11', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
444 $prepopulated_fields[] = array( 'field' => 'Default - Jabber / Google Talk', 'field-title' => __( 'Jabber / Google Talk', 'profile-builder' ), 'meta-name' => 'jabber', 'overwrite-existing' => 'No', 'id' => '12', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
445 }
446
447 $prepopulated_fields[] = array( 'field' => 'Default - About Yourself (Heading)', 'field-title' => __( 'About Yourself', 'profile-builder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '13', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
448 $prepopulated_fields[] = array( 'field' => 'Default - Biographical Info', 'field-title' => __( 'Biographical Info', 'profile-builder' ), 'meta-name' => 'description', 'overwrite-existing' => 'No', 'id' => '14', 'description' => __( 'Share a little biographical information to fill out your profile. This may be shown publicly.', 'profile-builder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'required' => 'No' );
449 $prepopulated_fields[] = array( 'field' => 'Default - Password', 'field-title' => __( 'Password', 'profile-builder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '15', 'description' => __( 'Type your password.', 'profile-builder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' );
450 $prepopulated_fields[] = array( 'field' => 'Default - Repeat Password', 'field-title' => __( 'Repeat Password', 'profile-builder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '16', 'description' => __( 'Type your password again. ', 'profile-builder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' );
451 if ( wppb_can_users_signup_blog() ){
452 $prepopulated_fields[] = array( 'field' => 'Default - Blog Details', 'field-title' => __( 'Blog Details', 'profile-builder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '17', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
453 }
454
455 add_option ( 'wppb_manage_fields', apply_filters ( 'wppb_prepopulated_fields', $prepopulated_fields ) );
456 }
457
458 /**
459 * Function that returns a unique meta-name
460 *
461 * @since v.2.0
462 *
463 * @return string
464 */
465 function wppb_get_meta_name( $option = 'wppb_manage_fields', $prefix = 'custom_field_' ){
466 $id = 1;
467
468 $wppb_manage_fields = get_option( $option, 'not_found' );
469
470 if ( ( $wppb_manage_fields === 'not_found' ) || ( empty( $wppb_manage_fields ) ) ){
471 return $prefix . $id;
472 }
473 else{
474 $meta_names = array();
475 foreach( $wppb_manage_fields as $value ){
476 if ( strpos( $value['meta-name'], $prefix ) === 0 ){
477 $meta_names[] = $value['meta-name'];
478 }
479 }
480
481 if( !empty( $meta_names ) ){
482 $meta_numbers = array();
483 foreach( $meta_names as $meta_name ){
484 $number = str_replace( $prefix, '', $meta_name );
485 /* we should have an underscore present in custom_field_# so remove it */
486 $number = str_replace( '_', '', $number );
487
488 $meta_numbers[] = $number;
489 }
490 if( !empty( $meta_numbers ) ){
491 rsort( $meta_numbers );
492 $id = (int)$meta_numbers[0] + 1;
493 }
494 }
495
496 return $prefix . $id;
497 }
498 }
499
500
501 /**
502 * Function that returns an array with countries
503 *
504 * @since v.2.0
505 *
506 * @return array
507 */
508 function wppb_country_select_options( $form_location ) {
509 $country_array = apply_filters( 'wppb_'.$form_location.'_country_select_array',
510 array(
511 '' => __( 'Select a Country', 'profile-builder' ),
512 'AF' => __( 'Afghanistan', 'profile-builder' ),
513 'AX' => __( 'Aland Islands', 'profile-builder' ),
514 'AL' => __( 'Albania', 'profile-builder' ),
515 'DZ' => __( 'Algeria', 'profile-builder' ),
516 'AS' => __( 'American Samoa', 'profile-builder' ),
517 'AD' => __( 'Andorra', 'profile-builder' ),
518 'AO' => __( 'Angola', 'profile-builder' ),
519 'AI' => __( 'Anguilla', 'profile-builder' ),
520 'AQ' => __( 'Antarctica', 'profile-builder' ),
521 'AG' => __( 'Antigua and Barbuda', 'profile-builder' ),
522 'AR' => __( 'Argentina', 'profile-builder' ),
523 'AM' => __( 'Armenia', 'profile-builder' ),
524 'AW' => __( 'Aruba', 'profile-builder' ),
525 'AU' => __( 'Australia', 'profile-builder' ),
526 'AT' => __( 'Austria', 'profile-builder' ),
527 'AZ' => __( 'Azerbaijan', 'profile-builder' ),
528 'BS' => __( 'Bahamas', 'profile-builder' ),
529 'BH' => __( 'Bahrain', 'profile-builder' ),
530 'BD' => __( 'Bangladesh', 'profile-builder' ),
531 'BB' => __( 'Barbados', 'profile-builder' ),
532 'BY' => __( 'Belarus', 'profile-builder' ),
533 'BE' => __( 'Belgium', 'profile-builder' ),
534 'BZ' => __( 'Belize', 'profile-builder' ),
535 'BJ' => __( 'Benin', 'profile-builder' ),
536 'BM' => __( 'Bermuda', 'profile-builder' ),
537 'BT' => __( 'Bhutan', 'profile-builder' ),
538 'BO' => __( 'Bolivia', 'profile-builder' ),
539 'BQ' => __( 'Bonaire, Saint Eustatius and Saba', 'profile-builder' ),
540 'BA' => __( 'Bosnia and Herzegovina', 'profile-builder' ),
541 'BW' => __( 'Botswana', 'profile-builder' ),
542 'BV' => __( 'Bouvet Island', 'profile-builder' ),
543 'BR' => __( 'Brazil', 'profile-builder' ),
544 'IO' => __( 'British Indian Ocean Territory', 'profile-builder' ),
545 'VG' => __( 'British Virgin Islands', 'profile-builder' ),
546 'BN' => __( 'Brunei', 'profile-builder' ),
547 'BG' => __( 'Bulgaria', 'profile-builder' ),
548 'BF' => __( 'Burkina Faso', 'profile-builder' ),
549 'BI' => __( 'Burundi', 'profile-builder' ),
550 'KH' => __( 'Cambodia', 'profile-builder' ),
551 'CM' => __( 'Cameroon', 'profile-builder' ),
552 'CA' => __( 'Canada', 'profile-builder' ),
553 'CV' => __( 'Cape Verde', 'profile-builder' ),
554 'KY' => __( 'Cayman Islands', 'profile-builder' ),
555 'CF' => __( 'Central African Republic', 'profile-builder' ),
556 'TD' => __( 'Chad', 'profile-builder' ),
557 'CL' => __( 'Chile', 'profile-builder' ),
558 'CN' => __( 'China', 'profile-builder' ),
559 'CX' => __( 'Christmas Island', 'profile-builder' ),
560 'CC' => __( 'Cocos Islands', 'profile-builder' ),
561 'CO' => __( 'Colombia', 'profile-builder' ),
562 'KM' => __( 'Comoros', 'profile-builder' ),
563 'CK' => __( 'Cook Islands', 'profile-builder' ),
564 'CR' => __( 'Costa Rica', 'profile-builder' ),
565 'HR' => __( 'Croatia', 'profile-builder' ),
566 'CU' => __( 'Cuba', 'profile-builder' ),
567 'CW' => __( 'Curacao', 'profile-builder' ),
568 'CY' => __( 'Cyprus', 'profile-builder' ),
569 'CZ' => __( 'Czech Republic', 'profile-builder' ),
570 'CD' => __( 'Democratic Republic of the Congo', 'profile-builder' ),
571 'DK' => __( 'Denmark', 'profile-builder' ),
572 'DJ' => __( 'Djibouti', 'profile-builder' ),
573 'DM' => __( 'Dominica', 'profile-builder' ),
574 'DO' => __( 'Dominican Republic', 'profile-builder' ),
575 'TL' => __( 'East Timor', 'profile-builder' ),
576 'EC' => __( 'Ecuador', 'profile-builder' ),
577 'EG' => __( 'Egypt', 'profile-builder' ),
578 'SV' => __( 'El Salvador', 'profile-builder' ),
579 'GQ' => __( 'Equatorial Guinea', 'profile-builder' ),
580 'ER' => __( 'Eritrea', 'profile-builder' ),
581 'EE' => __( 'Estonia', 'profile-builder' ),
582 'ET' => __( 'Ethiopia', 'profile-builder' ),
583 'FK' => __( 'Falkland Islands', 'profile-builder' ),
584 'FO' => __( 'Faroe Islands', 'profile-builder' ),
585 'FJ' => __( 'Fiji', 'profile-builder' ),
586 'FI' => __( 'Finland', 'profile-builder' ),
587 'FR' => __( 'France', 'profile-builder' ),
588 'GF' => __( 'French Guiana', 'profile-builder' ),
589 'PF' => __( 'French Polynesia', 'profile-builder' ),
590 'TF' => __( 'French Southern Territories', 'profile-builder' ),
591 'GA' => __( 'Gabon', 'profile-builder' ),
592 'GM' => __( 'Gambia', 'profile-builder' ),
593 'GE' => __( 'Georgia', 'profile-builder' ),
594 'DE' => __( 'Germany', 'profile-builder' ),
595 'GH' => __( 'Ghana', 'profile-builder' ),
596 'GI' => __( 'Gibraltar', 'profile-builder' ),
597 'GR' => __( 'Greece', 'profile-builder' ),
598 'GL' => __( 'Greenland', 'profile-builder' ),
599 'GD' => __( 'Grenada', 'profile-builder' ),
600 'GP' => __( 'Guadeloupe', 'profile-builder' ),
601 'GU' => __( 'Guam', 'profile-builder' ),
602 'GT' => __( 'Guatemala', 'profile-builder' ),
603 'GG' => __( 'Guernsey', 'profile-builder' ),
604 'GN' => __( 'Guinea', 'profile-builder' ),
605 'GW' => __( 'Guinea-Bissau', 'profile-builder' ),
606 'GY' => __( 'Guyana', 'profile-builder' ),
607 'HT' => __( 'Haiti', 'profile-builder' ),
608 'HM' => __( 'Heard Island and McDonald Islands', 'profile-builder' ),
609 'HN' => __( 'Honduras', 'profile-builder' ),
610 'HK' => __( 'Hong Kong', 'profile-builder' ),
611 'HU' => __( 'Hungary', 'profile-builder' ),
612 'IS' => __( 'Iceland', 'profile-builder' ),
613 'IN' => __( 'India', 'profile-builder' ),
614 'ID' => __( 'Indonesia', 'profile-builder' ),
615 'IR' => __( 'Iran', 'profile-builder' ),
616 'IQ' => __( 'Iraq', 'profile-builder' ),
617 'IE' => __( 'Ireland', 'profile-builder' ),
618 'IM' => __( 'Isle of Man', 'profile-builder' ),
619 'IL' => __( 'Israel', 'profile-builder' ),
620 'IT' => __( 'Italy', 'profile-builder' ),
621 'CI' => __( 'Ivory Coast', 'profile-builder' ),
622 'JM' => __( 'Jamaica', 'profile-builder' ),
623 'JP' => __( 'Japan', 'profile-builder' ),
624 'JE' => __( 'Jersey', 'profile-builder' ),
625 'JO' => __( 'Jordan', 'profile-builder' ),
626 'KZ' => __( 'Kazakhstan', 'profile-builder' ),
627 'KE' => __( 'Kenya', 'profile-builder' ),
628 'KI' => __( 'Kiribati', 'profile-builder' ),
629 'XK' => __( 'Kosovo', 'profile-builder' ),
630 'KW' => __( 'Kuwait', 'profile-builder' ),
631 'KG' => __( 'Kyrgyzstan', 'profile-builder' ),
632 'LA' => __( 'Laos', 'profile-builder' ),
633 'LV' => __( 'Latvia', 'profile-builder' ),
634 'LB' => __( 'Lebanon', 'profile-builder' ),
635 'LS' => __( 'Lesotho', 'profile-builder' ),
636 'LR' => __( 'Liberia', 'profile-builder' ),
637 'LY' => __( 'Libya', 'profile-builder' ),
638 'LI' => __( 'Liechtenstein', 'profile-builder' ),
639 'LT' => __( 'Lithuania', 'profile-builder' ),
640 'LU' => __( 'Luxembourg', 'profile-builder' ),
641 'MO' => __( 'Macao', 'profile-builder' ),
642 'MK' => __( 'Macedonia', 'profile-builder' ),
643 'MG' => __( 'Madagascar', 'profile-builder' ),
644 'MW' => __( 'Malawi', 'profile-builder' ),
645 'MY' => __( 'Malaysia', 'profile-builder' ),
646 'MV' => __( 'Maldives', 'profile-builder' ),
647 'ML' => __( 'Mali', 'profile-builder' ),
648 'MT' => __( 'Malta', 'profile-builder' ),
649 'MH' => __( 'Marshall Islands', 'profile-builder' ),
650 'MQ' => __( 'Martinique', 'profile-builder' ),
651 'MR' => __( 'Mauritania', 'profile-builder' ),
652 'MU' => __( 'Mauritius', 'profile-builder' ),
653 'YT' => __( 'Mayotte', 'profile-builder' ),
654 'MX' => __( 'Mexico', 'profile-builder' ),
655 'FM' => __( 'Micronesia', 'profile-builder' ),
656 'MD' => __( 'Moldova', 'profile-builder' ),
657 'MC' => __( 'Monaco', 'profile-builder' ),
658 'MN' => __( 'Mongolia', 'profile-builder' ),
659 'ME' => __( 'Montenegro', 'profile-builder' ),
660 'MS' => __( 'Montserrat', 'profile-builder' ),
661 'MA' => __( 'Morocco', 'profile-builder' ),
662 'MZ' => __( 'Mozambique', 'profile-builder' ),
663 'MM' => __( 'Myanmar', 'profile-builder' ),
664 'NA' => __( 'Namibia', 'profile-builder' ),
665 'NR' => __( 'Nauru', 'profile-builder' ),
666 'NP' => __( 'Nepal', 'profile-builder' ),
667 'NL' => __( 'Netherlands', 'profile-builder' ),
668 'NC' => __( 'New Caledonia', 'profile-builder' ),
669 'NZ' => __( 'New Zealand', 'profile-builder' ),
670 'NI' => __( 'Nicaragua', 'profile-builder' ),
671 'NE' => __( 'Niger', 'profile-builder' ),
672 'NG' => __( 'Nigeria', 'profile-builder' ),
673 'NU' => __( 'Niue', 'profile-builder' ),
674 'NF' => __( 'Norfolk Island', 'profile-builder' ),
675 'KP' => __( 'North Korea', 'profile-builder' ),
676 'MP' => __( 'Northern Mariana Islands', 'profile-builder' ),
677 'NO' => __( 'Norway', 'profile-builder' ),
678 'OM' => __( 'Oman', 'profile-builder' ),
679 'PK' => __( 'Pakistan', 'profile-builder' ),
680 'PW' => __( 'Palau', 'profile-builder' ),
681 'PS' => __( 'Palestinian Territory', 'profile-builder' ),
682 'PA' => __( 'Panama', 'profile-builder' ),
683 'PG' => __( 'Papua New Guinea', 'profile-builder' ),
684 'PY' => __( 'Paraguay', 'profile-builder' ),
685 'PE' => __( 'Peru', 'profile-builder' ),
686 'PH' => __( 'Philippines', 'profile-builder' ),
687 'PN' => __( 'Pitcairn', 'profile-builder' ),
688 'PL' => __( 'Poland', 'profile-builder' ),
689 'PT' => __( 'Portugal', 'profile-builder' ),
690 'PR' => __( 'Puerto Rico', 'profile-builder' ),
691 'QA' => __( 'Qatar', 'profile-builder' ),
692 'CG' => __( 'Republic of the Congo', 'profile-builder' ),
693 'RE' => __( 'Reunion', 'profile-builder' ),
694 'RO' => __( 'Romania', 'profile-builder' ),
695 'RU' => __( 'Russia', 'profile-builder' ),
696 'RW' => __( 'Rwanda', 'profile-builder' ),
697 'BL' => __( 'Saint Barthelemy', 'profile-builder' ),
698 'SH' => __( 'Saint Helena', 'profile-builder' ),
699 'KN' => __( 'Saint Kitts and Nevis', 'profile-builder' ),
700 'LC' => __( 'Saint Lucia', 'profile-builder' ),
701 'MF' => __( 'Saint Martin', 'profile-builder' ),
702 'PM' => __( 'Saint Pierre and Miquelon', 'profile-builder' ),
703 'VC' => __( 'Saint Vincent and the Grenadines', 'profile-builder' ),
704 'WS' => __( 'Samoa', 'profile-builder' ),
705 'SM' => __( 'San Marino', 'profile-builder' ),
706 'ST' => __( 'Sao Tome and Principe', 'profile-builder' ),
707 'SA' => __( 'Saudi Arabia', 'profile-builder' ),
708 'SN' => __( 'Senegal', 'profile-builder' ),
709 'RS' => __( 'Serbia', 'profile-builder' ),
710 'SC' => __( 'Seychelles', 'profile-builder' ),
711 'SL' => __( 'Sierra Leone', 'profile-builder' ),
712 'SG' => __( 'Singapore', 'profile-builder' ),
713 'SX' => __( 'Sint Maarten', 'profile-builder' ),
714 'SK' => __( 'Slovakia', 'profile-builder' ),
715 'SI' => __( 'Slovenia', 'profile-builder' ),
716 'SB' => __( 'Solomon Islands', 'profile-builder' ),
717 'SO' => __( 'Somalia', 'profile-builder' ),
718 'ZA' => __( 'South Africa', 'profile-builder' ),
719 'GS' => __( 'South Georgia and the South Sandwich Islands', 'profile-builder' ),
720 'KR' => __( 'South Korea', 'profile-builder' ),
721 'SS' => __( 'South Sudan', 'profile-builder' ),
722 'ES' => __( 'Spain', 'profile-builder' ),
723 'LK' => __( 'Sri Lanka', 'profile-builder' ),
724 'SD' => __( 'Sudan', 'profile-builder' ),
725 'SR' => __( 'Suriname', 'profile-builder' ),
726 'SJ' => __( 'Svalbard and Jan Mayen', 'profile-builder' ),
727 'SZ' => __( 'Swaziland', 'profile-builder' ),
728 'SE' => __( 'Sweden', 'profile-builder' ),
729 'CH' => __( 'Switzerland', 'profile-builder' ),
730 'SY' => __( 'Syria', 'profile-builder' ),
731 'TW' => __( 'Taiwan', 'profile-builder' ),
732 'TJ' => __( 'Tajikistan', 'profile-builder' ),
733 'TZ' => __( 'Tanzania', 'profile-builder' ),
734 'TH' => __( 'Thailand', 'profile-builder' ),
735 'TG' => __( 'Togo', 'profile-builder' ),
736 'TK' => __( 'Tokelau', 'profile-builder' ),
737 'TO' => __( 'Tonga', 'profile-builder' ),
738 'TT' => __( 'Trinidad and Tobago', 'profile-builder' ),
739 'TN' => __( 'Tunisia', 'profile-builder' ),
740 'TR' => __( 'Turkey', 'profile-builder' ),
741 'TM' => __( 'Turkmenistan', 'profile-builder' ),
742 'TC' => __( 'Turks and Caicos Islands', 'profile-builder' ),
743 'TV' => __( 'Tuvalu', 'profile-builder' ),
744 'VI' => __( 'U.S. Virgin Islands', 'profile-builder' ),
745 'UG' => __( 'Uganda', 'profile-builder' ),
746 'UA' => __( 'Ukraine', 'profile-builder' ),
747 'AE' => __( 'United Arab Emirates', 'profile-builder' ),
748 'GB' => __( 'United Kingdom', 'profile-builder' ),
749 'US' => __( 'United States', 'profile-builder' ),
750 'UM' => __( 'United States Minor Outlying Islands', 'profile-builder' ),
751 'UY' => __( 'Uruguay', 'profile-builder' ),
752 'UZ' => __( 'Uzbekistan', 'profile-builder' ),
753 'VU' => __( 'Vanuatu', 'profile-builder' ),
754 'VA' => __( 'Vatican', 'profile-builder' ),
755 'VE' => __( 'Venezuela', 'profile-builder' ),
756 'VN' => __( 'Vietnam', 'profile-builder' ),
757 'WF' => __( 'Wallis and Futuna', 'profile-builder' ),
758 'EH' => __( 'Western Sahara', 'profile-builder' ),
759 'YE' => __( 'Yemen', 'profile-builder' ),
760 'ZM' => __( 'Zambia', 'profile-builder' ),
761 'ZW' => __( 'Zimbabwe', 'profile-builder' ),
762 )
763 );
764
765 return wppb_translate_countries( $country_array );
766 }
767
768 /**
769 * Helper function to translate country names with WPML
770 * Registers strings in WPML String Translation and returns translated value
771 */
772 function wppb_translate_countries( $countries ) {
773
774 if ( !function_exists( 'icl_register_string' ) || !function_exists( 'icl_t' ) ) {
775 return $countries;
776 }
777
778 foreach( $countries as $index => $country ){
779 $prefix = 'country_' . $country;
780 icl_register_string( 'profile-builder', $prefix, $country );
781 $countries[$index] = icl_t( 'profile-builder', $prefix, $country );
782 }
783
784 return $countries;
785 }
786
787 /**
788 * Function that returns an array with timezone options
789 *
790 * @since v.2.0
791 *
792 * @return array
793 */
794 function wppb_timezone_select_options( $form_location ) {
795 $timezone_array = apply_filters( 'wppb_'.$form_location.'_timezone_select_array', array ( '(GMT -12:00) Eniwetok, Kwajalein', '(GMT -11:00) Midway Island, Samoa', '(GMT -10:00) Hawaii', '(GMT -9:00) Alaska', '(GMT -8:00) Pacific Time (US & Canada)', '(GMT -7:00) Mountain Time (US & Canada)', '(GMT -6:00) Central Time (US & Canada), Mexico City', '(GMT -5:00) Eastern Time (US & Canada), Bogota, Lima', '(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz', '(GMT -3:30) Newfoundland', '(GMT -3:00) Brazil, Buenos Aires, Georgetown', '(GMT -2:00) Mid-Atlantic', '(GMT -1:00) Azores, Cape Verde Islands', '(GMT) Western Europe Time, London, Lisbon, Casablanca', '(GMT +1:00) Brussels, Copenhagen, Madrid, Paris', '(GMT +2:00) Kaliningrad, South Africa', '(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg', '(GMT +3:30) Tehran', '(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi', '(GMT +4:30) Kabul', '(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent', '(GMT +5:30) Bombay, Calcutta, Madras, New Delhi', '(GMT +5:45) Kathmandu', '(GMT +6:00) Almaty, Dhaka, Colombo', '(GMT +7:00) Bangkok, Hanoi, Jakarta', '(GMT +8:00) Beijing, Perth, Singapore, Hong Kong', '(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk', '(GMT +9:30) Adelaide, Darwin', '(GMT +10:00) Eastern Australia, Guam, Vladivostok', '(GMT +11:00) Magadan, Solomon Islands, New Caledonia', '(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka' ) );
796
797 return $timezone_array;
798 }
799
800
801 /*
802 * Array with the currency ISO code and associated currency name
803 *
804 * @param string $form_location
805 *
806 * @return array
807 *
808 */
809 function wppb_get_currencies( $form_location = '' ) {
810
811 $currencies = array(
812 'ALL' => __( 'Albania Lek', 'profile-builder' ),
813 'AFN' => __( 'Afghanistan Afghani', 'profile-builder' ),
814 'ARS' => __( 'Argentina Peso', 'profile-builder' ),
815 'AWG' => __( 'Aruba Guilder', 'profile-builder' ),
816 'AUD' => __( 'Australia Dollar', 'profile-builder' ),
817 'AZN' => __( 'Azerbaijan New Manat', 'profile-builder' ),
818 'BSD' => __( 'Bahamas Dollar', 'profile-builder' ),
819 'BBD' => __( 'Barbados Dollar','profile-builder' ),
820 'BDT' => __( 'Bangladeshi taka','profile-builder' ),
821 'BYR' => __( 'Belarus Ruble','profile-builder' ),
822 'BZD' => __( 'Belize Dollar','profile-builder' ),
823 'BMD' => __( 'Bermuda Dollar','profile-builder' ),
824 'BOB' => __( 'Bolivia Boliviano','profile-builder' ),
825 'BAM' => __( 'Bosnia and Herzegovina Convertible Marka','profile-builder' ),
826 'BWP' => __( 'Botswana Pula','profile-builder' ),
827 'BGN' => __( 'Bulgaria Lev','profile-builder' ),
828 'BRL' => __( 'Brazil Real','profile-builder' ),
829 'BND' => __( 'Brunei Darussalam Dollar','profile-builder' ),
830 'KHR' => __( 'Cambodia Riel','profile-builder' ),
831 'CAD' => __( 'Canada Dollar','profile-builder' ),
832 'KYD' => __( 'Cayman Islands Dollar','profile-builder' ),
833 'CLP' => __( 'Chile Peso','profile-builder' ),
834 'CNY' => __( 'China Yuan Renminbi','profile-builder' ),
835 'COP' => __( 'Colombia Peso','profile-builder' ),
836 'CRC' => __( 'Costa Rica Colon','profile-builder' ),
837 'HRK' => __( 'Croatia Kuna','profile-builder' ),
838 'CUP' => __( 'Cuba Peso','profile-builder' ),
839 'CZK' => __( 'Czech Republic Koruna','profile-builder' ),
840 'DKK' => __( 'Denmark Krone','profile-builder' ),
841 'DOP' => __( 'Dominican Republic Peso','profile-builder' ),
842 'XCD' => __( 'East Caribbean Dollar','profile-builder' ),
843 'EGP' => __( 'Egypt Pound','profile-builder' ),
844 'SVC' => __( 'El Salvador Colon','profile-builder' ),
845 'EEK' => __( 'Estonia Kroon','profile-builder' ),
846 'EUR' => __( 'Euro','profile-builder' ),
847 'FKP' => __( 'Falkland Islands (Malvinas) Pound','profile-builder' ),
848 'FJD' => __( 'Fiji Dollar','profile-builder' ),
849 'GHC' => __( 'Ghana Cedis','profile-builder' ),
850 'GIP' => __( 'Gibraltar Pound','profile-builder' ),
851 'GTQ' => __( 'Guatemala Quetzal','profile-builder' ),
852 'GGP' => __( 'Guernsey Pound','profile-builder' ),
853 'GYD' => __( 'Guyana Dollar','profile-builder' ),
854 'HNL' => __( 'Honduras Lempira','profile-builder' ),
855 'HKD' => __( 'Hong Kong Dollar','profile-builder' ),
856 'HUF' => __( 'Hungary Forint','profile-builder' ),
857 'ISK' => __( 'Iceland Krona','profile-builder' ),
858 'INR' => __( 'India Rupee','profile-builder' ),
859 'IDR' => __( 'Indonesia Rupiah','profile-builder' ),
860 'IRR' => __( 'Iran Rial','profile-builder' ),
861 'IMP' => __( 'Isle of Man Pound','profile-builder' ),
862 'ILS' => __( 'Israel Shekel','profile-builder' ),
863 'JMD' => __( 'Jamaica Dollar','profile-builder' ),
864 'JPY' => __( 'Japan Yen','profile-builder' ),
865 'JEP' => __( 'Jersey Pound','profile-builder' ),
866 'KZT' => __( 'Kazakhstan Tenge','profile-builder' ),
867 'KPW' => __( 'Korea (North) Won','profile-builder' ),
868 'KRW' => __( 'Korea (South) Won','profile-builder' ),
869 'KGS' => __( 'Kyrgyzstan Som','profile-builder' ),
870 'LAK' => __( 'Laos Kip','profile-builder' ),
871 'LVL' => __( 'Latvia Lat','profile-builder' ),
872 'LBP' => __( 'Lebanon Pound','profile-builder' ),
873 'LRD' => __( 'Liberia Dollar','profile-builder' ),
874 'LTL' => __( 'Lithuania Litas','profile-builder' ),
875 'MKD' => __( 'Macedonia Denar','profile-builder' ),
876 'MYR' => __( 'Malaysia Ringgit','profile-builder' ),
877 'MUR' => __( 'Mauritius Rupee','profile-builder' ),
878 'MXN' => __( 'Mexico Peso','profile-builder' ),
879 'MNT' => __( 'Mongolia Tughrik','profile-builder' ),
880 'MZN' => __( 'Mozambique Metical','profile-builder' ),
881 'NAD' => __( 'Namibia Dollar','profile-builder' ),
882 'NPR' => __( 'Nepal Rupee','profile-builder' ),
883 'ANG' => __( 'Netherlands Antilles Guilder','profile-builder' ),
884 'NZD' => __( 'New Zealand Dollar','profile-builder' ),
885 'NIO' => __( 'Nicaragua Cordoba','profile-builder' ),
886 'NGN' => __( 'Nigeria Naira','profile-builder' ),
887 'NOK' => __( 'Norway Krone','profile-builder' ),
888 'OMR' => __( 'Oman Rial', 'profile-builder' ),
889 'PKR' => __( 'Pakistan Rupee', 'profile-builder' ),
890 'PAB' => __( 'Panama Balboa', 'profile-builder' ),
891 'PYG' => __( 'Paraguay Guarani', 'profile-builder' ),
892 'PEN' => __( 'Peru Nuevo Sol', 'profile-builder' ),
893 'PHP' => __( 'Philippines Peso', 'profile-builder' ),
894 'PLN' => __( 'Poland Zloty', 'profile-builder' ),
895 'QAR' => __( 'Qatar Riyal', 'profile-builder' ),
896 'RON' => __( 'Romania New Leu', 'profile-builder' ),
897 'RUB' => __( 'Russia Ruble', 'profile-builder' ),
898 'SHP' => __( 'Saint Helena Pound', 'profile-builder' ),
899 'SAR' => __( 'Saudi Arabia Riyal', 'profile-builder' ),
900 'RSD' => __( 'Serbia Dinar', 'profile-builder' ),
901 'SCR' => __( 'Seychelles Rupee', 'profile-builder' ),
902 'SGD' => __( 'Singapore Dollar', 'profile-builder' ),
903 'SBD' => __( 'Solomon Islands Dollar', 'profile-builder' ),
904 'SOS' => __( 'Somalia Shilling', 'profile-builder' ),
905 'ZAR' => __( 'South Africa Rand', 'profile-builder' ),
906 'LKR' => __( 'Sri Lanka Rupee', 'profile-builder' ),
907 'SEK' => __( 'Sweden Krona', 'profile-builder' ),
908 'CHF' => __( 'Switzerland Franc', 'profile-builder' ),
909 'SRD' => __( 'Suriname Dollar', 'profile-builder' ),
910 'SYP' => __( 'Syria Pound', 'profile-builder' ),
911 'TWD' => __( 'Taiwan New Dollar', 'profile-builder' ),
912 'THB' => __( 'Thailand Baht', 'profile-builder' ),
913 'TTD' => __( 'Trinidad and Tobago Dollar', 'profile-builder' ),
914 'TRY' => __( 'Turkey Lira', 'profile-builder' ),
915 'TRL' => __( 'Turkey Lira', 'profile-builder' ),
916 'TVD' => __( 'Tuvalu Dollar', 'profile-builder' ),
917 'UAH' => __( 'Ukraine Hryvna', 'profile-builder' ),
918 'GBP' => __( 'United Kingdom Pound', 'profile-builder' ),
919 'UGX' => __( 'Uganda Shilling', 'profile-builder' ),
920 'USD' => __( 'US Dollar', 'profile-builder' ),
921 'UYU' => __( 'Uruguay Peso', 'profile-builder' ),
922 'UZS' => __( 'Uzbekistan Som', 'profile-builder' ),
923 'VEF' => __( 'Venezuela Bolivar', 'profile-builder' ),
924 'VND' => __( 'Viet Nam Dong', 'profile-builder' ),
925 'YER' => __( 'Yemen Rial', 'profile-builder' ),
926 'ZWD' => __( 'Zimbabwe Dollar', 'profile-builder' )
927 );
928
929 $filter_name = ( empty( $form_location ) ? 'wppb_get_currencies' : 'wppb_get_currencies_' . $form_location );
930
931 return apply_filters( $filter_name, $currencies );
932
933 }
934
935
936 /*
937 * Returns the currency symbol for a given currency code
938 *
939 * @param string $currency_code
940 *
941 * @return string
942 *
943 */
944 function wppb_get_currency_symbol( $currency_code ) {
945
946 $currency_symbols = array(
947 'AED' => '&#1583;.&#1573;', // ?
948 'AFN' => '&#65;&#102;',
949 'ALL' => '&#76;&#101;&#107;',
950 'AMD' => '',
951 'ANG' => '&#402;',
952 'AOA' => '&#75;&#122;', // ?
953 'ARS' => '&#36;',
954 'AUD' => '&#36;',
955 'AWG' => '&#402;',
956 'AZN' => '&#1084;&#1072;&#1085;',
957 'BAM' => '&#75;&#77;',
958 'BBD' => '&#36;',
959 'BDT' => '&#2547;', // ?
960 'BGN' => '&#1083;&#1074;',
961 'BHD' => '.&#1583;.&#1576;', // ?
962 'BIF' => '&#70;&#66;&#117;', // ?
963 'BMD' => '&#36;',
964 'BND' => '&#36;',
965 'BOB' => '&#36;&#98;',
966 'BRL' => '&#82;&#36;',
967 'BSD' => '&#36;',
968 'BTN' => '&#78;&#117;&#46;', // ?
969 'BWP' => '&#80;',
970 'BYR' => '&#112;&#46;',
971 'BZD' => '&#66;&#90;&#36;',
972 'CAD' => '&#36;',
973 'CDF' => '&#70;&#67;',
974 'CHF' => '&#67;&#72;&#70;',
975 'CLF' => '', // ?
976 'CLP' => '&#36;',
977 'CNY' => '&#165;',
978 'COP' => '&#36;',
979 'CRC' => '&#8353;',
980 'CUP' => '&#8396;',
981 'CVE' => '&#36;', // ?
982 'CZK' => '&#75;&#269;',
983 'DJF' => '&#70;&#100;&#106;', // ?
984 'DKK' => '&#107;&#114;',
985 'DOP' => '&#82;&#68;&#36;',
986 'DZD' => '&#1583;&#1580;', // ?
987 'EGP' => '&#163;',
988 'ETB' => '&#66;&#114;',
989 'EUR' => '&#8364;',
990 'FJD' => '&#36;',
991 'FKP' => '&#163;',
992 'GBP' => '&#163;',
993 'GEL' => '&#4314;', // ?
994 'GHS' => '&#162;',
995 'GIP' => '&#163;',
996 'GMD' => '&#68;', // ?
997 'GNF' => '&#70;&#71;', // ?
998 'GTQ' => '&#81;',
999 'GYD' => '&#36;',
1000 'HKD' => '&#36;',
1001 'HNL' => '&#76;',
1002 'HRK' => '&#107;&#110;',
1003 'HTG' => '&#71;', // ?
1004 'HUF' => '&#70;&#116;',
1005 'IDR' => '&#82;&#112;',
1006 'ILS' => '&#8362;',
1007 'INR' => '&#8377;',
1008 'IQD' => '&#1593;.&#1583;', // ?
1009 'IRR' => '&#65020;',
1010 'ISK' => '&#107;&#114;',
1011 'JEP' => '&#163;',
1012 'JMD' => '&#74;&#36;',
1013 'JOD' => '&#74;&#68;', // ?
1014 'JPY' => '&#165;',
1015 'KES' => '&#75;&#83;&#104;', // ?
1016 'KGS' => '&#1083;&#1074;',
1017 'KHR' => '&#6107;',
1018 'KMF' => '&#67;&#70;', // ?
1019 'KPW' => '&#8361;',
1020 'KRW' => '&#8361;',
1021 'KWD' => '&#1583;.&#1603;', // ?
1022 'KYD' => '&#36;',
1023 'KZT' => '&#1083;&#1074;',
1024 'LAK' => '&#8365;',
1025 'LBP' => '&#163;',
1026 'LKR' => '&#8360;',
1027 'LRD' => '&#36;',
1028 'LSL' => '&#76;', // ?
1029 'LTL' => '&#76;&#116;',
1030 'LVL' => '&#76;&#115;',
1031 'LYD' => '&#1604;.&#1583;', // ?
1032 'MAD' => '&#1583;.&#1605;.', //?
1033 'MDL' => '&#76;',
1034 'MGA' => '&#65;&#114;', // ?
1035 'MKD' => '&#1076;&#1077;&#1085;',
1036 'MMK' => '&#75;',
1037 'MNT' => '&#8366;',
1038 'MOP' => '&#77;&#79;&#80;&#36;', // ?
1039 'MRO' => '&#85;&#77;', // ?
1040 'MUR' => '&#8360;', // ?
1041 'MVR' => '.&#1923;', // ?
1042 'MWK' => '&#77;&#75;',
1043 'MXN' => '&#36;',
1044 'MYR' => '&#82;&#77;',
1045 'MZN' => '&#77;&#84;',
1046 'NAD' => '&#36;',
1047 'NGN' => '&#8358;',
1048 'NIO' => '&#67;&#36;',
1049 'NOK' => '&#107;&#114;',
1050 'NPR' => '&#8360;',
1051 'NZD' => '&#36;',
1052 'OMR' => '&#65020;',
1053 'PAB' => '&#66;&#47;&#46;',
1054 'PEN' => '&#83;&#47;&#46;',
1055 'PGK' => '&#75;', // ?
1056 'PHP' => '&#8369;',
1057 'PKR' => '&#8360;',
1058 'PLN' => '&#122;&#322;',
1059 'PYG' => '&#71;&#115;',
1060 'QAR' => '&#65020;',
1061 'RON' => '&#108;&#101;&#105;',
1062 'RSD' => '&#1044;&#1080;&#1085;&#46;',
1063 'RUB' => '&#1088;&#1091;&#1073;',
1064 'RWF' => '&#1585;.&#1587;',
1065 'SAR' => '&#65020;',
1066 'SBD' => '&#36;',
1067 'SCR' => '&#8360;',
1068 'SDG' => '&#163;', // ?
1069 'SEK' => '&#107;&#114;',
1070 'SGD' => '&#36;',
1071 'SHP' => '&#163;',
1072 'SLL' => '&#76;&#101;', // ?
1073 'SOS' => '&#83;',
1074 'SRD' => '&#36;',
1075 'STD' => '&#68;&#98;', // ?
1076 'SVC' => '&#36;',
1077 'SYP' => '&#163;',
1078 'SZL' => '&#76;', // ?
1079 'THB' => '&#3647;',
1080 'TJS' => '&#84;&#74;&#83;', // ? TJS (guess)
1081 'TMT' => '&#109;',
1082 'TND' => '&#1583;.&#1578;',
1083 'TOP' => '&#84;&#36;',
1084 'TRY' => '&#8356;', // New Turkey Lira (old symbol used)
1085 'TTD' => '&#36;',
1086 'TWD' => '&#78;&#84;&#36;',
1087 'TZS' => '',
1088 'UAH' => '&#8372;',
1089 'UGX' => '&#85;&#83;&#104;',
1090 'USD' => '&#36;',
1091 'UYU' => '&#36;&#85;',
1092 'UZS' => '&#1083;&#1074;',
1093 'VEF' => '&#66;&#115;',
1094 'VND' => '&#8363;',
1095 'VUV' => '&#86;&#84;',
1096 'WST' => '&#87;&#83;&#36;',
1097 'XAF' => '&#70;&#67;&#70;&#65;',
1098 'XCD' => '&#36;',
1099 'XDR' => '',
1100 'XOF' => '',
1101 'XPF' => '&#70;',
1102 'YER' => '&#65020;',
1103 'ZAR' => '&#82;',
1104 'ZMK' => '&#90;&#75;', // ?
1105 'ZWL' => '&#90;&#36;',
1106 );
1107
1108 if( !empty( $currency_symbols[$currency_code] ) )
1109 return $currency_symbols[$currency_code];
1110 else
1111 return '';
1112
1113 }
1114
1115
1116 /**
1117 * Function that returns a unique, incremented ID
1118 *
1119 * @since v.2.0
1120 *
1121 * @return integer id
1122 */
1123 function wppb_get_unique_id(){
1124 $id = 1;
1125 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
1126 if ( ( $wppb_manage_fields === 'not_found' ) || ( empty( $wppb_manage_fields ) ) ){
1127 return $id;
1128 }
1129 else{
1130 $ids_array = array();
1131 foreach( $wppb_manage_fields as $value ){
1132 $ids_array[] = $value['id'];
1133 }
1134 if( !empty( $ids_array ) ){
1135 rsort( $ids_array );
1136 $id = $ids_array[0] + 1;
1137 }
1138 }
1139 return apply_filters( 'wppb_field_unique_id', $id, $ids_array, $wppb_manage_fields );
1140 }
1141
1142 /**
1143 * Function that checks to see if the id is unique when saving the new field
1144 *
1145 * @param array $values
1146 *
1147 * @return array
1148 */
1149 function wppb_check_unique_id_on_saving( $values ) {
1150 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
1151
1152 if( $wppb_manage_fields != 'not_found' ) {
1153
1154 $ids_array = array();
1155 foreach( $wppb_manage_fields as $field ){
1156 $ids_array[] = $field['id'];
1157 }
1158
1159 if( in_array( $values['id'], $ids_array ) ) {
1160 rsort( $ids_array );
1161 $values['id'] = $ids_array[0] + 1;
1162 }
1163
1164 }
1165 return $values;
1166 }
1167 add_filter( 'wck_add_meta_filter_values_wppb_manage_fields', 'wppb_check_unique_id_on_saving' );
1168
1169
1170 function wppb_return_unique_field_list( $only_default_fields = false ){
1171
1172 $unique_field_list[] = 'Default - Name (Heading)';
1173 $unique_field_list[] = 'Default - Contact Info (Heading)';
1174 $unique_field_list[] = 'Default - About Yourself (Heading)';
1175 $unique_field_list[] = 'Default - Username';
1176 $unique_field_list[] = 'Default - First Name';
1177 $unique_field_list[] = 'Default - Last Name';
1178 $unique_field_list[] = 'Default - Nickname';
1179 $unique_field_list[] = 'Default - E-mail';
1180 $unique_field_list[] = 'Default - Website';
1181
1182 // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
1183 if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){
1184 $unique_field_list[] = 'Default - AIM';
1185 $unique_field_list[] = 'Default - Yahoo IM';
1186 $unique_field_list[] = 'Default - Jabber / Google Talk';
1187 }
1188
1189 $unique_field_list[] = 'Default - Password';
1190 $unique_field_list[] = 'Default - Repeat Password';
1191 $unique_field_list[] = 'Default - Biographical Info';
1192 $unique_field_list[] = 'Default - Display name publicly as';
1193
1194 $unique_field_list[] = 'GDPR Checkbox';
1195
1196 $unique_field_list[] = 'Email Confirmation';
1197
1198 if ( wppb_can_users_signup_blog() ) {
1199 $unique_field_list[] = 'Default - Blog Details';
1200 }
1201
1202 if( !$only_default_fields ){
1203 $unique_field_list[] = 'Avatar';
1204 $unique_field_list[] = 'reCAPTCHA';
1205 $unique_field_list[] = 'Turnstile';
1206 $unique_field_list[] = 'Select (User Role)';
1207 $unique_field_list[] = 'Map';
1208 }
1209
1210 return apply_filters ( 'wppb_unique_field_list', $unique_field_list );
1211 }
1212
1213
1214 /**
1215 * Function that checks several things when adding/editing the fields
1216 *
1217 * @since v.2.0
1218 *
1219 * @param string $message - the message to be displayed
1220 * @param array $fields - the added fields
1221 * @param array $required_fields
1222 * @param string $meta - the meta-name of the option
1223 * @param string $values - The values entered for each option
1224 * @param integer $post_id
1225 * @return boolean
1226 */
1227 function wppb_check_field_on_edit_add( $message, $fields, $required_fields, $meta_name, $posted_values, $post_id ){
1228 global $wpdb;
1229
1230 if ( $meta_name == 'wppb_manage_fields' ){
1231
1232 // check for a valid field-type (fallback)
1233 if ( $posted_values['field'] == '' )
1234 $message .= __( "You must select a field\n", 'profile-builder' );
1235 // END check for a valid field-type (fallback)
1236
1237 $unique_field_list = wppb_return_unique_field_list();
1238 $all_fields = apply_filters( 'wppb_manage_fields_check_field_on_edit_add', get_option ( $meta_name, 'not_set' ), $posted_values );
1239
1240 // check if the unique fields are only added once
1241 if( $all_fields != 'not_set' ){
1242 foreach( $all_fields as $field ){
1243 if ( ( in_array ( $posted_values['field'], $unique_field_list ) ) && ( $posted_values['field'] == $field['field'] ) && ( $posted_values['id'] != $field['id'] ) ){
1244 $message .= __( "Please choose a different field type as this one already exists in your form (must be unique)\n", 'profile-builder' );
1245 break;
1246 }
1247
1248 if ( ( $posted_values['field'] == 'reCAPTCHA' && $field['field'] == 'Turnstile' ) || ( $posted_values['field'] == 'Turnstile' && $field['field'] == 'reCAPTCHA' ) ){
1249 $message .= __( "You cannot have both a reCAPTCHA and a Turnstile field! Please remove the other existing field first.\n", 'profile-builder' );
1250 break;
1251 }
1252 }
1253 }
1254 // END check if the unique fields are only added once
1255
1256 // check for avatar size
1257 if ( $posted_values['field'] == 'Avatar' ){
1258 if ( is_numeric( $posted_values['avatar-size'] ) ){
1259 if ( ( $posted_values['avatar-size'] < 20 ) || ( $posted_values['avatar-size'] > 800 ) )
1260 $message .= __( "The entered avatar size is not between 20 and 800\n", 'profile-builder' );
1261
1262 }else
1263 $message .= __( "The entered avatar size is not numerical\n", 'profile-builder' );
1264
1265 }
1266 // END check for avatar size
1267
1268 // check for max file size
1269 if ( in_array( $posted_values['field'], array( 'Avatar', 'Upload' ) ) ){
1270 if ( isset( $posted_values['max-file-size'] ) && $posted_values['max-file-size'] !== '' ){
1271 if ( !is_numeric( $posted_values['max-file-size'] ) || floatval( $posted_values['max-file-size'] ) <= 0 )
1272 $message .= __( "The entered maximum file size is not a valid positive number\n", 'profile-builder' );
1273 }
1274 }
1275 // END check for max file size
1276
1277 // check for correct row value
1278 if ( ( $posted_values['field'] == 'Default - Biographical Info' ) || ( $posted_values['field'] == 'Textarea' ) ){
1279 if ( !is_numeric( $posted_values['row-count'] ) )
1280 $message .= __( "The entered row number is not numerical\n", 'profile-builder' );
1281
1282 elseif ( trim( $posted_values['row-count'] ) == '' )
1283 $message .= __( "You must enter a value for the row number\n", 'profile-builder' );
1284 }
1285 // END check for correct row value
1286
1287
1288 // check for the public and private keys
1289 if ( $posted_values['field'] == 'reCAPTCHA' ){
1290 if ( trim( $posted_values['public-key'] ) == '' )
1291 $message .= __( "You must enter the site key!\n", 'profile-builder' );
1292 if ( trim( $posted_values['private-key'] ) == '' )
1293 $message .= __( "You must enter the secret key!\n", 'profile-builder' );
1294 }
1295 if ( $posted_values['field'] == 'Turnstile' ){
1296 if ( trim( $posted_values['turnstile-site-key'] ) == '' )
1297 $message .= __( "You must enter the site key!\n", 'profile-builder' );
1298 if ( trim( $posted_values['turnstile-secret-key'] ) == '' )
1299 $message .= __( "You must enter the secret key!\n", 'profile-builder' );
1300 }
1301 // END check for the public and private keys
1302
1303 // check for the correct the date-format
1304 if ( $posted_values['field'] == 'Datepicker' ){
1305 $date_format = trim( $posted_values['date-format'] );
1306 if( empty( $date_format ) )
1307 $message .= __( "You must enter a value for the date-format\n", 'profile-builder' );
1308 else {
1309 $date_format = preg_split("/(, | |\/|-|\.|,)/", $date_format );
1310 $valid_pieces = array('d', 'dd', 'D', 'DD', 'o', 'oo', 'm', 'mm', 'M', 'MM', 'y', 'yy', '@');
1311 if ($date_format) {
1312 $invalid_format = false;
1313 foreach ($date_format as $piece) {
1314 if (!in_array($piece, $valid_pieces)) {
1315 $invalid_format = true;
1316 break;
1317 }
1318 }
1319
1320 if ($invalid_format)
1321 $message .= __("The entered value for the Datepicker is not a valid date-format\n", 'profile-builder');
1322 }
1323 }
1324
1325 }
1326 // END check for the correct the date-format
1327
1328
1329 $skip_check_for_fields = wppb_return_unique_field_list(true);
1330 $skip_check_for_fields = apply_filters ( 'wppb_skip_check_for_fields', $skip_check_for_fields );
1331
1332 // check for empty, reserved and/or duplicate meta-name
1333 if ( !in_array( trim( $posted_values['field'] ), $skip_check_for_fields ) ) {
1334 $reserved_meta_name_list = wppb_get_reserved_meta_name_list( $all_fields, $posted_values );
1335
1336 //check to see if meta-name is empty
1337 $skip_empty_check_for_fields = array( 'Heading', 'Select (User Role)', 'reCAPTCHA', 'Turnstile', 'HTML', 'GDPR Delete Button' );
1338
1339 if( !in_array( $posted_values['field'], $skip_empty_check_for_fields ) && empty( $posted_values['meta-name'] ) ) {
1340 $message .= __( "The meta-name cannot be empty\n", 'profile-builder' );
1341 }
1342
1343 //check if the meta-name starts or ends with a space
1344 if ( strpos( $posted_values['meta-name'], " " ) === 0 ) {
1345 $message .= __( "The meta-name cannot begin with a space\n", 'profile-builder' );
1346 }
1347 if ( strpos( $posted_values['meta-name'], " " ) === strlen( $posted_values['meta-name'] ) - 1 ) {
1348 $message .= __( "The meta-name cannot end with a space\n", 'profile-builder' );
1349 }
1350
1351 // meta names that are reserved and cannot be used as part of other meta names
1352 $reserved_meta_name_list_strict = apply_filters( 'wppb_unique_meta_name_list_strict', array( 'map' ) );
1353 // skip meta name check for these fields
1354 $skip_unique_meta_name_list_check = apply_filters( 'wppb_skip_unique_meta_name_list_check', array( 'Map', 'Honeypot' ) );
1355
1356 // if the desired meta name is in the restricted list or if one of the meta names in the strictly
1357 // restricted list is part of it display an error message
1358 $is_reserved_meta_name = false;
1359 $trimmed_meta_name = trim( $posted_values['meta-name'] );
1360
1361 if ( !in_array( $posted_values['field'], $skip_unique_meta_name_list_check ) ) {
1362 foreach ( $reserved_meta_name_list as $reserved_meta_name ) {
1363
1364 if ( in_array( $trimmed_meta_name, $reserved_meta_name_list ) || ( strpos( $trimmed_meta_name, $reserved_meta_name ) !== false && in_array( $reserved_meta_name, $reserved_meta_name_list_strict ) ) ) {
1365 $is_reserved_meta_name = true;
1366 break;
1367 }
1368
1369 }
1370 }
1371
1372 if ( $is_reserved_meta_name ) {
1373 $message .= __( "That meta-name can't be used, please choose another\n", 'profile-builder' );
1374 }
1375 elseif ( $posted_values['overwrite-existing'] == 'No' ) { // check for duplicate meta-name
1376 $found_in_custom_fields = false;
1377
1378 if( $all_fields != 'not_set' )
1379 foreach( $all_fields as $field ){
1380
1381 if ( $posted_values['meta-name'] != '' && ( $field['meta-name'] == $posted_values['meta-name'] ) && ( $field['id'] != $posted_values['id'] ) ) {
1382 $message .= __( "That meta-name is already in use\n", 'profile-builder' );
1383 $found_in_custom_fields = true;
1384 }
1385 elseif ( ( $field['meta-name'] == $posted_values['meta-name'] ) && ( $field['id'] == $posted_values['id'] ) )
1386 $found_in_custom_fields = true;
1387
1388 }
1389
1390 if ( $found_in_custom_fields === false ) {
1391
1392 if( $posted_values['meta-name'] != '' ) {
1393 $found_meta_name = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->usermeta WHERE meta_key = %s", $posted_values['meta-name'] ) );
1394
1395 if ( $found_meta_name != null )
1396 $message .= __( "That meta-name is already in use\n", 'profile-builder' );
1397
1398 }
1399
1400 }
1401
1402 }
1403
1404 }
1405 //END check for empty, reserved and/or duplicate meta-name
1406
1407 // check for correct meta name
1408 if( $posted_values['field'] == 'Upload' ) {
1409 if( ! empty( $posted_values['meta-name'] ) && preg_match( '/([^a-z\d_-])/', $posted_values['meta-name'] ) ) {
1410 $message .= __( "The meta-name can only contain lowercase letters, numbers, _ , - and no spaces.\n", 'profile-builder' );
1411 }
1412 }
1413 elseif ( ! empty( $posted_values['meta-name'] ) && preg_match( '/\s/', $posted_values['meta-name'] ) ) {
1414 $message .= __( "The meta-name cannot contain spaces.\n", 'profile-builder' );
1415 }
1416
1417 // END check for correct meta name
1418
1419 // check for valid default option (checkbox, select, radio)
1420 if ( ( $posted_values['field'] == 'Checkbox' ) || ( $posted_values['field'] == 'Select (Multiple)' ) ) {
1421 $options = array_map( 'trim', explode( ',', $posted_values['options'] ) );
1422 $default_options = ( ( trim( $posted_values['default-options'] ) == '' ) ? array() : array_map( 'trim', explode( ',', $posted_values['default-options'] ) ) );
1423
1424 /* echo "<script>console.log( Posted options: " . print_r($options, true) . "' );</script>";
1425 echo "<script>console.log( Default options: " . print_r($default_options, true) . "' );</script>"; */
1426
1427 $not_found = '';
1428 foreach ( $default_options as $key => $value ){
1429 if ( !in_array( $value, $options ) )
1430 $not_found .= $value . ', ';
1431 }
1432
1433 if ( $not_found != '' )
1434 $message .= sprintf( __( "The following option(s) did not coincide with the ones in the options list: %s\n", 'profile-builder' ), trim( $not_found, ', ' ) );
1435
1436 }elseif ( ( $posted_values['field'] == 'Radio' ) || ( $posted_values['field'] == 'Select' ) ){
1437 if ( ( trim( $posted_values['default-option'] ) != '' ) && ( !in_array( $posted_values['default-option'], array_map( 'trim', explode( ',', $posted_values['options'] ) ) ) ) )
1438 $message .= sprintf( __( "The following option did not coincide with the ones in the options list: %s\n", 'profile-builder' ), $posted_values['default-option'] );
1439 }
1440 // END check for valid default option (checkbox, select, radio)
1441
1442 // check to see if any user role is selected (user-role field)
1443 if( $posted_values['field'] == 'Select (User Role)' ) {
1444 if( empty( $posted_values['user-roles'] ) ) {
1445 $message .= __( "Please select at least one user role\n", 'profile-builder' );
1446 }
1447 }
1448 // END check to see if Administrator user role has been selected (user-role field)
1449
1450 $message = apply_filters( 'wppb_check_extra_manage_fields', $message, $posted_values );
1451
1452 }elseif ( ( $meta_name == 'wppb_rf_fields' ) || ( $meta_name == 'wppb_epf_fields' ) ){
1453 if ( $posted_values['field'] == '' ){
1454 $message .= __( "You must select a field\n", 'profile-builder' );
1455
1456 }else{
1457 $fields_so_far = get_post_meta ( $post_id, $meta_name, true );
1458 if ( !empty($fields_so_far) ){
1459 foreach ( $fields_so_far as $key => $value ){
1460 if ( $value['id'] == $posted_values['id'] )
1461 $message .= __( "That field is already added in this form\n", 'profile-builder' );
1462 }
1463 }
1464 }
1465 }
1466 return $message;
1467 }
1468 add_filter( 'wck_extra_message', 'wppb_check_field_on_edit_add', 10, 6 );
1469
1470
1471 /**
1472 * Function that calls the wppb_hide_properties_for_already_added_fields and wppb_enable_select2 after a field-update
1473 *
1474 * @since v.2.0
1475 *
1476 * @param void
1477 *
1478 * @return string
1479 */
1480 function wppb_manage_fields_after_refresh_list( $id ){
1481 echo "<script type=\"text/javascript\">wppb_hide_properties_for_already_added_fields( '#container_wppb_manage_fields' );</script>";
1482 echo "<script type=\"text/javascript\">wppb_enable_select2( '#wppb_manage_fields' );</script>";
1483
1484 }
1485 add_action( "wck_refresh_list_wppb_manage_fields", "wppb_manage_fields_after_refresh_list" );
1486 add_action( "wck_refresh_entry_wppb_manage_fields", "wppb_manage_fields_after_refresh_list" );
1487
1488 /**
1489 * Function that calls the wppb_hide_all and wppb_enable_select2
1490 *
1491 * @since v.2.0
1492 *
1493 * @param void
1494 *
1495 * @return string
1496 */
1497 function wppb_manage_fields_after_ajax_add_field( $id ){
1498 echo "<script type=\"text/javascript\">wppb_hide_all( '#wppb_manage_fields' );</script>";
1499 echo "<script type=\"text/javascript\">wppb_enable_select2( '#wppb_manage_fields' );</script>";
1500 }
1501 add_action("wck_ajax_add_form_wppb_manage_fields", "wppb_manage_fields_after_ajax_add_field" );
1502
1503 /**
1504 * Function that modifies the table header in Manage Fields to add Field Name, Field Type, Meta Key, Required
1505 *
1506 * @since v.2.0
1507 *
1508 * @param $list, $id
1509 *
1510 * @return string
1511 */
1512 function wppb_manage_fields_header( $list_header ){
1513 return '<thead><tr><th class="wck-number">#</th><th class="wck-content">'. __( '<pre>Title</pre><pre>Type</pre><pre>Meta Name</pre><pre class="wppb-mb-head-required">Required</pre>', 'profile-builder' ) .'</th><th class="wck-edit">'. __( 'Edit', 'profile-builder' ) .'</th><th class="wck-delete">'. __( 'Delete', 'profile-builder' ) .'</th></tr></thead>';
1514 }
1515 add_action( 'wck_metabox_content_header_wppb_manage_fields', 'wppb_manage_fields_header' );
1516
1517 /**
1518 * Add contextual help to the side of manage fields for the shortcodes
1519 *
1520 * @since v.2.0
1521 *
1522 * @param $hook
1523 *
1524 * @return string
1525 */
1526 function wppb_add_content_before_manage_fields(){
1527 ?>
1528 <p class="cozmoslabs-description"><?php esc_html_e('Use these shortcodes on the pages you want the forms to be displayed:', 'profile-builder'); ?></p>
1529
1530 <ul class="cozmoslabs-shortcodes-list">
1531 <li><strong class="nowrap">[wppb-register]</strong></li>
1532 <li><strong class="nowrap">[wppb-edit-profile]</strong></li>
1533 <li><strong class="nowrap">[wppb-register role="author"]</strong></li>
1534 </ul>
1535
1536 <p class="cozmoslabs-description">
1537 <?php
1538 $versions = array( 'Profile Builder Pro', 'Profile Builder Agency', 'Profile Builder Unlimited', 'Profile Builder Dev' );
1539
1540 if( in_array( PROFILE_BUILDER, $versions ) )
1541 esc_html_e("If you're interested in displaying different fields in the registration and edit profile forms, please use the Multiple Registration & Edit Profile Forms Add-ons.", 'profile-builder');
1542 else
1543 esc_html_e( "With Profile Builder Pro you can display different fields in the registration and edit profile forms, using the Multiple Registration & Edit Profile Forms add-on.", "profile-builder" )
1544 ?>
1545 </p>
1546 <?php
1547 }
1548 add_action('wck_metabox_content_wppb_manage_fields_info', 'wppb_add_content_before_manage_fields');
1549
1550
1551 /**
1552 * Function that calls the wppb_edit_form_properties
1553 *
1554 * @since v.2.0
1555 *
1556 * @param void
1557 *
1558 * @return string
1559 */
1560 function wppb_remove_properties_from_added_form( $meta_name, $id, $element_id ){
1561 if ( ( $meta_name == 'wppb_epf_fields' ) || ( $meta_name == 'wppb_rf_fields' ) )
1562 echo "<script type=\"text/javascript\">wppb_disable_delete_on_default_mandatory_fields();</script>";
1563
1564 if ( $meta_name == 'wppb_manage_fields' ) {
1565 echo "<script type=\"text/javascript\">wppb_edit_form_properties( '#container_wppb_manage_fields', 'update_container_wppb_manage_fields_" . esc_attr( $element_id ) . "' );</script>";
1566 echo "<script type=\"text/javascript\">wppb_enable_select2( '#container_wppb_manage_fields' );</script>";
1567 }
1568 }
1569 add_action("wck_after_adding_form", "wppb_remove_properties_from_added_form", 10, 3);
1570
1571 /*
1572 * WPML Support for dynamic strings in Profile Builder. Tags: WPML, fields, translate
1573 */
1574 add_filter( 'update_option_wppb_manage_fields', 'wppb_wpml_compat_with_fields', 10, 2 );
1575 function wppb_wpml_compat_with_fields( $oldvalue, $_newvalue ){
1576 $default_fields = array(
1577 'Default - Name (Heading)',
1578 'Default - Contact Info (Heading)',
1579 'Default - About Yourself (Heading)',
1580 'Default - Username',
1581 'Default - First Name',
1582 'Default - Last Name',
1583 'Default - Nickname',
1584 'Default - E-mail',
1585 'Default - Website',
1586 'Default - AIM',
1587 'Default - Yahoo IM',
1588 'Default - Jabber / Google Talk',
1589 'Default - Password',
1590 'Default - Repeat Password',
1591 'Default - Biographical Info',
1592 'Default - Blog Details',
1593 'Default - Display name publicly as'
1594 );
1595
1596 if ( is_array( $_newvalue ) ){
1597 foreach ( $_newvalue as $field ){
1598 if ( in_array($field['field'], $default_fields) ){
1599 $prefix = 'default_field_';
1600 } else {
1601 $prefix = 'custom_field_';
1602 }
1603 if (function_exists('wppb_icl_register_string')){
1604 if( !empty( $field['field-title'] ) )
1605 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_title_translation' , $field['field-title'] );
1606 if( !empty( $field['description'] ) )
1607 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_description_translation', $field['description'] );
1608 if( !empty( $field['labels'] ) )
1609 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_labels_translation', $field['labels'] );
1610 if( !empty( $field['default-value'] ) )
1611 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_default_value_translation', $field['default-value'] );
1612 if( !empty( $field['default-content'] ) )
1613 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_default_content_translation', $field['default-content'] );
1614 if( !empty( $field['html-content'] ) )
1615 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_html_content_translation', $field['html-content'] );
1616 }
1617 }
1618 }
1619 }
1620
1621
1622 /*
1623 * Returns the HTML for a map given the field
1624 *
1625 */
1626 function wppb_get_map_output( $field, $args ) {
1627
1628 $defaults = array(
1629 'markers' => array(),
1630 'editable' => true,
1631 'show_search' => true,
1632 'extra_attr' => ''
1633 );
1634
1635 $args = wp_parse_args( $args, $defaults );
1636
1637 $return = '';
1638
1639 // Search box
1640 // The style:left=-99999px is set to hide the input from the viewport. It will be rewritten when the map gets initialised
1641 if ( $args['show_search'] ) {
1642 $return .= '<input style="left: -99999px" type="text" id="' . $field['meta-name'] . '-search-box" class="wppb-map-search-box" placeholder="' . __( 'Search Location', 'profile-builder' ) . '" />';
1643 }
1644
1645 $lng = ( ! empty( $field['map-default-lng'] ) ) ? (float) $field['map-default-lng'] : WPPB_DEFAULTS_MAP_LNG;
1646 $lat = ( ! empty( $field['map-default-lat'] ) ) ? (float) $field['map-default-lat'] : WPPB_DEFAULTS_MAP_LAT;
1647 $zoom = ( ! empty( $field['map-default-zoom'] ) ) ? (int) $field['map-default-zoom'] : WPPB_DEFAULTS_MAP_ZOOM;
1648
1649 // Get one time the settings.
1650 $settings = wppb_options_get_map_settings();
1651 $pin_info = ( ! empty( $args['user_id'] ) ) ? wppb_compute_simple_pin_content_for_user( $args['user_id'], $settings ) : '';
1652
1653 // Map container.
1654 $return .= '<div id="' . $field['meta-name'] . '" class="wppb-map-container" style="height: ' . $field['map-height'] . 'px;" data-editable="' . ( $args['editable'] ? 1 : 0 ) . '" data-default-zoom="' . $zoom . '" data-default-lat="' . $lat . '" data-default-lng="' . $lng . '" ' . $args['extra_attr'] . '></div>';
1655
1656 if ( ! empty( $args['markers'] ) ) {
1657 foreach ( $args['markers'] as $marker ) {
1658 if ( ! empty( $args['user_id'] ) ) {
1659 // Also compute the marker bubble content.
1660 $bubble = wppb_get_user_pin_bubble(
1661 $args['user_id'],
1662 strstr( $marker, ',', true ),
1663 ltrim( strstr( $marker, ',' ), ',' ),
1664 $pin_info,
1665 ''
1666 );
1667 $return .= $bubble;
1668 }
1669
1670 $return .= '<input name="' . $field['meta-name'] . '[]" type="hidden" class="wppb-map-marker" value="' . $marker . '" />';
1671 }
1672 }
1673
1674 return $return;
1675 }
1676
1677
1678 /*
1679 * Returns all the saved markers for a map field for a particular user
1680 *
1681 */
1682 function wppb_get_user_map_markers( $user_id, $meta_name ) {
1683
1684 global $wpdb;
1685
1686 $meta_name_underlined = $meta_name . '_';
1687
1688 $results = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value, meta_key FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key LIKE '%s'", $user_id, '%' . $meta_name_underlined . '%' ), ARRAY_N );
1689
1690 $markers = array();
1691 $i = 0;
1692
1693 foreach( $results as $key => $result ) {
1694 $pattern = '/^' . $meta_name . '_[0-9]+(_[0-9]+)*$/';
1695 preg_match( $pattern, $result[1], $matches );
1696 if ( count ($matches) > 0 ) {
1697 $markers[$i] = $result[0];
1698 $i++;
1699 }
1700
1701 }
1702 return $markers;
1703
1704 }
1705
1706 /*
1707 * Deletes from the database all saved markers
1708 *
1709 */
1710 function wppb_delete_user_map_markers( $user_id, $meta_name ) {
1711
1712 global $wpdb;
1713
1714 $delete = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE user_id=%d AND meta_key REGEXP %s", $user_id, $meta_name . '_[0-9]' ) );
1715
1716 wp_cache_delete( $user_id, 'user_meta' );
1717
1718 }
1719
1720
1721 if ( ! function_exists( 'wppb_options_get_map_settings' ) ) {
1722 /**
1723 * Get all the map related attributes.
1724 *
1725 * @return string
1726 */
1727 function wppb_options_get_map_settings() {
1728 $manage_fields = apply_filters(
1729 'wppb_form_fields',
1730 get_option( 'wppb_manage_fields', 'not_set' ),
1731 array( 'context' => 'map_api_key' )
1732 );
1733 foreach ( $manage_fields as $field ) {
1734 if ( ! empty( $field['map-api-key'] ) ) {
1735 // Fail-fast. This is what we need.
1736 return $field;
1737 }
1738 }
1739
1740 // Fallback.
1741 return null;
1742 }
1743 }
1744
1745 if ( ! function_exists( 'wppb_get_user_pin_bubble' ) ) {
1746 /**
1747 * Returns the map usable marker info.
1748 *
1749 * @param integer $id The user ID.
1750 * @param float $lat The latitude.
1751 * @param float $lng The longitude.
1752 * @param string $info The bubble inner info.
1753 * @param string $icon The pin custom icon.
1754 * @return string
1755 */
1756 function wppb_get_user_pin_bubble( $id, $lat, $lng, $info, $icon = '' ) {
1757 return '<div class="marker marker-for-user-' . (int) $id . ' marker-content-info" data-lat="' . esc_attr( $lat ) . '" data-lng="' . esc_attr( $lng ) . '" data-icon="' . esc_attr( $icon ) . '"><div class="marker-content">' . wp_kses_post( $info ) . '</div></div>';
1758 }
1759 }
1760
1761 if ( ! function_exists( 'wppb_compute_simple_pin_content_for_user' ) ) {
1762 /**
1763 * Compute simple pin content for user.
1764 *
1765 * @param integer $id_user User ID.
1766 * @param array $settings Settings array.
1767 * @return string
1768 */
1769 function wppb_compute_simple_pin_content_for_user( $id_user, $settings = array() ) {
1770
1771 if ( empty( $id_user ) ) {
1772 // Fail-fast.
1773 return '';
1774 }
1775 if ( empty( $settings ) ) {
1776 // Get one time the settings.
1777 $settings = wppb_options_get_map_settings();
1778 }
1779
1780 $args = ( ! empty( $settings['map-bubble-fields'] ) ) ? explode( ', ', $settings['map-bubble-fields'] ) : array();
1781 $result = '';
1782 if ( ! empty( $args ) ) {
1783 foreach ( $args as $tag ) {
1784 // Go to souce.
1785 if ( 'avatar_or_gravatar' == $tag ) {
1786 $val = apply_filters( 'mustache_variable_avatar_or_gravatar', '', $tag, array(), array(
1787 'user_id' => $id_user,
1788 ) );
1789 } else {
1790 $val = apply_filters( 'mustache_variable_default_user_field', '', $tag, array(), array(
1791 'user_id' => $id_user,
1792 ) );
1793 }
1794 if ( ! empty( $val ) ) {
1795 $result .= '<p class="marker-info-' . esc_attr( $tag ) . '">' . wp_kses_post( $val ) . '</p>';
1796 }
1797 }
1798 }
1799
1800 return $result;
1801 }
1802 }
1803
1804
1805 /**
1806 * Disable the add button again after we added a field
1807 */
1808 add_action( 'wck_ajax_add_form_wppb_manage_fields', 'wppb_redisable_the_add_button' );
1809 function wppb_redisable_the_add_button(){
1810 ?>
1811 <script>wppb_disable_add_entry_button ( '#wppb_manage_fields' );</script>
1812 <?php
1813 }
1814
1815
1816 /**
1817 * Function that updates the meta_key of a field in the usertmeta table when it was changed for a field. It is turned off by default
1818 */
1819 add_action( 'wck_before_update_meta', 'wppb_change_field_meta_key', 10, 4 );
1820 function wppb_change_field_meta_key( $meta, $id, $values, $element_id ){
1821 if( apply_filters( 'wppb_update_field_meta_key_in_db', false ) ) {
1822 if ($meta == 'wppb_manage_fields') {
1823 global $wpdb;
1824 $wppb_manage_fields = get_option('wppb_manage_fields');
1825 if (!empty($wppb_manage_fields)) {
1826
1827 $is_not_repeater = true;
1828
1829 if( !empty( $wppb_manage_fields[$element_id] ) && $wppb_manage_fields[$element_id]['field'] == 'Repeater' )
1830 $is_not_repeater = false;
1831
1832 if (!empty($values['meta-name']) && $wppb_manage_fields[$element_id]['meta-name'] != $values['meta-name'] && $is_not_repeater ) {
1833 $wpdb->update(
1834 $wpdb->usermeta,
1835 array('meta_key' => sanitize_text_field($values['meta-name'])),
1836 array('meta_key' => sanitize_text_field($wppb_manage_fields[$element_id]['meta-name']))
1837 );
1838 } else {
1839 return;
1840 }
1841 }
1842 }
1843 }
1844 }
1845
1846
1847 if ( ! function_exists( 'wppb_prepare_key_value_options' ) ) {
1848 /**
1849 * Convert an array with keys and values into a usable option for the defined fields types.
1850 *
1851 * @param arrays $array List of options.
1852 * @return array Usable options.
1853 */
1854 function wppb_prepare_key_value_options( $array = array() ) {
1855 $result = array();
1856 if ( ! empty( $array ) ) {
1857 foreach ( $array as $name => $label ) {
1858 $result[] = '%' . wppb_prepare_wck_labels( $label ) . '%' . $name;
1859 }
1860 }
1861 return $result;
1862 }
1863 }
1864
1865 if ( ! function_exists( 'wppb_filter_map_bubble_fields' ) ) {
1866 /**
1867 * Filter the map POI's bubble content.
1868 *
1869 * @param arrays $tags List of available tags.
1870 * @return array Filtered and sorted tags.
1871 */
1872 function wppb_filter_map_bubble_fields( $tags ) {
1873 // Attempt to preseve one tag example.
1874 $maybe_avatar = ( ! empty( $tags['avatar_or_gravatar'] ) ) ? $tags['avatar_or_gravatar'] : false;
1875
1876 // Remove some of the tags.
1877 unset( $tags['meta_user_name'] );
1878 unset( $tags['more_info_url'] );
1879 unset( $tags['avatar_or_gravatar'] );
1880
1881 if ( ! empty( $maybe_avatar ) ) {
1882 // Perhaps preprend this to the list.
1883 $tags = array_merge( array( 'avatar_or_gravatar' => $maybe_avatar ), $tags );
1884 }
1885
1886 return $tags;
1887 }
1888 }
1889 add_filter( 'wppb_map_bubble_fields', 'wppb_filter_map_bubble_fields' );
1890
1891
1892 /**
1893 * Get field property mapping for cleaning up stored field data
1894 *
1895 * Maps each field type to its required properties based on the JavaScript
1896 * field definitions in assets/js/jquery-manage-fields-live-change.js
1897 *
1898 * @since 3.15.3
1899 * @return array Field type to properties mapping
1900 */
1901 function wppb_get_field_property_mapping() {
1902
1903 // Properties that can be dynamically added by various add-ons to many field types
1904 $optional_addon_properties = array(
1905 // Conditional Fields add-on
1906 'conditional-logic-enabled',
1907 'conditional-logic',
1908 // WooCommerce Sync add-on
1909 'woocommerce-checkout-field',
1910 // BuddyPress add-on
1911 'bdp-default-visibility',
1912 'bdp-allow-custom-visibility',
1913 // Field Visibility add-on
1914 'visibility',
1915 'user-role-visibility',
1916 'location-visibility',
1917 // Edit Profile Approved by Admin add-on
1918 'edit-profile-approved-by-admin',
1919 // Maximum Character Length add-on
1920 'maximum-character-length',
1921 // Custom CSS Classes add-on
1922 'class-field',
1923 );
1924
1925 /**
1926 * Filter the optional addon properties that are applied to all field types.
1927 *
1928 * Add-ons can use this filter to register properties that should be preserved
1929 * across all field types (e.g., properties that can be applied to any field).
1930 *
1931 * @since 3.15.3
1932 *
1933 * @param array $optional_addon_properties Array of property slugs to preserve for all fields
1934 *
1935 * @example
1936 * add_filter( 'wppb_field_optional_properties', 'my_addon_register_optional_properties' );
1937 * function my_addon_register_optional_properties( $properties ) {
1938 * $properties[] = 'my-custom-property';
1939 * $properties[] = 'another-property';
1940 * return $properties;
1941 * }
1942 */
1943 $optional_addon_properties = apply_filters( 'wppb_field_optional_properties', $optional_addon_properties );
1944
1945 $mapping = array(
1946 // Default WordPress Fields - Headings
1947 'Default - Name (Heading)' => array(),
1948 'Default - Contact Info (Heading)' => array(),
1949 'Default - About Yourself (Heading)' => array(),
1950
1951 // Default WordPress Fields - User Data
1952 'Default - Username' => array('default-value'),
1953 'Default - First Name' => array('default-value'),
1954 'Default - Last Name' => array('default-value'),
1955 'Default - Nickname' => array('default-value'),
1956 'Default - E-mail' => array('default-value'),
1957 'Default - Website' => array('default-value'),
1958 'Default - AIM' => array('default-value'),
1959 'Default - Yahoo IM' => array('default-value'),
1960 'Default - Jabber / Google Talk' => array('default-value'),
1961 'Default - Password' => array('ask-current-password'),
1962 'Default - Repeat Password' => array(),
1963 'Default - Biographical Info' => array('row-count', 'default-content'),
1964 'Default - Display name publicly as' => array('default-value'),
1965 'Default - Blog Details' => array(),
1966
1967 // GDPR Fields
1968 'GDPR Checkbox' => array(),
1969 'GDPR Delete Button' => array(),
1970 'GDPR Communication Preferences' => array('gdpr-communication-preferences', 'gdpr-communication-preferences-sort-order'),
1971
1972 // Standard Fields
1973 'Heading' => array('heading-tag'),
1974 'Input' => array('default-value'),
1975 'Email' => array('default-value'),
1976 'Email Confirmation' => array(),
1977 'URL' => array('default-value'),
1978 'Number' => array('default-value', 'min-number-value', 'max-number-value', 'number-step-value'),
1979 'Input (Hidden)' => array('default-value'),
1980 'Language' => array('default-value'),
1981 'Textarea' => array('default-content', 'row-count'),
1982 'WYSIWYG' => array('default-content', 'row-count'),
1983 'Phone' => array('default-value', 'phone-format'),
1984
1985 // Select Fields
1986 'Select' => array('default-option', 'options', 'labels'),
1987 'Select (Multiple)' => array('default-options', 'options', 'labels'),
1988 'Select (Country)' => array('default-option-country'),
1989 'Select (Currency)' => array('show-currency-symbol', 'default-option-currency'),
1990 'Select (Timezone)' => array('default-option-timezone'),
1991 'Select (CPT)' => array('default-option', 'cpt'),
1992 'Select (Taxonomy)' => array('default-option', 'taxonomy'),
1993 'Select2' => array('default-option', 'options', 'labels'),
1994 'Select2 (Multiple)' => array('default-options', 'options', 'labels', 'select2-multiple-limit', 'select2-multiple-tags'),
1995
1996 // Checkbox and Radio Fields
1997 'Checkbox' => array('default-options', 'options', 'labels'),
1998 'Checkbox (Terms and Conditions)' => array('terms-of-agreement'),
1999 'Radio' => array('default-option', 'options', 'labels'),
2000 'Honeypot' => array(),
2001
2002 // Upload Fields
2003 'Upload' => array('simple-upload', 'allowed-upload-extensions', 'max-file-size'),
2004 'Avatar' => array('simple-upload', 'allowed-image-extensions', 'avatar-size', 'max-file-size'),
2005
2006 // Date/Time Fields
2007 'Datepicker' => array('default-value', 'date-format'),
2008 'Timepicker' => array('time-format'),
2009 'Colorpicker' => array('default-value'),
2010
2011 // Advanced Fields
2012 'Validation' => array('validation-possible-values', 'custom-error-message'),
2013 'reCAPTCHA' => array('recaptcha-type', 'public-key', 'private-key', 'score-threshold', 'captcha-pb-forms', 'captcha-wp-forms'),
2014 'Turnstile' => array('theme', 'turnstile-site-key', 'turnstile-secret-key', 'turnstile-pb-forms', 'turnstile-wp-forms'),
2015 'Select (User Role)' => array('user-roles', 'user-roles-on-edit-profile', 'user-roles-sort-order'),
2016 'Map' => array('map-api-key', 'map-default-lat', 'map-default-lng', 'map-default-zoom', 'map-height', 'map-pins-load-type', 'map-pagination-number', 'map-bubble-fields'),
2017 'Additional Map' => array('map-default-lat', 'map-default-lng', 'map-default-zoom', 'map-height'),
2018 'HTML' => array('html-content'),
2019
2020 // WooCommerce Fields (added via JS by add-on)
2021 'WooCommerce Customer Billing Address' => array('woo-billing-fields', 'woo-billing-fields-required', 'woo-billing-fields-sort-order', 'woo-billing-fields-name'),
2022 'WooCommerce Customer Shipping Address' => array('woo-shipping-fields', 'woo-shipping-fields-required', 'woo-shipping-fields-sort-order', 'woo-shipping-fields-name'),
2023
2024 // Add-on Fields (MailChimp, MailPoet, Campaign Monitor, etc. may add their own)
2025 'MailChimp Subscribe' => array('mailchimp-lists', 'mailchimp-default-checked', 'mailchimp-hide-field'),
2026 'MailPoet Subscribe' => array('mailpoet-lists', 'mailpoet-default-checked', 'mailpoet-hide-field'),
2027 'Campaign Monitor Subscribe' => array('campaign-monitor-lists', 'campaign-monitor-hide-field'),
2028 'Subscription Plans' => array('subscription-plans', 'subscription-plans-sort-order', 'subscription-plan-selected'),
2029 'PMS Billing Fields' => array('pms-billing-fields'),
2030 'Repeater' => array('rpf-enable-limit', 'rpf-limit', 'rpf-limit-reached-message', 'rpf-role-limit', 'rpf-button'),
2031 );
2032
2033 // Add optional addon properties to all field types
2034 foreach ( $mapping as $field_type => $properties ) {
2035 $mapping[$field_type] = array_merge( $properties, $optional_addon_properties );
2036 }
2037
2038 // Allow add-ons to register their field type property mappings
2039 $mapping = apply_filters( 'wppb_field_property_mapping', $mapping );
2040
2041 return $mapping;
2042 }
2043
2044 /**
2045 * Clean up field properties before saving to database
2046 *
2047 * Removes unused properties from each field based on its type, reducing database bloat.
2048 * Common properties are kept for all fields, field-specific properties are kept only
2049 * when relevant to the field type.
2050 *
2051 * @since 3.15.3
2052 * @param array $value New field data being saved
2053 * @param array $old_value Existing field data (not used)
2054 * @return array Cleaned field data
2055 */
2056 function wppb_cleanup_manage_fields_before_save( $value, $old_value ) {
2057 // Only process if we have an array
2058 if ( ! is_array( $value ) ) {
2059 return $value;
2060 }
2061
2062 // Get field type to property mapping
2063 $mapping = wppb_get_field_property_mapping();
2064
2065 // Common properties kept for all fields
2066 // Note: meta-name is kept even when not shown in UI, as it's set programmatically
2067 $common_properties = array(
2068 'id',
2069 'field',
2070 'field-title',
2071 'meta-name',
2072 'description',
2073 'required',
2074 'overwrite-existing',
2075 );
2076
2077 // Process each field
2078 foreach ( $value as $key => $field ) {
2079 if ( ! isset( $field['field'] ) ) {
2080 continue;
2081 }
2082
2083 $field_type = $field['field'];
2084 $allowed_properties = $common_properties;
2085
2086 // Add field-specific properties if we have a mapping
2087 if ( isset( $mapping[$field_type] ) ) {
2088 $allowed_properties = array_merge( $allowed_properties, $mapping[$field_type] );
2089 } else {
2090 // Unknown field type: keep common properties + any non-empty properties
2091 foreach ( $field as $prop_key => $prop_value ) {
2092 if ( ! in_array( $prop_key, $common_properties ) && ! empty( $prop_value ) ) {
2093 $allowed_properties[] = $prop_key;
2094 }
2095 }
2096 }
2097
2098 // Filter the field to only keep allowed properties
2099 $value[$key] = array_intersect_key( $field, array_flip( $allowed_properties ) );
2100 }
2101
2102 return $value;
2103 }
2104 add_filter( 'pre_update_option_wppb_manage_fields', 'wppb_cleanup_manage_fields_before_save', 5, 2 );
2105