PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.8.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.8.3
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 3.8.3, at admin/manage-fields.php

1,798 lines 97.7 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'][] = 'Avatar';
111
112 $manage_field_types['optgroups']['advanced']['options'][] = 'Phone';
113 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (Country)';
114 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (Timezone)';
115 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (Currency)';
116 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (CPT)';
117 $manage_field_types['optgroups']['advanced']['options'][] = 'Checkbox (Terms and Conditions)';
118 $manage_field_types['optgroups']['advanced']['options'][] = 'Datepicker';
119 $manage_field_types['optgroups']['advanced']['options'][] = 'Timepicker';
120 $manage_field_types['optgroups']['advanced']['options'][] = 'Colorpicker';
121 $manage_field_types['optgroups']['advanced']['options'][] = 'Validation';
122 $manage_field_types['optgroups']['advanced']['options'][] = 'Map';
123
124 $manage_field_types['optgroups']['other']['options'][] = 'Email';
125 $manage_field_types['optgroups']['other']['options'][] = 'URL';
126
127 // $manage_field_types['optgroups']['other']['options'][] = 'Select2';
128 $manage_field_types['optgroups']['other']['options'][] = 'Select2 (Multiple)';
129
130 $manage_field_types['optgroups']['other']['options'][] = 'Honeypot';
131
132 }
133
134 $manage_field_types['optgroups']['other']['options'][] = 'Email Confirmation';
135
136 /* added recaptcha and user role field since version 2.6.2 */
137 $manage_field_types['optgroups']['advanced']['options'][] = 'reCAPTCHA';
138 $manage_field_types['optgroups']['advanced']['options'][] = 'Select (User Role)';
139
140
141 $manage_field_types['optgroups']['other']['options'] = apply_filters( 'wppb_manage_fields_types', $manage_field_types['optgroups']['other']['options'] );
142
143 $manage_field_types = apply_filters( 'wppb_all_manage_fields_types', $manage_field_types );
144
145 if( PROFILE_BUILDER == 'Profile Builder Free' ) {
146
147 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'Number', 'disabled' => true );
148 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'Input (Hidden)', 'disabled' => true );
149 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'Language', 'disabled' => true );
150 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'WYSIWYG', 'disabled' => true );
151 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'Select (Multiple)', 'disabled' => true );
152 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'HTML', 'disabled' => true );
153 $manage_field_types['optgroups']['standard']['options'][] = array( 'field_name' => 'Upload', 'disabled' => true );
154
155 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Phone', 'disabled' => true );
156 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Select (Country)', 'disabled' => true );
157 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Select (Timezone)', 'disabled' => true );
158 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Select (Currency)', 'disabled' => true );
159 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Select (CPT)', 'disabled' => true );
160 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Checkbox (Terms and Conditions)', 'disabled' => true );
161 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Datepicker', 'disabled' => true );
162 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Timepicker', 'disabled' => true );
163 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Colorpicker', 'disabled' => true );
164 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Validation', 'disabled' => true );
165 $manage_field_types['optgroups']['advanced']['options'][] = array( 'field_name' => 'Map', 'disabled' => true );
166
167 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'WooCommerce Customer Billing Address', 'disabled' => true );
168 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'WooCommerce Customer Shipping Address', 'disabled' => true );
169 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'MailChimp Subscribe', 'disabled' => true );
170 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'Email', 'disabled' => true );
171 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'URL', 'disabled' => true );
172 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'Select2 (Multiple)', 'disabled' => true );
173 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'Honeypot', 'disabled' => true );
174
175 }
176
177 if( !is_plugin_active( 'paid-member-subscriptions/index.php' ) )
178 $manage_field_types['optgroups']['other']['options'][] = array( 'field_name' => 'Subscription Plans', 'disabled' => true );
179
180 // Free to Pro call to action on Manage Fields page
181 $field_description = __('Choose one of the supported field types','profile-builder');
182 if( PROFILE_BUILDER == 'Profile Builder Free' ) {
183 $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=wpbackend&utm_medium=clientsite&utm_content=manage-fields-link&utm_campaign=PBFree' ) );
184 }
185
186 //user roles
187 global $wp_roles;
188
189 // @TODO - The block below could use refactoring, see new function wppb_prepare_key_value_options.
190 $user_roles = array();
191 foreach( $wp_roles->roles as $user_role_slug => $user_role )
192 if( $user_role_slug !== 'administrator' )
193 array_push( $user_roles, '%' . wppb_prepare_wck_labels( $user_role['name'] ) . '%' . $user_role_slug );
194
195
196 // @TODO - The block below could use refactoring, see new function wppb_prepare_key_value_options.
197 // country select
198 $default_country_array = wppb_country_select_options( 'back_end' );
199 foreach( $default_country_array as $iso_country_code => $country_name ) {
200 $default_country_options[] = '%'. wppb_prepare_wck_labels( $country_name ) .'%'.$iso_country_code;
201 }
202
203 // @TODO - The block below could use refactoring, see new function wppb_prepare_key_value_options.
204 // currency select
205 $default_currency_array = wppb_get_currencies( 'back_end' );
206 array_unshift( $default_currency_array, '' );
207 foreach( $default_currency_array as $iso_currency_code => $currency_name ) {
208 $default_currency_options[] = '%'. wppb_prepare_wck_labels( $currency_name ) .'%'.$iso_currency_code;
209 }
210
211 //cpt select
212 $post_types = get_post_types( array( 'public' => true ), 'names' );
213
214
215 if( apply_filters( 'wppb_update_field_meta_key_in_db', false ) ) {
216 $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' );
217 }
218 else{
219 $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' );
220 }
221
222 // Initiate the list of available tags for the pin bubble.
223 if( function_exists( 'wppb_generate_userlisting_merge_tags' ) ) {
224 $bubble_meta_tags = wppb_generate_userlisting_merge_tags('meta');
225 $bubble_meta_tags = wp_list_pluck($bubble_meta_tags, 'label', 'name');
226 }
227 else
228 $bubble_meta_tags = array();
229
230 // set up the fields array
231 $fields = apply_filters( 'wppb_manage_fields', array(
232
233 array( 'type' => 'text', 'slug' => 'field-title', 'title' => __( 'Field Title', 'profile-builder' ), 'description' => __( 'Title of the field', 'profile-builder' ) ),
234 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 ),
235 array( 'type' => 'text', 'slug' => 'meta-name', 'title' => __( 'Meta-name', 'profile-builder' ), 'default' => wppb_get_meta_name(), 'description' => $meta_key_description ),
236 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 ),
237 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') ),
238 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' ) ),
239 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' ) ),
240 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' ) ),
241 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' ) ),
242 array( 'type' => 'text', 'slug' => 'avatar-size', 'title' => __( 'Avatar Size', 'profile-builder' ), 'default' => 100, 'description' => __( "Enter a value (between 20 and 200) for the size of the 'Avatar'<br/>If not specified, defaults to 100", 'profile-builder' ) ),
243 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' ) ),
244 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' ) ),
245 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' ) ),
246 array( 'type' => 'text', 'slug' => 'labels', 'title' => __( 'Labels', 'profile-builder' ), 'description' => __( "Enter a comma separated list of labels<br/>Visible for the user", 'profile-builder' ) ),
247 array( 'type' => 'select', 'slug' => 'recaptcha-type', 'title' => __( 'reCAPTCHA Type', 'profile-builder' ), 'options' => array('%reCAPTCHA V2%v2', '%Invisible reCAPTCHA%invisible'), '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' ) ),
248 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' ) ),
249 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' ) ),
250 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' ) ),
251 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' => 'default_wp_register', 'description' => __( "Select on which default WP forms to display reCAPTCHA", 'profile-builder' ) ),
252 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' ) ),
253 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' ) ),
254 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' ) ),
255 array( 'type' => 'text', 'slug' => 'default-value', 'title' => __( 'Default Value', 'profile-builder' ), 'description' => __( "Default value of the field", 'profile-builder' ) ),
256 array( 'type' => 'text', 'slug' => 'default-option', 'title' => __( 'Default Option', 'profile-builder' ), 'description' => __( "Specify the option which should be selected by default", 'profile-builder' ) ),
257 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' ) ),
258 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' ) ),
259 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' ) ),
260 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' ) ),
261 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' ) ),
262 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' ) ),
263 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' ) ),
264 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' ) ),
265 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' ) ),
266 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' ) ),
267
268 array(
269 'type' => 'text',
270 'slug' => 'map-default-lat',
271 'title' => __( 'Default Latitude', 'profile-builder' ),
272 'description' => __( 'The latitude at which the map should be displayed when no pins are attached.', 'profile-builder' ),
273 'default' => WPPB_DEFAULTS_MAP_LAT,
274 ),
275 array(
276 'type' => 'text',
277 'slug' => 'map-default-lng',
278 'title' => __( 'Default Longitude', 'profile-builder' ),
279 'description' => __( 'The longitude at which the map should be displayed when no pins are attached.', 'profile-builder' ),
280 'default' => WPPB_DEFAULTS_MAP_LNG,
281 ),
282 array(
283 'type' => 'text',
284 'slug' => 'map-default-zoom',
285 'title' => __( 'Default Zoom Level', 'profile-builder' ),
286 'description' => __( 'Add a number from 0 to 19. The higher the number the higher the zoom.', 'profile-builder' ),
287 'default' => WPPB_DEFAULTS_MAP_ZOOM,
288 ),
289
290 array( 'type' => 'text', 'slug' => 'map-height', 'title' => __( 'Map Height', 'profile-builder' ), 'description' => __( "The height of the map.", 'profile-builder' ), 'default' => 400 ),
291 array( 'type' => 'textarea', 'slug' => 'default-content', 'title' => __( 'Default Content', 'profile-builder' ), 'description' => __( "Default value of the textarea", 'profile-builder' ) ),
292 array( 'type' => 'textarea', 'slug' => 'html-content', 'title' => __( 'HTML Content', 'profile-builder' ), 'description' => __( "Add your HTML (or text) content", 'profile-builder' ) ),
293 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' ) ),
294 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' ) ),
295 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' ) ),
296 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' ) ),
297 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' ) ),
298 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' ) ),
299 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' ) ),
300
301 // Added the new option for the map field type, that allows to customize the POIs load type.
302 array(
303 'type' => 'select',
304 'slug' => 'map-pins-load-type',
305 'title' => __( 'POIs Load Type', 'profile-builder' ),
306 'options' => array(
307 '%' . __( 'POIs of the listed users (as filtered & paginated)', 'profile-builder' ) . '%',
308 '%' . __( 'POIs of all the users for the filter* (no pagination)', 'profile-builder' ) . '%all',
309 ),
310 'default' => '',
311 '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' ),
312 ),
313
314 // Added the new option for the map field type, that allows to customize the POI bubble content.
315 array(
316 'type' => 'checkbox',
317 'slug' => 'map-bubble-fields',
318 'title' => __( 'POI Bubble Info', 'profile-builder' ),
319 'options' => wppb_prepare_key_value_options( apply_filters( 'wppb_map_bubble_fields', $bubble_meta_tags ) ),
320 'default' => 'avatar_or_gravatar, meta_display_name',
321 'description' => __( 'Select the attributes to be listed inside the POI bubble.', 'profile-builder' ),
322 'extra_attributes' => array(
323 'dropdown_options' => true,
324 'sortable_options' => true,
325 ),
326 ),
327
328 // Added the new option for the map field type, that allows to customize the number of users per iteration.
329 array(
330 'type' => 'text',
331 'slug' => 'map-pagination-number',
332 'title' => __( 'Number of Users per Map Iteration', 'profile-builder' ),
333 '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' ),
334 'default' => 50,
335 ),
336
337 //add Select 2 attributes
338 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' ) ),
339 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' ) ),
340
341 ) );
342
343 // create the new submenu with the above options
344 $args = array(
345 'metabox_id' => 'manage-fields',
346 'metabox_title' => __( 'Form Field Properties', 'profile-builder' ),
347 'post_type' => 'manage-fields',
348 'meta_name' => 'wppb_manage_fields',
349 'meta_array' => $fields,
350 'context' => 'option'
351 );
352 new Wordpress_Creation_Kit_PB( $args );
353
354 /* this is redundant but it should have a very low impact and for comfort we leave it here as well */
355 wppb_prepopulate_fields();
356
357 // create the info side meta-box
358 $args = array(
359 'metabox_id' => 'manage-fields-info',
360 'metabox_title' => __( 'Registration & Edit Profile Forms', 'profile-builder' ),
361 'post_type' => 'manage-fields',
362 'meta_name' => 'wppb_manage_fields_info',
363 'meta_array' => '',
364 'context' => 'option',
365 'mb_context' => 'side'
366 );
367 new Wordpress_Creation_Kit_PB( $args );
368 }
369 add_action( 'admin_init', 'wppb_populate_manage_fields', 1 );
370
371 /**
372 * Function that prepopulates the manage fields list with the default fields of WP
373 *
374 * @since v.2.0
375 *
376 * @return void
377 */
378 function wppb_prepopulate_fields(){
379 $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' );
380 $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' );
381 $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' );
382 $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' );
383 $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' );
384 $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' );
385 $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' );
386 $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' );
387 $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' );
388
389 // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
390 if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){
391 $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' );
392 $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' );
393 $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' );
394 }
395
396 $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' );
397 $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' );
398 $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' );
399 $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' );
400 if ( wppb_can_users_signup_blog() ){
401 $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' );
402 }
403
404 add_option ( 'wppb_manage_fields', apply_filters ( 'wppb_prepopulated_fields', $prepopulated_fields ) );
405 }
406
407 /**
408 * Function that returns a unique meta-name
409 *
410 * @since v.2.0
411 *
412 * @return string
413 */
414 function wppb_get_meta_name( $option = 'wppb_manage_fields', $prefix = 'custom_field_' ){
415 $id = 1;
416
417 $wppb_manage_fields = get_option( $option, 'not_found' );
418
419 if ( ( $wppb_manage_fields === 'not_found' ) || ( empty( $wppb_manage_fields ) ) ){
420 return $prefix . $id;
421 }
422 else{
423 $meta_names = array();
424 foreach( $wppb_manage_fields as $value ){
425 if ( strpos( $value['meta-name'], $prefix ) === 0 ){
426 $meta_names[] = $value['meta-name'];
427 }
428 }
429
430 if( !empty( $meta_names ) ){
431 $meta_numbers = array();
432 foreach( $meta_names as $meta_name ){
433 $number = str_replace( $prefix, '', $meta_name );
434 /* we should have an underscore present in custom_field_# so remove it */
435 $number = str_replace( '_', '', $number );
436
437 $meta_numbers[] = $number;
438 }
439 if( !empty( $meta_numbers ) ){
440 rsort( $meta_numbers );
441 $id = (int)$meta_numbers[0] + 1;
442 }
443 }
444
445 return $prefix . $id;
446 }
447 }
448
449
450 /**
451 * Function that returns an array with countries
452 *
453 * @since v.2.0
454 *
455 * @return array
456 */
457 function wppb_country_select_options( $form_location ) {
458 $country_array = apply_filters( 'wppb_'.$form_location.'_country_select_array',
459 array(
460 '' => __( 'Select a Country', 'profile-builder' ),
461 'AF' => __( 'Afghanistan', 'profile-builder' ),
462 'AX' => __( 'Aland Islands', 'profile-builder' ),
463 'AL' => __( 'Albania', 'profile-builder' ),
464 'DZ' => __( 'Algeria', 'profile-builder' ),
465 'AS' => __( 'American Samoa', 'profile-builder' ),
466 'AD' => __( 'Andorra', 'profile-builder' ),
467 'AO' => __( 'Angola', 'profile-builder' ),
468 'AI' => __( 'Anguilla', 'profile-builder' ),
469 'AQ' => __( 'Antarctica', 'profile-builder' ),
470 'AG' => __( 'Antigua and Barbuda', 'profile-builder' ),
471 'AR' => __( 'Argentina', 'profile-builder' ),
472 'AM' => __( 'Armenia', 'profile-builder' ),
473 'AW' => __( 'Aruba', 'profile-builder' ),
474 'AU' => __( 'Australia', 'profile-builder' ),
475 'AT' => __( 'Austria', 'profile-builder' ),
476 'AZ' => __( 'Azerbaijan', 'profile-builder' ),
477 'BS' => __( 'Bahamas', 'profile-builder' ),
478 'BH' => __( 'Bahrain', 'profile-builder' ),
479 'BD' => __( 'Bangladesh', 'profile-builder' ),
480 'BB' => __( 'Barbados', 'profile-builder' ),
481 'BY' => __( 'Belarus', 'profile-builder' ),
482 'BE' => __( 'Belgium', 'profile-builder' ),
483 'BZ' => __( 'Belize', 'profile-builder' ),
484 'BJ' => __( 'Benin', 'profile-builder' ),
485 'BM' => __( 'Bermuda', 'profile-builder' ),
486 'BT' => __( 'Bhutan', 'profile-builder' ),
487 'BO' => __( 'Bolivia', 'profile-builder' ),
488 'BQ' => __( 'Bonaire, Saint Eustatius and Saba', 'profile-builder' ),
489 'BA' => __( 'Bosnia and Herzegovina', 'profile-builder' ),
490 'BW' => __( 'Botswana', 'profile-builder' ),
491 'BV' => __( 'Bouvet Island', 'profile-builder' ),
492 'BR' => __( 'Brazil', 'profile-builder' ),
493 'IO' => __( 'British Indian Ocean Territory', 'profile-builder' ),
494 'VG' => __( 'British Virgin Islands', 'profile-builder' ),
495 'BN' => __( 'Brunei', 'profile-builder' ),
496 'BG' => __( 'Bulgaria', 'profile-builder' ),
497 'BF' => __( 'Burkina Faso', 'profile-builder' ),
498 'BI' => __( 'Burundi', 'profile-builder' ),
499 'KH' => __( 'Cambodia', 'profile-builder' ),
500 'CM' => __( 'Cameroon', 'profile-builder' ),
501 'CA' => __( 'Canada', 'profile-builder' ),
502 'CV' => __( 'Cape Verde', 'profile-builder' ),
503 'KY' => __( 'Cayman Islands', 'profile-builder' ),
504 'CF' => __( 'Central African Republic', 'profile-builder' ),
505 'TD' => __( 'Chad', 'profile-builder' ),
506 'CL' => __( 'Chile', 'profile-builder' ),
507 'CN' => __( 'China', 'profile-builder' ),
508 'CX' => __( 'Christmas Island', 'profile-builder' ),
509 'CC' => __( 'Cocos Islands', 'profile-builder' ),
510 'CO' => __( 'Colombia', 'profile-builder' ),
511 'KM' => __( 'Comoros', 'profile-builder' ),
512 'CK' => __( 'Cook Islands', 'profile-builder' ),
513 'CR' => __( 'Costa Rica', 'profile-builder' ),
514 'HR' => __( 'Croatia', 'profile-builder' ),
515 'CU' => __( 'Cuba', 'profile-builder' ),
516 'CW' => __( 'Curacao', 'profile-builder' ),
517 'CY' => __( 'Cyprus', 'profile-builder' ),
518 'CZ' => __( 'Czech Republic', 'profile-builder' ),
519 'CD' => __( 'Democratic Republic of the Congo', 'profile-builder' ),
520 'DK' => __( 'Denmark', 'profile-builder' ),
521 'DJ' => __( 'Djibouti', 'profile-builder' ),
522 'DM' => __( 'Dominica', 'profile-builder' ),
523 'DO' => __( 'Dominican Republic', 'profile-builder' ),
524 'TL' => __( 'East Timor', 'profile-builder' ),
525 'EC' => __( 'Ecuador', 'profile-builder' ),
526 'EG' => __( 'Egypt', 'profile-builder' ),
527 'SV' => __( 'El Salvador', 'profile-builder' ),
528 'GQ' => __( 'Equatorial Guinea', 'profile-builder' ),
529 'ER' => __( 'Eritrea', 'profile-builder' ),
530 'EE' => __( 'Estonia', 'profile-builder' ),
531 'ET' => __( 'Ethiopia', 'profile-builder' ),
532 'FK' => __( 'Falkland Islands', 'profile-builder' ),
533 'FO' => __( 'Faroe Islands', 'profile-builder' ),
534 'FJ' => __( 'Fiji', 'profile-builder' ),
535 'FI' => __( 'Finland', 'profile-builder' ),
536 'FR' => __( 'France', 'profile-builder' ),
537 'GF' => __( 'French Guiana', 'profile-builder' ),
538 'PF' => __( 'French Polynesia', 'profile-builder' ),
539 'TF' => __( 'French Southern Territories', 'profile-builder' ),
540 'GA' => __( 'Gabon', 'profile-builder' ),
541 'GM' => __( 'Gambia', 'profile-builder' ),
542 'GE' => __( 'Georgia', 'profile-builder' ),
543 'DE' => __( 'Germany', 'profile-builder' ),
544 'GH' => __( 'Ghana', 'profile-builder' ),
545 'GI' => __( 'Gibraltar', 'profile-builder' ),
546 'GR' => __( 'Greece', 'profile-builder' ),
547 'GL' => __( 'Greenland', 'profile-builder' ),
548 'GD' => __( 'Grenada', 'profile-builder' ),
549 'GP' => __( 'Guadeloupe', 'profile-builder' ),
550 'GU' => __( 'Guam', 'profile-builder' ),
551 'GT' => __( 'Guatemala', 'profile-builder' ),
552 'GG' => __( 'Guernsey', 'profile-builder' ),
553 'GN' => __( 'Guinea', 'profile-builder' ),
554 'GW' => __( 'Guinea-Bissau', 'profile-builder' ),
555 'GY' => __( 'Guyana', 'profile-builder' ),
556 'HT' => __( 'Haiti', 'profile-builder' ),
557 'HM' => __( 'Heard Island and McDonald Islands', 'profile-builder' ),
558 'HN' => __( 'Honduras', 'profile-builder' ),
559 'HK' => __( 'Hong Kong', 'profile-builder' ),
560 'HU' => __( 'Hungary', 'profile-builder' ),
561 'IS' => __( 'Iceland', 'profile-builder' ),
562 'IN' => __( 'India', 'profile-builder' ),
563 'ID' => __( 'Indonesia', 'profile-builder' ),
564 'IR' => __( 'Iran', 'profile-builder' ),
565 'IQ' => __( 'Iraq', 'profile-builder' ),
566 'IE' => __( 'Ireland', 'profile-builder' ),
567 'IM' => __( 'Isle of Man', 'profile-builder' ),
568 'IL' => __( 'Israel', 'profile-builder' ),
569 'IT' => __( 'Italy', 'profile-builder' ),
570 'CI' => __( 'Ivory Coast', 'profile-builder' ),
571 'JM' => __( 'Jamaica', 'profile-builder' ),
572 'JP' => __( 'Japan', 'profile-builder' ),
573 'JE' => __( 'Jersey', 'profile-builder' ),
574 'JO' => __( 'Jordan', 'profile-builder' ),
575 'KZ' => __( 'Kazakhstan', 'profile-builder' ),
576 'KE' => __( 'Kenya', 'profile-builder' ),
577 'KI' => __( 'Kiribati', 'profile-builder' ),
578 'XK' => __( 'Kosovo', 'profile-builder' ),
579 'KW' => __( 'Kuwait', 'profile-builder' ),
580 'KG' => __( 'Kyrgyzstan', 'profile-builder' ),
581 'LA' => __( 'Laos', 'profile-builder' ),
582 'LV' => __( 'Latvia', 'profile-builder' ),
583 'LB' => __( 'Lebanon', 'profile-builder' ),
584 'LS' => __( 'Lesotho', 'profile-builder' ),
585 'LR' => __( 'Liberia', 'profile-builder' ),
586 'LY' => __( 'Libya', 'profile-builder' ),
587 'LI' => __( 'Liechtenstein', 'profile-builder' ),
588 'LT' => __( 'Lithuania', 'profile-builder' ),
589 'LU' => __( 'Luxembourg', 'profile-builder' ),
590 'MO' => __( 'Macao', 'profile-builder' ),
591 'MK' => __( 'Macedonia', 'profile-builder' ),
592 'MG' => __( 'Madagascar', 'profile-builder' ),
593 'MW' => __( 'Malawi', 'profile-builder' ),
594 'MY' => __( 'Malaysia', 'profile-builder' ),
595 'MV' => __( 'Maldives', 'profile-builder' ),
596 'ML' => __( 'Mali', 'profile-builder' ),
597 'MT' => __( 'Malta', 'profile-builder' ),
598 'MH' => __( 'Marshall Islands', 'profile-builder' ),
599 'MQ' => __( 'Martinique', 'profile-builder' ),
600 'MR' => __( 'Mauritania', 'profile-builder' ),
601 'MU' => __( 'Mauritius', 'profile-builder' ),
602 'YT' => __( 'Mayotte', 'profile-builder' ),
603 'MX' => __( 'Mexico', 'profile-builder' ),
604 'FM' => __( 'Micronesia', 'profile-builder' ),
605 'MD' => __( 'Moldova', 'profile-builder' ),
606 'MC' => __( 'Monaco', 'profile-builder' ),
607 'MN' => __( 'Mongolia', 'profile-builder' ),
608 'ME' => __( 'Montenegro', 'profile-builder' ),
609 'MS' => __( 'Montserrat', 'profile-builder' ),
610 'MA' => __( 'Morocco', 'profile-builder' ),
611 'MZ' => __( 'Mozambique', 'profile-builder' ),
612 'MM' => __( 'Myanmar', 'profile-builder' ),
613 'NA' => __( 'Namibia', 'profile-builder' ),
614 'NR' => __( 'Nauru', 'profile-builder' ),
615 'NP' => __( 'Nepal', 'profile-builder' ),
616 'NL' => __( 'Netherlands', 'profile-builder' ),
617 'NC' => __( 'New Caledonia', 'profile-builder' ),
618 'NZ' => __( 'New Zealand', 'profile-builder' ),
619 'NI' => __( 'Nicaragua', 'profile-builder' ),
620 'NE' => __( 'Niger', 'profile-builder' ),
621 'NG' => __( 'Nigeria', 'profile-builder' ),
622 'NU' => __( 'Niue', 'profile-builder' ),
623 'NF' => __( 'Norfolk Island', 'profile-builder' ),
624 'KP' => __( 'North Korea', 'profile-builder' ),
625 'MP' => __( 'Northern Mariana Islands', 'profile-builder' ),
626 'NO' => __( 'Norway', 'profile-builder' ),
627 'OM' => __( 'Oman', 'profile-builder' ),
628 'PK' => __( 'Pakistan', 'profile-builder' ),
629 'PW' => __( 'Palau', 'profile-builder' ),
630 'PS' => __( 'Palestinian Territory', 'profile-builder' ),
631 'PA' => __( 'Panama', 'profile-builder' ),
632 'PG' => __( 'Papua New Guinea', 'profile-builder' ),
633 'PY' => __( 'Paraguay', 'profile-builder' ),
634 'PE' => __( 'Peru', 'profile-builder' ),
635 'PH' => __( 'Philippines', 'profile-builder' ),
636 'PN' => __( 'Pitcairn', 'profile-builder' ),
637 'PL' => __( 'Poland', 'profile-builder' ),
638 'PT' => __( 'Portugal', 'profile-builder' ),
639 'PR' => __( 'Puerto Rico', 'profile-builder' ),
640 'QA' => __( 'Qatar', 'profile-builder' ),
641 'CG' => __( 'Republic of the Congo', 'profile-builder' ),
642 'RE' => __( 'Reunion', 'profile-builder' ),
643 'RO' => __( 'Romania', 'profile-builder' ),
644 'RU' => __( 'Russia', 'profile-builder' ),
645 'RW' => __( 'Rwanda', 'profile-builder' ),
646 'BL' => __( 'Saint Barthelemy', 'profile-builder' ),
647 'SH' => __( 'Saint Helena', 'profile-builder' ),
648 'KN' => __( 'Saint Kitts and Nevis', 'profile-builder' ),
649 'LC' => __( 'Saint Lucia', 'profile-builder' ),
650 'MF' => __( 'Saint Martin', 'profile-builder' ),
651 'PM' => __( 'Saint Pierre and Miquelon', 'profile-builder' ),
652 'VC' => __( 'Saint Vincent and the Grenadines', 'profile-builder' ),
653 'WS' => __( 'Samoa', 'profile-builder' ),
654 'SM' => __( 'San Marino', 'profile-builder' ),
655 'ST' => __( 'Sao Tome and Principe', 'profile-builder' ),
656 'SA' => __( 'Saudi Arabia', 'profile-builder' ),
657 'SN' => __( 'Senegal', 'profile-builder' ),
658 'RS' => __( 'Serbia', 'profile-builder' ),
659 'SC' => __( 'Seychelles', 'profile-builder' ),
660 'SL' => __( 'Sierra Leone', 'profile-builder' ),
661 'SG' => __( 'Singapore', 'profile-builder' ),
662 'SX' => __( 'Sint Maarten', 'profile-builder' ),
663 'SK' => __( 'Slovakia', 'profile-builder' ),
664 'SI' => __( 'Slovenia', 'profile-builder' ),
665 'SB' => __( 'Solomon Islands', 'profile-builder' ),
666 'SO' => __( 'Somalia', 'profile-builder' ),
667 'ZA' => __( 'South Africa', 'profile-builder' ),
668 'GS' => __( 'South Georgia and the South Sandwich Islands', 'profile-builder' ),
669 'KR' => __( 'South Korea', 'profile-builder' ),
670 'SS' => __( 'South Sudan', 'profile-builder' ),
671 'ES' => __( 'Spain', 'profile-builder' ),
672 'LK' => __( 'Sri Lanka', 'profile-builder' ),
673 'SD' => __( 'Sudan', 'profile-builder' ),
674 'SR' => __( 'Suriname', 'profile-builder' ),
675 'SJ' => __( 'Svalbard and Jan Mayen', 'profile-builder' ),
676 'SZ' => __( 'Swaziland', 'profile-builder' ),
677 'SE' => __( 'Sweden', 'profile-builder' ),
678 'CH' => __( 'Switzerland', 'profile-builder' ),
679 'SY' => __( 'Syria', 'profile-builder' ),
680 'TW' => __( 'Taiwan', 'profile-builder' ),
681 'TJ' => __( 'Tajikistan', 'profile-builder' ),
682 'TZ' => __( 'Tanzania', 'profile-builder' ),
683 'TH' => __( 'Thailand', 'profile-builder' ),
684 'TG' => __( 'Togo', 'profile-builder' ),
685 'TK' => __( 'Tokelau', 'profile-builder' ),
686 'TO' => __( 'Tonga', 'profile-builder' ),
687 'TT' => __( 'Trinidad and Tobago', 'profile-builder' ),
688 'TN' => __( 'Tunisia', 'profile-builder' ),
689 'TR' => __( 'Turkey', 'profile-builder' ),
690 'TM' => __( 'Turkmenistan', 'profile-builder' ),
691 'TC' => __( 'Turks and Caicos Islands', 'profile-builder' ),
692 'TV' => __( 'Tuvalu', 'profile-builder' ),
693 'VI' => __( 'U.S. Virgin Islands', 'profile-builder' ),
694 'UG' => __( 'Uganda', 'profile-builder' ),
695 'UA' => __( 'Ukraine', 'profile-builder' ),
696 'AE' => __( 'United Arab Emirates', 'profile-builder' ),
697 'GB' => __( 'United Kingdom', 'profile-builder' ),
698 'US' => __( 'United States', 'profile-builder' ),
699 'UM' => __( 'United States Minor Outlying Islands', 'profile-builder' ),
700 'UY' => __( 'Uruguay', 'profile-builder' ),
701 'UZ' => __( 'Uzbekistan', 'profile-builder' ),
702 'VU' => __( 'Vanuatu', 'profile-builder' ),
703 'VA' => __( 'Vatican', 'profile-builder' ),
704 'VE' => __( 'Venezuela', 'profile-builder' ),
705 'VN' => __( 'Vietnam', 'profile-builder' ),
706 'WF' => __( 'Wallis and Futuna', 'profile-builder' ),
707 'EH' => __( 'Western Sahara', 'profile-builder' ),
708 'YE' => __( 'Yemen', 'profile-builder' ),
709 'ZM' => __( 'Zambia', 'profile-builder' ),
710 'ZW' => __( 'Zimbabwe', 'profile-builder' ),
711 )
712 );
713
714 return $country_array;
715 }
716
717
718 /**
719 * Function that returns an array with timezone options
720 *
721 * @since v.2.0
722 *
723 * @return array
724 */
725 function wppb_timezone_select_options( $form_location ) {
726 $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' ) );
727
728 return $timezone_array;
729 }
730
731
732 /*
733 * Array with the currency ISO code and associated currency name
734 *
735 * @param string $form_location
736 *
737 * @return array
738 *
739 */
740 function wppb_get_currencies( $form_location = '' ) {
741
742 $currencies = array(
743 'ALL' => __( 'Albania Lek', 'profile-builder' ),
744 'AFN' => __( 'Afghanistan Afghani', 'profile-builder' ),
745 'ARS' => __( 'Argentina Peso', 'profile-builder' ),
746 'AWG' => __( 'Aruba Guilder', 'profile-builder' ),
747 'AUD' => __( 'Australia Dollar', 'profile-builder' ),
748 'AZN' => __( 'Azerbaijan New Manat', 'profile-builder' ),
749 'BSD' => __( 'Bahamas Dollar', 'profile-builder' ),
750 'BBD' => __( 'Barbados Dollar','profile-builder' ),
751 'BDT' => __( 'Bangladeshi taka','profile-builder' ),
752 'BYR' => __( 'Belarus Ruble','profile-builder' ),
753 'BZD' => __( 'Belize Dollar','profile-builder' ),
754 'BMD' => __( 'Bermuda Dollar','profile-builder' ),
755 'BOB' => __( 'Bolivia Boliviano','profile-builder' ),
756 'BAM' => __( 'Bosnia and Herzegovina Convertible Marka','profile-builder' ),
757 'BWP' => __( 'Botswana Pula','profile-builder' ),
758 'BGN' => __( 'Bulgaria Lev','profile-builder' ),
759 'BRL' => __( 'Brazil Real','profile-builder' ),
760 'BND' => __( 'Brunei Darussalam Dollar','profile-builder' ),
761 'KHR' => __( 'Cambodia Riel','profile-builder' ),
762 'CAD' => __( 'Canada Dollar','profile-builder' ),
763 'KYD' => __( 'Cayman Islands Dollar','profile-builder' ),
764 'CLP' => __( 'Chile Peso','profile-builder' ),
765 'CNY' => __( 'China Yuan Renminbi','profile-builder' ),
766 'COP' => __( 'Colombia Peso','profile-builder' ),
767 'CRC' => __( 'Costa Rica Colon','profile-builder' ),
768 'HRK' => __( 'Croatia Kuna','profile-builder' ),
769 'CUP' => __( 'Cuba Peso','profile-builder' ),
770 'CZK' => __( 'Czech Republic Koruna','profile-builder' ),
771 'DKK' => __( 'Denmark Krone','profile-builder' ),
772 'DOP' => __( 'Dominican Republic Peso','profile-builder' ),
773 'XCD' => __( 'East Caribbean Dollar','profile-builder' ),
774 'EGP' => __( 'Egypt Pound','profile-builder' ),
775 'SVC' => __( 'El Salvador Colon','profile-builder' ),
776 'EEK' => __( 'Estonia Kroon','profile-builder' ),
777 'EUR' => __( 'Euro','profile-builder' ),
778 'FKP' => __( 'Falkland Islands (Malvinas) Pound','profile-builder' ),
779 'FJD' => __( 'Fiji Dollar','profile-builder' ),
780 'GHC' => __( 'Ghana Cedis','profile-builder' ),
781 'GIP' => __( 'Gibraltar Pound','profile-builder' ),
782 'GTQ' => __( 'Guatemala Quetzal','profile-builder' ),
783 'GGP' => __( 'Guernsey Pound','profile-builder' ),
784 'GYD' => __( 'Guyana Dollar','profile-builder' ),
785 'HNL' => __( 'Honduras Lempira','profile-builder' ),
786 'HKD' => __( 'Hong Kong Dollar','profile-builder' ),
787 'HUF' => __( 'Hungary Forint','profile-builder' ),
788 'ISK' => __( 'Iceland Krona','profile-builder' ),
789 'INR' => __( 'India Rupee','profile-builder' ),
790 'IDR' => __( 'Indonesia Rupiah','profile-builder' ),
791 'IRR' => __( 'Iran Rial','profile-builder' ),
792 'IMP' => __( 'Isle of Man Pound','profile-builder' ),
793 'ILS' => __( 'Israel Shekel','profile-builder' ),
794 'JMD' => __( 'Jamaica Dollar','profile-builder' ),
795 'JPY' => __( 'Japan Yen','profile-builder' ),
796 'JEP' => __( 'Jersey Pound','profile-builder' ),
797 'KZT' => __( 'Kazakhstan Tenge','profile-builder' ),
798 'KPW' => __( 'Korea (North) Won','profile-builder' ),
799 'KRW' => __( 'Korea (South) Won','profile-builder' ),
800 'KGS' => __( 'Kyrgyzstan Som','profile-builder' ),
801 'LAK' => __( 'Laos Kip','profile-builder' ),
802 'LVL' => __( 'Latvia Lat','profile-builder' ),
803 'LBP' => __( 'Lebanon Pound','profile-builder' ),
804 'LRD' => __( 'Liberia Dollar','profile-builder' ),
805 'LTL' => __( 'Lithuania Litas','profile-builder' ),
806 'MKD' => __( 'Macedonia Denar','profile-builder' ),
807 'MYR' => __( 'Malaysia Ringgit','profile-builder' ),
808 'MUR' => __( 'Mauritius Rupee','profile-builder' ),
809 'MXN' => __( 'Mexico Peso','profile-builder' ),
810 'MNT' => __( 'Mongolia Tughrik','profile-builder' ),
811 'MZN' => __( 'Mozambique Metical','profile-builder' ),
812 'NAD' => __( 'Namibia Dollar','profile-builder' ),
813 'NPR' => __( 'Nepal Rupee','profile-builder' ),
814 'ANG' => __( 'Netherlands Antilles Guilder','profile-builder' ),
815 'NZD' => __( 'New Zealand Dollar','profile-builder' ),
816 'NIO' => __( 'Nicaragua Cordoba','profile-builder' ),
817 'NGN' => __( 'Nigeria Naira','profile-builder' ),
818 'NOK' => __( 'Norway Krone','profile-builder' ),
819 'OMR' => __( 'Oman Rial', 'profile-builder' ),
820 'PKR' => __( 'Pakistan Rupee', 'profile-builder' ),
821 'PAB' => __( 'Panama Balboa', 'profile-builder' ),
822 'PYG' => __( 'Paraguay Guarani', 'profile-builder' ),
823 'PEN' => __( 'Peru Nuevo Sol', 'profile-builder' ),
824 'PHP' => __( 'Philippines Peso', 'profile-builder' ),
825 'PLN' => __( 'Poland Zloty', 'profile-builder' ),
826 'QAR' => __( 'Qatar Riyal', 'profile-builder' ),
827 'RON' => __( 'Romania New Leu', 'profile-builder' ),
828 'RUB' => __( 'Russia Ruble', 'profile-builder' ),
829 'SHP' => __( 'Saint Helena Pound', 'profile-builder' ),
830 'SAR' => __( 'Saudi Arabia Riyal', 'profile-builder' ),
831 'RSD' => __( 'Serbia Dinar', 'profile-builder' ),
832 'SCR' => __( 'Seychelles Rupee', 'profile-builder' ),
833 'SGD' => __( 'Singapore Dollar', 'profile-builder' ),
834 'SBD' => __( 'Solomon Islands Dollar', 'profile-builder' ),
835 'SOS' => __( 'Somalia Shilling', 'profile-builder' ),
836 'ZAR' => __( 'South Africa Rand', 'profile-builder' ),
837 'LKR' => __( 'Sri Lanka Rupee', 'profile-builder' ),
838 'SEK' => __( 'Sweden Krona', 'profile-builder' ),
839 'CHF' => __( 'Switzerland Franc', 'profile-builder' ),
840 'SRD' => __( 'Suriname Dollar', 'profile-builder' ),
841 'SYP' => __( 'Syria Pound', 'profile-builder' ),
842 'TWD' => __( 'Taiwan New Dollar', 'profile-builder' ),
843 'THB' => __( 'Thailand Baht', 'profile-builder' ),
844 'TTD' => __( 'Trinidad and Tobago Dollar', 'profile-builder' ),
845 'TRY' => __( 'Turkey Lira', 'profile-builder' ),
846 'TRL' => __( 'Turkey Lira', 'profile-builder' ),
847 'TVD' => __( 'Tuvalu Dollar', 'profile-builder' ),
848 'UAH' => __( 'Ukraine Hryvna', 'profile-builder' ),
849 'GBP' => __( 'United Kingdom Pound', 'profile-builder' ),
850 'UGX' => __( 'Uganda Shilling', 'profile-builder' ),
851 'USD' => __( 'US Dollar', 'profile-builder' ),
852 'UYU' => __( 'Uruguay Peso', 'profile-builder' ),
853 'UZS' => __( 'Uzbekistan Som', 'profile-builder' ),
854 'VEF' => __( 'Venezuela Bolivar', 'profile-builder' ),
855 'VND' => __( 'Viet Nam Dong', 'profile-builder' ),
856 'YER' => __( 'Yemen Rial', 'profile-builder' ),
857 'ZWD' => __( 'Zimbabwe Dollar', 'profile-builder' )
858 );
859
860 $filter_name = ( empty( $form_location ) ? 'wppb_get_currencies' : 'wppb_get_currencies_' . $form_location );
861
862 return apply_filters( $filter_name, $currencies );
863
864 }
865
866
867 /*
868 * Returns the currency symbol for a given currency code
869 *
870 * @param string $currency_code
871 *
872 * @return string
873 *
874 */
875 function wppb_get_currency_symbol( $currency_code ) {
876
877 $currency_symbols = array(
878 'AED' => '&#1583;.&#1573;', // ?
879 'AFN' => '&#65;&#102;',
880 'ALL' => '&#76;&#101;&#107;',
881 'AMD' => '',
882 'ANG' => '&#402;',
883 'AOA' => '&#75;&#122;', // ?
884 'ARS' => '&#36;',
885 'AUD' => '&#36;',
886 'AWG' => '&#402;',
887 'AZN' => '&#1084;&#1072;&#1085;',
888 'BAM' => '&#75;&#77;',
889 'BBD' => '&#36;',
890 'BDT' => '&#2547;', // ?
891 'BGN' => '&#1083;&#1074;',
892 'BHD' => '.&#1583;.&#1576;', // ?
893 'BIF' => '&#70;&#66;&#117;', // ?
894 'BMD' => '&#36;',
895 'BND' => '&#36;',
896 'BOB' => '&#36;&#98;',
897 'BRL' => '&#82;&#36;',
898 'BSD' => '&#36;',
899 'BTN' => '&#78;&#117;&#46;', // ?
900 'BWP' => '&#80;',
901 'BYR' => '&#112;&#46;',
902 'BZD' => '&#66;&#90;&#36;',
903 'CAD' => '&#36;',
904 'CDF' => '&#70;&#67;',
905 'CHF' => '&#67;&#72;&#70;',
906 'CLF' => '', // ?
907 'CLP' => '&#36;',
908 'CNY' => '&#165;',
909 'COP' => '&#36;',
910 'CRC' => '&#8353;',
911 'CUP' => '&#8396;',
912 'CVE' => '&#36;', // ?
913 'CZK' => '&#75;&#269;',
914 'DJF' => '&#70;&#100;&#106;', // ?
915 'DKK' => '&#107;&#114;',
916 'DOP' => '&#82;&#68;&#36;',
917 'DZD' => '&#1583;&#1580;', // ?
918 'EGP' => '&#163;',
919 'ETB' => '&#66;&#114;',
920 'EUR' => '&#8364;',
921 'FJD' => '&#36;',
922 'FKP' => '&#163;',
923 'GBP' => '&#163;',
924 'GEL' => '&#4314;', // ?
925 'GHS' => '&#162;',
926 'GIP' => '&#163;',
927 'GMD' => '&#68;', // ?
928 'GNF' => '&#70;&#71;', // ?
929 'GTQ' => '&#81;',
930 'GYD' => '&#36;',
931 'HKD' => '&#36;',
932 'HNL' => '&#76;',
933 'HRK' => '&#107;&#110;',
934 'HTG' => '&#71;', // ?
935 'HUF' => '&#70;&#116;',
936 'IDR' => '&#82;&#112;',
937 'ILS' => '&#8362;',
938 'INR' => '&#8377;',
939 'IQD' => '&#1593;.&#1583;', // ?
940 'IRR' => '&#65020;',
941 'ISK' => '&#107;&#114;',
942 'JEP' => '&#163;',
943 'JMD' => '&#74;&#36;',
944 'JOD' => '&#74;&#68;', // ?
945 'JPY' => '&#165;',
946 'KES' => '&#75;&#83;&#104;', // ?
947 'KGS' => '&#1083;&#1074;',
948 'KHR' => '&#6107;',
949 'KMF' => '&#67;&#70;', // ?
950 'KPW' => '&#8361;',
951 'KRW' => '&#8361;',
952 'KWD' => '&#1583;.&#1603;', // ?
953 'KYD' => '&#36;',
954 'KZT' => '&#1083;&#1074;',
955 'LAK' => '&#8365;',
956 'LBP' => '&#163;',
957 'LKR' => '&#8360;',
958 'LRD' => '&#36;',
959 'LSL' => '&#76;', // ?
960 'LTL' => '&#76;&#116;',
961 'LVL' => '&#76;&#115;',
962 'LYD' => '&#1604;.&#1583;', // ?
963 'MAD' => '&#1583;.&#1605;.', //?
964 'MDL' => '&#76;',
965 'MGA' => '&#65;&#114;', // ?
966 'MKD' => '&#1076;&#1077;&#1085;',
967 'MMK' => '&#75;',
968 'MNT' => '&#8366;',
969 'MOP' => '&#77;&#79;&#80;&#36;', // ?
970 'MRO' => '&#85;&#77;', // ?
971 'MUR' => '&#8360;', // ?
972 'MVR' => '.&#1923;', // ?
973 'MWK' => '&#77;&#75;',
974 'MXN' => '&#36;',
975 'MYR' => '&#82;&#77;',
976 'MZN' => '&#77;&#84;',
977 'NAD' => '&#36;',
978 'NGN' => '&#8358;',
979 'NIO' => '&#67;&#36;',
980 'NOK' => '&#107;&#114;',
981 'NPR' => '&#8360;',
982 'NZD' => '&#36;',
983 'OMR' => '&#65020;',
984 'PAB' => '&#66;&#47;&#46;',
985 'PEN' => '&#83;&#47;&#46;',
986 'PGK' => '&#75;', // ?
987 'PHP' => '&#8369;',
988 'PKR' => '&#8360;',
989 'PLN' => '&#122;&#322;',
990 'PYG' => '&#71;&#115;',
991 'QAR' => '&#65020;',
992 'RON' => '&#108;&#101;&#105;',
993 'RSD' => '&#1044;&#1080;&#1085;&#46;',
994 'RUB' => '&#1088;&#1091;&#1073;',
995 'RWF' => '&#1585;.&#1587;',
996 'SAR' => '&#65020;',
997 'SBD' => '&#36;',
998 'SCR' => '&#8360;',
999 'SDG' => '&#163;', // ?
1000 'SEK' => '&#107;&#114;',
1001 'SGD' => '&#36;',
1002 'SHP' => '&#163;',
1003 'SLL' => '&#76;&#101;', // ?
1004 'SOS' => '&#83;',
1005 'SRD' => '&#36;',
1006 'STD' => '&#68;&#98;', // ?
1007 'SVC' => '&#36;',
1008 'SYP' => '&#163;',
1009 'SZL' => '&#76;', // ?
1010 'THB' => '&#3647;',
1011 'TJS' => '&#84;&#74;&#83;', // ? TJS (guess)
1012 'TMT' => '&#109;',
1013 'TND' => '&#1583;.&#1578;',
1014 'TOP' => '&#84;&#36;',
1015 'TRY' => '&#8356;', // New Turkey Lira (old symbol used)
1016 'TTD' => '&#36;',
1017 'TWD' => '&#78;&#84;&#36;',
1018 'TZS' => '',
1019 'UAH' => '&#8372;',
1020 'UGX' => '&#85;&#83;&#104;',
1021 'USD' => '&#36;',
1022 'UYU' => '&#36;&#85;',
1023 'UZS' => '&#1083;&#1074;',
1024 'VEF' => '&#66;&#115;',
1025 'VND' => '&#8363;',
1026 'VUV' => '&#86;&#84;',
1027 'WST' => '&#87;&#83;&#36;',
1028 'XAF' => '&#70;&#67;&#70;&#65;',
1029 'XCD' => '&#36;',
1030 'XDR' => '',
1031 'XOF' => '',
1032 'XPF' => '&#70;',
1033 'YER' => '&#65020;',
1034 'ZAR' => '&#82;',
1035 'ZMK' => '&#90;&#75;', // ?
1036 'ZWL' => '&#90;&#36;',
1037 );
1038
1039 if( !empty( $currency_symbols[$currency_code] ) )
1040 return $currency_symbols[$currency_code];
1041 else
1042 return '';
1043
1044 }
1045
1046
1047 /**
1048 * Function that returns a unique, incremented ID
1049 *
1050 * @since v.2.0
1051 *
1052 * @return integer id
1053 */
1054 function wppb_get_unique_id(){
1055 $id = 1;
1056 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
1057 if ( ( $wppb_manage_fields === 'not_found' ) || ( empty( $wppb_manage_fields ) ) ){
1058 return $id;
1059 }
1060 else{
1061 $ids_array = array();
1062 foreach( $wppb_manage_fields as $value ){
1063 $ids_array[] = $value['id'];
1064 }
1065 if( !empty( $ids_array ) ){
1066 rsort( $ids_array );
1067 $id = $ids_array[0] + 1;
1068 }
1069 }
1070 return apply_filters( 'wppb_field_unique_id', $id, $ids_array, $wppb_manage_fields );
1071 }
1072
1073 /**
1074 * Function that checks to see if the id is unique when saving the new field
1075 *
1076 * @param array $values
1077 *
1078 * @return array
1079 */
1080 function wppb_check_unique_id_on_saving( $values ) {
1081 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
1082
1083 if( $wppb_manage_fields != 'not_found' ) {
1084
1085 $ids_array = array();
1086 foreach( $wppb_manage_fields as $field ){
1087 $ids_array[] = $field['id'];
1088 }
1089
1090 if( in_array( $values['id'], $ids_array ) ) {
1091 rsort( $ids_array );
1092 $values['id'] = $ids_array[0] + 1;
1093 }
1094
1095 }
1096 return $values;
1097 }
1098 add_filter( 'wck_add_meta_filter_values_wppb_manage_fields', 'wppb_check_unique_id_on_saving' );
1099
1100
1101 function wppb_return_unique_field_list( $only_default_fields = false ){
1102
1103 $unique_field_list[] = 'Default - Name (Heading)';
1104 $unique_field_list[] = 'Default - Contact Info (Heading)';
1105 $unique_field_list[] = 'Default - About Yourself (Heading)';
1106 $unique_field_list[] = 'Default - Username';
1107 $unique_field_list[] = 'Default - First Name';
1108 $unique_field_list[] = 'Default - Last Name';
1109 $unique_field_list[] = 'Default - Nickname';
1110 $unique_field_list[] = 'Default - E-mail';
1111 $unique_field_list[] = 'Default - Website';
1112
1113 // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
1114 if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){
1115 $unique_field_list[] = 'Default - AIM';
1116 $unique_field_list[] = 'Default - Yahoo IM';
1117 $unique_field_list[] = 'Default - Jabber / Google Talk';
1118 }
1119
1120 $unique_field_list[] = 'Default - Password';
1121 $unique_field_list[] = 'Default - Repeat Password';
1122 $unique_field_list[] = 'Default - Biographical Info';
1123 $unique_field_list[] = 'Default - Display name publicly as';
1124
1125 $unique_field_list[] = 'GDPR Checkbox';
1126
1127 $unique_field_list[] = 'Email Confirmation';
1128
1129 if ( wppb_can_users_signup_blog() ) {
1130 $unique_field_list[] = 'Default - Blog Details';
1131 }
1132
1133 if( !$only_default_fields ){
1134 $unique_field_list[] = 'Avatar';
1135 $unique_field_list[] = 'reCAPTCHA';
1136 $unique_field_list[] = 'Select (User Role)';
1137 $unique_field_list[] = 'Map';
1138 }
1139
1140 return apply_filters ( 'wppb_unique_field_list', $unique_field_list );
1141 }
1142
1143
1144 /**
1145 * Function that checks several things when adding/editing the fields
1146 *
1147 * @since v.2.0
1148 *
1149 * @param string $message - the message to be displayed
1150 * @param array $fields - the added fields
1151 * @param array $required_fields
1152 * @param string $meta - the meta-name of the option
1153 * @param string $values - The values entered for each option
1154 * @param integer $post_id
1155 * @return boolean
1156 */
1157 function wppb_check_field_on_edit_add( $message, $fields, $required_fields, $meta_name, $posted_values, $post_id ){
1158 global $wpdb;
1159
1160 if ( $meta_name == 'wppb_manage_fields' ){
1161
1162 // check for a valid field-type (fallback)
1163 if ( $posted_values['field'] == '' )
1164 $message .= __( "You must select a field\n", 'profile-builder' );
1165 // END check for a valid field-type (fallback)
1166
1167 $unique_field_list = wppb_return_unique_field_list();
1168 $all_fields = apply_filters( 'wppb_manage_fields_check_field_on_edit_add', get_option ( $meta_name, 'not_set' ), $posted_values );
1169
1170 // check if the unique fields are only added once
1171 if( $all_fields != 'not_set' ){
1172 foreach( $all_fields as $field ){
1173 if ( ( in_array ( $posted_values['field'], $unique_field_list ) ) && ( $posted_values['field'] == $field['field'] ) && ( $posted_values['id'] != $field['id'] ) ){
1174 $message .= __( "Please choose a different field type as this one already exists in your form (must be unique)\n", 'profile-builder' );
1175 break;
1176 }
1177 }
1178 }
1179 // END check if the unique fields are only added once
1180
1181 // check for avatar size
1182 if ( $posted_values['field'] == 'Avatar' ){
1183 if ( is_numeric( $posted_values['avatar-size'] ) ){
1184 if ( ( $posted_values['avatar-size'] < 20 ) || ( $posted_values['avatar-size'] > 200 ) )
1185 $message .= __( "The entered avatar size is not between 20 and 200\n", 'profile-builder' );
1186
1187 }else
1188 $message .= __( "The entered avatar size is not numerical\n", 'profile-builder' );
1189
1190 }
1191 // END check for avatar size
1192
1193 // check for correct row value
1194 if ( ( $posted_values['field'] == 'Default - Biographical Info' ) || ( $posted_values['field'] == 'Textarea' ) ){
1195 if ( !is_numeric( $posted_values['row-count'] ) )
1196 $message .= __( "The entered row number is not numerical\n", 'profile-builder' );
1197
1198 elseif ( trim( $posted_values['row-count'] ) == '' )
1199 $message .= __( "You must enter a value for the row number\n", 'profile-builder' );
1200 }
1201 // END check for correct row value
1202
1203
1204 // check for the public and private keys
1205 if ( $posted_values['field'] == 'reCAPTCHA'){
1206 if ( trim( $posted_values['public-key'] ) == '' )
1207 $message .= __( "You must enter the site key\n", 'profile-builder' );
1208 if ( trim( $posted_values['private-key'] ) == '' )
1209 $message .= __( "You must enter the secret key\n", 'profile-builder' );
1210 }
1211 // END check for the public and private keys
1212
1213 // check for the correct the date-format
1214 if ( $posted_values['field'] == 'Datepicker' ){
1215 $date_format = trim( $posted_values['date-format'] );
1216 if( empty( $date_format ) )
1217 $message .= __( "You must enter a value for the date-format\n", 'profile-builder' );
1218 else {
1219 $date_format = preg_split("/(, | |\/|-|\.|,)/", $date_format );
1220 $valid_pieces = array('d', 'dd', 'D', 'DD', 'o', 'oo', 'm', 'mm', 'M', 'MM', 'y', 'yy', '@');
1221 if ($date_format) {
1222 $invalid_format = false;
1223 foreach ($date_format as $piece) {
1224 if (!in_array($piece, $valid_pieces)) {
1225 $invalid_format = true;
1226 break;
1227 }
1228 }
1229
1230 if ($invalid_format)
1231 $message .= __("The entered value for the Datepicker is not a valid date-format\n", 'profile-builder');
1232 }
1233 }
1234
1235 }
1236 // END check for the correct the date-format
1237
1238 //check for empty meta-name and duplicate meta-name
1239 if ( $posted_values['overwrite-existing'] == 'No' ){
1240 $skip_check_for_fields = wppb_return_unique_field_list(true);
1241 $skip_check_for_fields = apply_filters ( 'wppb_skip_check_for_fields', $skip_check_for_fields );
1242
1243 if ( !in_array( trim( $posted_values['field'] ), $skip_check_for_fields ) ){
1244 $reserved_meta_name_list = wppb_get_reserved_meta_name_list( $all_fields, $posted_values );
1245
1246 //check to see if meta-name is empty
1247 $skip_empty_check_for_fields = array( 'Heading', 'Select (User Role)', 'reCAPTCHA', 'HTML', 'GDPR Delete Button' );
1248
1249 if( !in_array( $posted_values['field'], $skip_empty_check_for_fields ) && empty( $posted_values['meta-name'] ) ) {
1250 $message .= __( "The meta-name cannot be empty\n", 'profile-builder' );
1251 }
1252
1253 //check if the meta-name starts or ends with a space
1254 if ( strpos( $posted_values['meta-name'], " " ) === 0 ) {
1255 $message .= __( "The meta-name cannot begin with a space\n", 'profile-builder' );
1256 }
1257 if ( strpos( $posted_values['meta-name'], " " ) === strlen( $posted_values['meta-name'] ) - 1 ) {
1258 $message .= __( "The meta-name cannot end with a space\n", 'profile-builder' );
1259 }
1260
1261 // meta names that are reserved and cannot be used as part of other meta names
1262 $reserved_meta_name_list_strict = apply_filters( 'wppb_unique_meta_name_list_strict', array( 'map' ) );
1263 // skip meta name check for these fields
1264 $skip_unique_meta_name_list_check = apply_filters( 'wppb_skip_unique_meta_name_list_check', array( 'Map', 'Honeypot' ) );
1265
1266 // if the desired meta name is in the restricted list or if one of the meta names in the strictly
1267 // restricted list is part of it display an error message
1268 $is_reserved_meta_name = false;
1269 $trimmed_meta_name = trim( $posted_values['meta-name'] );
1270 if ( !in_array( $posted_values['field'], $skip_unique_meta_name_list_check ) ) {
1271 foreach ($reserved_meta_name_list as $reserved_meta_name) {
1272 if (in_array($trimmed_meta_name, $reserved_meta_name_list) ||
1273 (strpos($trimmed_meta_name, $reserved_meta_name) !== false && in_array($reserved_meta_name, $reserved_meta_name_list_strict))) {
1274 $is_reserved_meta_name = true;
1275 break;
1276 }
1277 }
1278 }
1279 if ( $is_reserved_meta_name )
1280 $message .= __( "That meta-name can't be used, please choose another\n", 'profile-builder' );
1281
1282 else{
1283 $found_in_custom_fields = false;
1284
1285 if( $all_fields != 'not_set' )
1286 foreach( $all_fields as $field ){
1287 if ( $posted_values['meta-name'] != '' && ( $field['meta-name'] == $posted_values['meta-name'] ) && ( $field['id'] != $posted_values['id'] ) ){
1288 $message .= __( "That meta-name is already in use\n", 'profile-builder' );
1289 $found_in_custom_fields = true;
1290
1291 }elseif ( ( $field['meta-name'] == $posted_values['meta-name'] ) && ( $field['id'] == $posted_values['id'] ) )
1292 $found_in_custom_fields = true;
1293 }
1294
1295 if ( $found_in_custom_fields === false ){
1296 if( $posted_values['meta-name'] != '' ) {
1297 $found_meta_name = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE meta_key = %s", $posted_values['meta-name']));
1298 if ($found_meta_name != null)
1299 $message .= __("That meta-name is already in use\n", 'profile-builder');
1300 }
1301 }
1302 }
1303 }
1304 }
1305 //END check duplicate meta-name
1306
1307 // check for correct meta name on upload field
1308 if( $posted_values['field'] == 'Upload' ) {
1309 if( ! empty( $posted_values['meta-name'] ) && preg_match( '/([^a-z\d_-])/', $posted_values['meta-name'] ) ) {
1310 $message .= __( "The meta-name can only contain lowercase letters, numbers, _ , - and no spaces.\n", 'profile-builder' );
1311 }
1312 }
1313 // END check for correct meta name on upload field
1314
1315 // check for valid default option (checkbox, select, radio)
1316 if ( ( $posted_values['field'] == 'Checkbox' ) || ( $posted_values['field'] == 'Select (Multiple)' ) ) {
1317 $options = array_map( 'trim', explode( ',', $posted_values['options'] ) );
1318 $default_options = ( ( trim( $posted_values['default-options'] ) == '' ) ? array() : array_map( 'trim', explode( ',', $posted_values['default-options'] ) ) );
1319
1320 /* echo "<script>console.log( Posted options: " . print_r($options, true) . "' );</script>";
1321 echo "<script>console.log( Default options: " . print_r($default_options, true) . "' );</script>"; */
1322
1323 $not_found = '';
1324 foreach ( $default_options as $key => $value ){
1325 if ( !in_array( $value, $options ) )
1326 $not_found .= $value . ', ';
1327 }
1328
1329 if ( $not_found != '' )
1330 $message .= sprintf( __( "The following option(s) did not coincide with the ones in the options list: %s\n", 'profile-builder' ), trim( $not_found, ', ' ) );
1331
1332 }elseif ( ( $posted_values['field'] == 'Radio' ) || ( $posted_values['field'] == 'Select' ) ){
1333 if ( ( trim( $posted_values['default-option'] ) != '' ) && ( !in_array( $posted_values['default-option'], array_map( 'trim', explode( ',', $posted_values['options'] ) ) ) ) )
1334 $message .= sprintf( __( "The following option did not coincide with the ones in the options list: %s\n", 'profile-builder' ), $posted_values['default-option'] );
1335 }
1336 // END check for valid default option (checkbox, select, radio)
1337
1338 // check to see if any user role is selected (user-role field)
1339 if( $posted_values['field'] == 'Select (User Role)' ) {
1340 if( empty( $posted_values['user-roles'] ) ) {
1341 $message .= __( "Please select at least one user role\n", 'profile-builder' );
1342 }
1343 }
1344 // END check to see if Administrator user role has been selected (user-role field)
1345
1346 $message = apply_filters( 'wppb_check_extra_manage_fields', $message, $posted_values );
1347
1348 }elseif ( ( $meta_name == 'wppb_rf_fields' ) || ( $meta_name == 'wppb_epf_fields' ) ){
1349 if ( $posted_values['field'] == '' ){
1350 $message .= __( "You must select a field\n", 'profile-builder' );
1351
1352 }else{
1353 $fields_so_far = get_post_meta ( $post_id, $meta_name, true );
1354 if ( !empty($fields_so_far) ){
1355 foreach ( $fields_so_far as $key => $value ){
1356 if ( $value['id'] == $posted_values['id'] )
1357 $message .= __( "That field is already added in this form\n", 'profile-builder' );
1358 }
1359 }
1360 }
1361 }
1362 return $message;
1363 }
1364 add_filter( 'wck_extra_message', 'wppb_check_field_on_edit_add', 10, 6 );
1365
1366
1367 /**
1368 * Function that calls the wppb_hide_properties_for_already_added_fields and wppb_enable_select2 after a field-update
1369 *
1370 * @since v.2.0
1371 *
1372 * @param void
1373 *
1374 * @return string
1375 */
1376 function wppb_manage_fields_after_refresh_list( $id ){
1377 echo "<script type=\"text/javascript\">wppb_hide_properties_for_already_added_fields( '#container_wppb_manage_fields' );</script>";
1378 echo "<script type=\"text/javascript\">wppb_enable_select2( '#wppb_manage_fields' );</script>";
1379
1380 }
1381 add_action( "wck_refresh_list_wppb_manage_fields", "wppb_manage_fields_after_refresh_list" );
1382 add_action( "wck_refresh_entry_wppb_manage_fields", "wppb_manage_fields_after_refresh_list" );
1383
1384 /**
1385 * Function that calls the wppb_hide_all and wppb_enable_select2
1386 *
1387 * @since v.2.0
1388 *
1389 * @param void
1390 *
1391 * @return string
1392 */
1393 function wppb_manage_fields_after_ajax_add_field( $id ){
1394 echo "<script type=\"text/javascript\">wppb_hide_all( '#wppb_manage_fields' );</script>";
1395 echo "<script type=\"text/javascript\">wppb_enable_select2( '#wppb_manage_fields' );</script>";
1396 }
1397 add_action("wck_ajax_add_form_wppb_manage_fields", "wppb_manage_fields_after_ajax_add_field" );
1398
1399 /**
1400 * Function that modifies the table header in Manage Fields to add Field Name, Field Type, Meta Key, Required
1401 *
1402 * @since v.2.0
1403 *
1404 * @param $list, $id
1405 *
1406 * @return string
1407 */
1408 function wppb_manage_fields_header( $list_header ){
1409 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>';
1410 }
1411 add_action( 'wck_metabox_content_header_wppb_manage_fields', 'wppb_manage_fields_header' );
1412
1413 /**
1414 * Add contextual help to the side of manage fields for the shortcodes
1415 *
1416 * @since v.2.0
1417 *
1418 * @param $hook
1419 *
1420 * @return string
1421 */
1422 function wppb_add_content_before_manage_fields(){
1423 ?>
1424 <p><?php esc_html_e('Use these shortcodes on the pages you want the forms to be displayed:', 'profile-builder'); ?></p>
1425 <ul>
1426 <li><strong class="nowrap">[wppb-register]</strong></li>
1427 <li><strong class="nowrap">[wppb-edit-profile]</strong></li>
1428 <li><strong class="nowrap">[wppb-register role="author"]</strong></li>
1429 </ul>
1430 <p>
1431 <?php
1432 $versions = array( 'Profile Builder Pro', 'Profile Builder Elite', 'Profile Builder Unlimited', 'Profile Builder Dev' );
1433
1434 if( in_array( PROFILE_BUILDER, $versions ) )
1435 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');
1436 else
1437 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" )
1438 ?>
1439 </p>
1440 <?php
1441 }
1442 add_action('wck_metabox_content_wppb_manage_fields_info', 'wppb_add_content_before_manage_fields');
1443
1444
1445 /**
1446 * Function that calls the wppb_edit_form_properties
1447 *
1448 * @since v.2.0
1449 *
1450 * @param void
1451 *
1452 * @return string
1453 */
1454 function wppb_remove_properties_from_added_form( $meta_name, $id, $element_id ){
1455 if ( ( $meta_name == 'wppb_epf_fields' ) || ( $meta_name == 'wppb_rf_fields' ) )
1456 echo "<script type=\"text/javascript\">wppb_disable_delete_on_default_mandatory_fields();</script>";
1457
1458 if ( $meta_name == 'wppb_manage_fields' ) {
1459 echo "<script type=\"text/javascript\">wppb_edit_form_properties( '#container_wppb_manage_fields', 'update_container_wppb_manage_fields_" . esc_attr( $element_id ) . "' );</script>";
1460 echo "<script type=\"text/javascript\">wppb_enable_select2( '#container_wppb_manage_fields' );</script>";
1461 }
1462 }
1463 add_action("wck_after_adding_form", "wppb_remove_properties_from_added_form", 10, 3);
1464
1465 /*
1466 * WPML Support for dynamic strings in Profile Builder. Tags: WPML, fields, translate
1467 */
1468 add_filter( 'update_option_wppb_manage_fields', 'wppb_wpml_compat_with_fields', 10, 2 );
1469 function wppb_wpml_compat_with_fields( $oldvalue, $_newvalue ){
1470 $default_fields = array(
1471 'Default - Name (Heading)',
1472 'Default - Contact Info (Heading)',
1473 'Default - About Yourself (Heading)',
1474 'Default - Username',
1475 'Default - First Name',
1476 'Default - Last Name',
1477 'Default - Nickname',
1478 'Default - E-mail',
1479 'Default - Website',
1480 'Default - AIM',
1481 'Default - Yahoo IM',
1482 'Default - Jabber / Google Talk',
1483 'Default - Password',
1484 'Default - Repeat Password',
1485 'Default - Biographical Info',
1486 'Default - Blog Details',
1487 'Default - Display name publicly as'
1488 );
1489
1490 if ( is_array( $_newvalue ) ){
1491 foreach ( $_newvalue as $field ){
1492 if ( in_array($field['field'], $default_fields) ){
1493 $prefix = 'default_field_';
1494 } else {
1495 $prefix = 'custom_field_';
1496 }
1497 if (function_exists('wppb_icl_register_string')){
1498 if( !empty( $field['field-title'] ) )
1499 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_title_translation' , $field['field-title'] );
1500 if( !empty( $field['description'] ) )
1501 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_description_translation', $field['description'] );
1502 if( !empty( $field['labels'] ) )
1503 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_labels_translation', $field['labels'] );
1504 if( !empty( $field['default-value'] ) )
1505 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_default_value_translation', $field['default-value'] );
1506 if( !empty( $field['default-content'] ) )
1507 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_default_content_translation', $field['default-content'] );
1508 if( !empty( $field['html-content'] ) )
1509 wppb_icl_register_string('plugin profile-builder-pro', $prefix . $field['id'].'_html_content_translation', $field['html-content'] );
1510 }
1511 }
1512 }
1513 }
1514
1515
1516 /*
1517 * Returns the HTML for a map given the field
1518 *
1519 */
1520 function wppb_get_map_output( $field, $args ) {
1521
1522 $defaults = array(
1523 'markers' => array(),
1524 'editable' => true,
1525 'show_search' => true,
1526 'extra_attr' => ''
1527 );
1528
1529 $args = wp_parse_args( $args, $defaults );
1530
1531 $return = '';
1532
1533 // Search box
1534 // The style:left=-99999px is set to hide the input from the viewport. It will be rewritten when the map gets initialised
1535 if ( $args['show_search'] ) {
1536 $return .= '<input style="left: -99999px" type="text" id="' . $field['meta-name'] . '-search-box" class="wppb-map-search-box" placeholder="' . __( 'Search Location', 'profile-builder' ) . '" />';
1537 }
1538
1539 $lng = ( ! empty( $field['map-default-lng'] ) ) ? (float) $field['map-default-lng'] : WPPB_DEFAULTS_MAP_LNG;
1540 $lat = ( ! empty( $field['map-default-lat'] ) ) ? (float) $field['map-default-lat'] : WPPB_DEFAULTS_MAP_LAT;
1541 $zoom = ( ! empty( $field['map-default-zoom'] ) ) ? (int) $field['map-default-zoom'] : WPPB_DEFAULTS_MAP_ZOOM;
1542
1543 // Get one time the settings.
1544 $settings = wppb_options_get_map_settings();
1545 $pin_info = ( ! empty( $args['user_id'] ) ) ? wppb_compute_simple_pin_content_for_user( $args['user_id'], $settings ) : '';
1546
1547 // Map container.
1548 $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>';
1549
1550 if ( ! empty( $args['markers'] ) ) {
1551 foreach ( $args['markers'] as $marker ) {
1552 if ( ! empty( $args['user_id'] ) ) {
1553 // Also compute the marker bubble content.
1554 $bubble = wppb_get_user_pin_bubble(
1555 $args['user_id'],
1556 strstr( $marker, ',', true ),
1557 ltrim( strstr( $marker, ',' ), ',' ),
1558 $pin_info,
1559 ''
1560 );
1561 $return .= $bubble;
1562 }
1563
1564 $return .= '<input name="' . $field['meta-name'] . '[]" type="hidden" class="wppb-map-marker" value="' . $marker . '" />';
1565 }
1566 }
1567
1568 return $return;
1569 }
1570
1571
1572 /*
1573 * Returns all the saved markers for a map field for a particular user
1574 *
1575 */
1576 function wppb_get_user_map_markers( $user_id, $meta_name ) {
1577
1578 global $wpdb;
1579
1580 $meta_name_underlined = $meta_name . '_';
1581
1582 $results = $wpdb->get_results( "SELECT meta_value, meta_key FROM {$wpdb->usermeta} WHERE user_id={$user_id} AND meta_key LIKE '%{$meta_name_underlined}%'", ARRAY_N );
1583
1584 $markers = array();
1585 $i = 0;
1586
1587 foreach( $results as $key => $result ) {
1588 $pattern = '/^' . $meta_name . '_[0-9]+(_[0-9]+)*$/';
1589 preg_match( $pattern, $result[1], $matches );
1590 if ( count ($matches) > 0 ) {
1591 $markers[$i] = $result[0];
1592 $i++;
1593 }
1594
1595 }
1596 return $markers;
1597
1598 }
1599
1600 /*
1601 * Deletes from the database all saved markers
1602 *
1603 */
1604 function wppb_delete_user_map_markers( $user_id, $meta_name ) {
1605
1606 global $wpdb;
1607
1608 $delete = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE user_id=%d AND meta_key REGEXP %s", $user_id, $meta_name . '_[0-9]' ) );
1609
1610 wp_cache_delete( $user_id, 'user_meta' );
1611
1612 }
1613
1614
1615 if ( ! function_exists( 'wppb_options_get_map_settings' ) ) {
1616 /**
1617 * Get all the map related attributes.
1618 *
1619 * @return string
1620 */
1621 function wppb_options_get_map_settings() {
1622 $manage_fields = apply_filters(
1623 'wppb_form_fields',
1624 get_option( 'wppb_manage_fields', 'not_set' ),
1625 array( 'context' => 'map_api_key' )
1626 );
1627 foreach ( $manage_fields as $field ) {
1628 if ( ! empty( $field['map-api-key'] ) ) {
1629 // Fail-fast. This is what we need.
1630 return $field;
1631 }
1632 }
1633
1634 // Fallback.
1635 return null;
1636 }
1637 }
1638
1639 if ( ! function_exists( 'wppb_get_user_pin_bubble' ) ) {
1640 /**
1641 * Returns the map usable marker info.
1642 *
1643 * @param integer $id The user ID.
1644 * @param float $lat The latitude.
1645 * @param float $lng The longitude.
1646 * @param string $info The bubble inner info.
1647 * @param string $icon The pin custom icon.
1648 * @return string
1649 */
1650 function wppb_get_user_pin_bubble( $id, $lat, $lng, $info, $icon = '' ) {
1651 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>';
1652 }
1653 }
1654
1655 if ( ! function_exists( 'wppb_compute_simple_pin_content_for_user' ) ) {
1656 /**
1657 * Compute simple pin content for user.
1658 *
1659 * @param integer $id_user User ID.
1660 * @param array $settings Settings array.
1661 * @return string
1662 */
1663 function wppb_compute_simple_pin_content_for_user( $id_user, $settings = array() ) {
1664
1665 if ( empty( $id_user ) ) {
1666 // Fail-fast.
1667 return '';
1668 }
1669 if ( empty( $settings ) ) {
1670 // Get one time the settings.
1671 $settings = wppb_options_get_map_settings();
1672 }
1673
1674 $args = ( ! empty( $settings['map-bubble-fields'] ) ) ? explode( ', ', $settings['map-bubble-fields'] ) : array();
1675 $result = '';
1676 if ( ! empty( $args ) ) {
1677 foreach ( $args as $tag ) {
1678 // Go to souce.
1679 if ( 'avatar_or_gravatar' == $tag ) {
1680 $val = apply_filters( 'mustache_variable_avatar_or_gravatar', '', $tag, array(), array(
1681 'user_id' => $id_user,
1682 ) );
1683 } else {
1684 $val = apply_filters( 'mustache_variable_default_user_field', '', $tag, array(), array(
1685 'user_id' => $id_user,
1686 ) );
1687 }
1688 if ( ! empty( $val ) ) {
1689 $result .= '<p class="marker-info-' . esc_attr( $tag ) . '">' . wp_kses_post( $val ) . '</p>';
1690 }
1691 }
1692 }
1693
1694 return $result;
1695 }
1696 }
1697
1698
1699 /**
1700 * Disable the add button again after we added a field
1701 */
1702 add_action( 'wck_ajax_add_form_wppb_manage_fields', 'wppb_redisable_the_add_button' );
1703 function wppb_redisable_the_add_button(){
1704 ?>
1705 <script>wppb_disable_add_entry_button ( '#wppb_manage_fields' );</script>
1706 <?php
1707 }
1708
1709
1710 /**
1711 * 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
1712 */
1713 add_action( 'wck_before_update_meta', 'wppb_change_field_meta_key', 10, 4 );
1714 function wppb_change_field_meta_key( $meta, $id, $values, $element_id ){
1715 if( apply_filters( 'wppb_update_field_meta_key_in_db', false ) ) {
1716 if ($meta == 'wppb_manage_fields') {
1717 global $wpdb;
1718 $wppb_manage_fields = get_option('wppb_manage_fields');
1719 if (!empty($wppb_manage_fields)) {
1720
1721 /*
1722 * We need to be sure this is not a repeater.
1723 * The way we're doing this is by checking if the $values['meta-name'] is found inside $wppb_manage_fields
1724 * If it's not, it's probably inside a repeater.
1725 *
1726 * The reason we're doing this is because when we're updating a repeater field the $meta is still 'wppb_manage_fields' for some reason, while $element_id comes from the position of the repeater.
1727 *
1728 * This means we're updating last_name (if it's the 9'th position in wppb_manage_fields) instead of 'something_repeater' that's also in the 9'th position but inside the repeater group.
1729 *
1730 * Also, this code didn't account for 'something_repeater_1' etc, meaning it would have changed just 1 field, causing data loss anyway.
1731 *
1732 */
1733 $is_not_repeater = false;
1734 foreach ($wppb_manage_fields as $field){
1735 if ( $field['meta-name'] == $values['meta-name'] ){
1736 $is_not_repeater = true;
1737 }
1738 }
1739
1740 if (!empty($values['meta-name']) && $wppb_manage_fields[$element_id]['meta-name'] != $values['meta-name'] && $is_not_repeater ) {
1741 $wpdb->update(
1742 $wpdb->usermeta,
1743 array('meta_key' => sanitize_text_field($values['meta-name'])),
1744 array('meta_key' => sanitize_text_field($wppb_manage_fields[$element_id]['meta-name']))
1745 );
1746 } else {
1747 return;
1748 }
1749 }
1750 }
1751 }
1752 }
1753
1754
1755 if ( ! function_exists( 'wppb_prepare_key_value_options' ) ) {
1756 /**
1757 * Convert an array with keys and values into a usable option for the defined fields types.
1758 *
1759 * @param arrays $array List of options.
1760 * @return array Usable options.
1761 */
1762 function wppb_prepare_key_value_options( $array = array() ) {
1763 $result = array();
1764 if ( ! empty( $array ) ) {
1765 foreach ( $array as $name => $label ) {
1766 $result[] = '%' . wppb_prepare_wck_labels( $label ) . '%' . $name;
1767 }
1768 }
1769 return $result;
1770 }
1771 }
1772
1773 if ( ! function_exists( 'wppb_filter_map_bubble_fields' ) ) {
1774 /**
1775 * Filter the map POI's bubble content.
1776 *
1777 * @param arrays $tags List of available tags.
1778 * @return array Filtered and sorted tags.
1779 */
1780 function wppb_filter_map_bubble_fields( $tags ) {
1781 // Attempt to preseve one tag example.
1782 $maybe_avatar = ( ! empty( $tags['avatar_or_gravatar'] ) ) ? $tags['avatar_or_gravatar'] : false;
1783
1784 // Remove some of the tags.
1785 unset( $tags['meta_user_name'] );
1786 unset( $tags['more_info_url'] );
1787 unset( $tags['avatar_or_gravatar'] );
1788
1789 if ( ! empty( $maybe_avatar ) ) {
1790 // Perhaps preprend this to the list.
1791 $tags = array_merge( array( 'avatar_or_gravatar' => $maybe_avatar ), $tags );
1792 }
1793
1794 return $tags;
1795 }
1796 }
1797 add_filter( 'wppb_map_bubble_fields', 'wppb_filter_map_bubble_fields' );
1798