function wppb_country_select_handler($output, $form_location, $field, $user_id, $field_check_errors, $request_data)
{
    if ($field['field'] == 'Select (Country)') {
        $item_title = apply_filters('wppb_' . $form_location . '_country_select_custom_field_' . $field['id'] . '_item_title', wppb_icl_t('plugin profile-builder-pro', 'custom_field_' . $field['id'] . '_title_translation', $field['field-title']));
        $item_description = wppb_icl_t('plugin profile-builder-pro', 'custom_field_' . $field['id'] . '_description_translation', $field['description']);
        $country_array = wppb_country_select_options($form_location);
        $old_country_array = array("Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia, Plurinational State of", "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cabo Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote dIvoire", "Croatia", "Cuba", "Curacao", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island and McDonald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic Peoples Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan", "Lao Peoples Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, the former Yugoslav Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestine, State of", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Barthelemy", "Saint Helena, Ascension and Tristan da Cunha", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin (French part)", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Sint Maarten (Dutch part)", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela, Bolivarian Republic of", "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe");
        $extra_attr = apply_filters('wppb_extra_attribute', '', $field);
        if ($form_location != 'register') {
            // change current user country meta_value with country ISO code
            $user_country_option = wppb_user_meta_exists($user_id, $field['meta-name']);
            if ($user_country_option != null) {
                if (in_array($user_country_option->meta_value, $old_country_array)) {
                    $country_iso = array_search($user_country_option->meta_value, $country_array);
                    update_user_meta($user_id, $field['meta-name'], $country_iso);
                }
            }
            $input_value = $user_country_option != null ? $country_array[stripslashes(get_user_meta($user_id, $field['meta-name'], true))] : $country_array[$field['default-option-country']];
        } else {
            $input_value = !empty($field['default-option-country']) ? $country_array[trim($field['default-option-country'])] : '';
        }
        $input_value = isset($request_data[wppb_handle_meta_name($field['meta-name'])]) ? $country_array[trim($request_data[wppb_handle_meta_name($field['meta-name'])])] : $input_value;
        if ($form_location != 'back_end') {
            $error_mark = $field['required'] == 'Yes' ? '<span class="wppb-required" title="' . wppb_required_field_error($field["field-title"]) . '">*</span>' : '';
            if (array_key_exists($field['id'], $field_check_errors)) {
                $error_mark = '<img src="' . WPPB_PLUGIN_URL . 'assets/images/pencil_delete.png" title="' . wppb_required_field_error($field["field-title"]) . '"/>';
            }
            $output = '
				<label for="' . $field['meta-name'] . '">' . $item_title . $error_mark . '</label>
				<select name="' . $field['meta-name'] . '" id="' . $field['meta-name'] . '" class="custom_field_country_select ' . apply_filters('wppb_fields_extra_css_class', '', $field) . '" ' . $extra_attr . '>';
            foreach ($country_array as $iso => $country) {
                $output .= '<option value="' . $iso . '"';
                if ($input_value === $country) {
                    $output .= ' selected';
                }
                $output .= '>' . $country . '</option>';
            }
            $output .= '
				</select>';
            if (!empty($item_description)) {
                $output .= '<span class="wppb-description-delimiter">' . $item_description . '</span>';
            }
        } else {
            $output = '
				<table class="form-table">
					<tr>
						<th><label for="' . $field['meta-name'] . '">' . $item_title . '</label></th>
						<td>
							<select name="' . $field['meta-name'] . '" class="custom_field_country_select" id="' . $field['meta-name'] . '" ' . $extra_attr . '>';
            foreach ($country_array as $iso => $country) {
                $output .= '<option value="' . $iso . '"';
                if ($input_value === $country) {
                    $output .= ' selected';
                }
                $output .= '>' . $country . '</option>';
            }
            $output .= '</select>
							<span class="description">' . $item_description . '</span>
						</td>
					</tr>
				</table>';
        }
        return apply_filters('wppb_' . $form_location . '_country_select_custom_field_' . $field['id'], $output, $form_location, $field, $user_id, $field_check_errors, $request_data, $input_value);
    }
}
/**
 * Function that creates the Manage Fields submenu and populates it with a repeater field form
 *
 * @since v.2.0
 *
 * @return void
 */
function wppb_manage_fields_submenu()
{
    // create a new sub_menu page which holds the data for the default + extra fields
    $args = array('menu_title' => __('Manage Fields', 'profilebuilder'), 'page_title' => __('Manage Default and Extra Fields', 'profilebuilder'), 'menu_slug' => 'manage-fields', 'page_type' => 'submenu_page', 'capability' => 'manage_options', 'priority' => 5, 'parent_slug' => 'profile-builder');
    $all_fields = new WCK_Page_Creator_PB($args);
    // populate this page
    $manage_field_types[] = 'Default - Name (Heading)';
    $manage_field_types[] = 'Default - Contact Info (Heading)';
    $manage_field_types[] = 'Default - About Yourself (Heading)';
    $manage_field_types[] = 'Default - Username';
    $manage_field_types[] = 'Default - First Name';
    $manage_field_types[] = 'Default - Last Name';
    $manage_field_types[] = 'Default - Nickname';
    $manage_field_types[] = 'Default - E-mail';
    $manage_field_types[] = 'Default - Website';
    // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
    if (apply_filters('wppb_remove_default_contact_methods', get_site_option('initial_db_version') < 23588)) {
        $manage_field_types[] = 'Default - AIM';
        $manage_field_types[] = 'Default - Yahoo IM';
        $manage_field_types[] = 'Default - Jabber / Google Talk';
    }
    $manage_field_types[] = 'Default - Password';
    $manage_field_types[] = 'Default - Repeat Password';
    $manage_field_types[] = 'Default - Biographical Info';
    $manage_field_types[] = 'Default - Display name publicly as';
    if (PROFILE_BUILDER != 'Profile Builder Free') {
        $manage_field_types[] = 'Heading';
        $manage_field_types[] = 'Input';
        $manage_field_types[] = 'Input (Hidden)';
        $manage_field_types[] = 'Textarea';
        $manage_field_types[] = 'WYSIWYG';
        $manage_field_types[] = 'Select';
        $manage_field_types[] = 'Select (Multiple)';
        $manage_field_types[] = 'Select (Country)';
        $manage_field_types[] = 'Select (Timezone)';
        $manage_field_types[] = 'Select (User Role)';
        $manage_field_types[] = 'Checkbox';
        $manage_field_types[] = 'Checkbox (Terms and Conditions)';
        $manage_field_types[] = 'Radio';
        $manage_field_types[] = 'Upload';
        $manage_field_types[] = 'Avatar';
        $manage_field_types[] = 'Datepicker';
        $manage_field_types[] = 'reCAPTCHA';
    }
    //Free to Pro call to action on Manage Fields page
    $field_description = __('Choose one of the supported field types', 'profilebuilder');
    if (PROFILE_BUILDER == 'Profile Builder Free') {
        $field_description .= sprintf(__('. Extra Field Types are available in <a href="%s">Hobbyist or PRO versions</a>.', 'profilebuilder'), esc_url('http://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=wpbackend&utm_medium=clientsite&utm_content=manage-fields-link&utm_campaign=PBFree'));
    }
    //user roles
    global $wp_roles;
    $user_roles = array();
    foreach ($wp_roles->roles as $user_role_slug => $user_role) {
        if ($user_role_slug !== 'administrator') {
            array_push($user_roles, '%' . $user_role['name'] . '%' . $user_role_slug);
        }
    }
    // set up the fields array
    $fields = apply_filters('wppb_manage_fields', array(array('type' => 'text', 'slug' => 'field-title', 'title' => __('Field Title', 'profilebuilder'), 'description' => __('Title of the field', 'profilebuilder')), array('type' => 'select', 'slug' => 'field', 'title' => __('Field', 'profilebuilder'), 'options' => apply_filters('wppb_manage_fields_types', $manage_field_types), 'default-option' => true, 'description' => $field_description), array('type' => 'text', 'slug' => 'meta-name', 'title' => __('Meta-name', 'profilebuilder'), 'default' => wppb_get_meta_name(), 'description' => __('Use this in conjuction 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 uniqe)<br/>Changing this might take long in case of a very big user-count', 'profilebuilder')), array('type' => 'text', 'slug' => 'id', 'title' => __('ID', 'profilebuilder'), '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", 'profilebuilder'), 'readonly' => true), array('type' => 'textarea', 'slug' => 'description', 'title' => __('Description', 'profilebuilder'), 'description' => __('Enter a (detailed) description of the option for end users to read<br/>Optional', 'profilebuilder')), array('type' => 'text', 'slug' => 'row-count', 'title' => __('Row Count', 'profilebuilder'), 'default' => 5, 'description' => __("Specify the number of rows for a 'Textarea' field<br/>If not specified, defaults to 5", 'profilebuilder')), array('type' => 'text', 'slug' => 'allowed-image-extensions', 'title' => __('Allowed Image Extensions', 'profilebuilder'), '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 (.*)', 'profilebuilder')), array('type' => 'text', 'slug' => 'allowed-upload-extensions', 'title' => __('Allowed Upload Extensions', 'profilebuilder'), '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 (.*)', 'profilebuilder')), array('type' => 'text', 'slug' => 'avatar-size', 'title' => __('Avatar Size', 'profilebuilder'), 'default' => 100, 'description' => __("Enter a value (between 20 and 200) for the size of the 'Avatar'<br/>If not specified, defaults to 100", 'profilebuilder')), array('type' => 'text', 'slug' => 'date-format', 'title' => __('Date-format', 'profilebuilder'), '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<br/>If not specified, defaults to mm/dd/yy', 'profilebuilder')), array('type' => 'textarea', 'slug' => 'terms-of-agreement', 'title' => __('Terms of Agreement', 'profilebuilder'), 'description' => __('Enter a detailed description of the temrs 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;', 'profilebuilder')), array('type' => 'text', 'slug' => 'options', 'title' => __('Options', 'profilebuilder'), '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", 'profilebuilder')), array('type' => 'text', 'slug' => 'labels', 'title' => __('Labels', 'profilebuilder'), 'description' => __("Enter a comma separated list of labels<br/>Visible for the user", 'profilebuilder')), array('type' => 'text', 'slug' => 'public-key', 'title' => __('Site Key', 'profilebuilder'), 'description' => __('The site key from Google, <a href="http://www.google.com/recaptcha" target="_blank">www.google.com/recaptcha</a>', 'profilebuilder')), array('type' => 'text', 'slug' => 'private-key', 'title' => __('Secret Key', 'profilebuilder'), 'description' => __('The secret key from Google, <a href="http://www.google.com/recaptcha" target="_blank">www.google.com/recaptcha</a>', 'profilebuilder')), array('type' => 'checkbox', 'slug' => 'captcha-pb-forms', 'title' => __('Display on PB forms', 'profilebuilder'), 'options' => array('%' . __('PB Login', 'profilebuilder') . '%' . 'pb_login', '%' . __('PB Register', 'profilebuilder') . '%' . 'pb_register', '%' . __('PB Recover Password', 'profilebuilder') . '%' . 'pb_recover_password'), 'default' => 'pb_register', 'description' => __("Select on which Profile Builder forms to display reCAPTCHA", 'profilebuilder')), array('type' => 'checkbox', 'slug' => 'captcha-wp-forms', 'title' => __('Display on default WP forms', 'profilebuilder'), 'options' => array('%' . __('Default WP Login', 'profilebuilder') . '%' . 'default_wp_login', '%' . __('Default WP Register', 'profilebuilder') . '%' . 'default_wp_register', '%' . __('Default WP Recover Password', 'profilebuilder') . '%' . 'default_wp_recover_password'), 'default' => 'default_wp_register', 'description' => __("Select on which default WP forms to display reCAPTCHA", 'profilebuilder')), array('type' => 'checkbox', 'slug' => 'user-roles', 'title' => __('User Roles', 'profilebuilder'), 'options' => $user_roles, 'description' => __("Select which user roles to show to the user ( drag and drop to re-order )", 'profilebuilder')), array('type' => 'text', 'slug' => 'user-roles-sort-order', 'title' => __('User Roles Order', 'profilebuilder'), 'description' => __("Save the user role order from the user roles checkboxes", 'profilebuilder')), array('type' => 'text', 'slug' => 'default-value', 'title' => __('Default Value', 'profilebuilder'), 'description' => __("Default value of the field", 'profilebuilder')), array('type' => 'text', 'slug' => 'default-option', 'title' => __('Default Option', 'profilebuilder'), 'description' => __("Specify the option which should be selected by default", 'profilebuilder')), array('type' => 'text', 'slug' => 'default-options', 'title' => __('Default Option(s)', 'profilebuilder'), 'description' => __("Specify the option which should be checked by default<br/>If there are multiple values, separate them with a ',' (comma)", 'profilebuilder')), array('type' => 'select', 'slug' => 'default-option-country', 'title' => __('Default Option', 'profilebuilder'), 'options' => wppb_country_select_options('back_end'), 'description' => __("Default option of the field", 'profilebuilder')), array('type' => 'select', 'slug' => 'default-option-timezone', 'title' => __('Default Option', 'profilebuilder'), 'options' => wppb_timezone_select_options('back_end'), 'description' => __("Default option of the field", 'profilebuilder')), array('type' => 'textarea', 'slug' => 'default-content', 'title' => __('Default Content', 'profilebuilder'), 'description' => __("Default value of the textarea", 'profilebuilder')), array('type' => 'select', 'slug' => 'required', 'title' => __('Required', 'profilebuilder'), 'options' => array('No', 'Yes'), 'default' => 'No', 'description' => __('Whether the field is required or not', 'profilebuilder')), array('type' => 'select', 'slug' => 'overwrite-existing', 'title' => __('Overwrite Existing', 'profilebuilder'), '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", 'profilebuilder'))));
    // create the new submenu with the above options
    $args = array('metabox_id' => 'manage-fields', 'metabox_title' => __('Field Properties', 'profilebuilder'), 'post_type' => 'manage-fields', 'meta_name' => 'wppb_manage_fields', 'meta_array' => $fields, 'context' => 'option');
    new Wordpress_Creation_Kit_PB($args);
    wppb_prepopulate_fields();
    // create the info side meta-box
    $args = array('metabox_id' => 'manage-fields-info', 'metabox_title' => __('Registration & Edit Profile', 'profilebuilder'), 'post_type' => 'manage-fields', 'meta_name' => 'wppb_manage_fields_info', 'meta_array' => '', 'context' => 'option', 'mb_context' => 'side');
    new Wordpress_Creation_Kit_PB($args);
}
Example #3
0
function wppb_country_select_handler($output, $form_location, $field, $user_id, $field_check_errors, $request_data)
{
    if ($field['field'] == 'Select (Country)') {
        $item_title = apply_filters('wppb_' . $form_location . '_country_select_custom_field_' . $field['id'] . '_item_title', wppb_icl_t('plugin profile-builder-pro', 'custom_field_' . $field['id'] . '_title_translation', $field['field-title']));
        $item_description = wppb_icl_t('plugin profile-builder-pro', 'custom_field_' . $field['id'] . '_description_translation', $field['description']);
        $country_array = wppb_country_select_options($form_location);
        $old_country_array = array(__('Afghanistan', 'profile-builder'), __('Aland Islands', 'profile-builder'), __('Albania', 'profile-builder'), __('Algeria', 'profile-builder'), __('American Samoa', 'profile-builder'), __('Andorra', 'profile-builder'), __('Angola', 'profile-builder'), __('Anguilla', 'profile-builder'), __('Antarctica', 'profile-builder'), __('Antigua and Barbuda', 'profile-builder'), __('Argentina', 'profile-builder'), __('Armenia', 'profile-builder'), __('Aruba', 'profile-builder'), __('Australia', 'profile-builder'), __('Austria', 'profile-builder'), __('Azerbaijan', 'profile-builder'), __('Bahamas', 'profile-builder'), __('Bahrain', 'profile-builder'), __('Bangladesh', 'profile-builder'), __('Barbados', 'profile-builder'), __('Belarus', 'profile-builder'), __('Belgium', 'profile-builder'), __('Belize', 'profile-builder'), __('Benin', 'profile-builder'), __('Bermuda', 'profile-builder'), __('Bhutan', 'profile-builder'), __('Bolivia, __( Plurinational State of', 'profile-builder'), __('Bonaire, __( Sint Eustatius and Saba', 'profile-builder'), __('Bosnia and Herzegovina', 'profile-builder'), __('Botswana', 'profile-builder'), __('Bouvet Island', 'profile-builder'), __('Brazil', 'profile-builder'), __('British Indian Ocean Territory', 'profile-builder'), __('Brunei Darussalam', 'profile-builder'), __('Bulgaria', 'profile-builder'), __('Burkina Faso', 'profile-builder'), __('Burundi', 'profile-builder'), __('Cambodia', 'profile-builder'), __('Cameroon', 'profile-builder'), __('Canada', 'profile-builder'), __('Cabo Verde', 'profile-builder'), __('Cayman Islands', 'profile-builder'), __('Central African Republic', 'profile-builder'), __('Chad', 'profile-builder'), __('Chile', 'profile-builder'), __('China', 'profile-builder'), __('Christmas Island', 'profile-builder'), __('Cocos (Keeling) Islands', 'profile-builder'), __('Colombia', 'profile-builder'), __('Comoros', 'profile-builder'), __('Congo', 'profile-builder'), __('Congo, __( the Democratic Republic of the', 'profile-builder'), __('Cook Islands', 'profile-builder'), __('Costa Rica', 'profile-builder'), __('Cote dIvoire', 'profile-builder'), __('Croatia', 'profile-builder'), __('Cuba', 'profile-builder'), __('Curacao', 'profile-builder'), __('Cyprus', 'profile-builder'), __('Czech Republic', 'profile-builder'), __('Denmark', 'profile-builder'), __('Djibouti', 'profile-builder'), __('Dominica', 'profile-builder'), __('Dominican Republic', 'profile-builder'), __('Ecuador', 'profile-builder'), __('Egypt', 'profile-builder'), __('El Salvador', 'profile-builder'), __('Equatorial Guinea', 'profile-builder'), __('Eritrea', 'profile-builder'), __('Estonia', 'profile-builder'), __('Ethiopia', 'profile-builder'), __('Falkland Islands (Malvinas)', 'profile-builder'), __('Faroe Islands', 'profile-builder'), __('Fiji', 'profile-builder'), __('Finland', 'profile-builder'), __('France', 'profile-builder'), __('French Guiana', 'profile-builder'), __('French Polynesia', 'profile-builder'), __('French Southern Territories', 'profile-builder'), __('Gabon', 'profile-builder'), __('Gambia', 'profile-builder'), __('Georgia', 'profile-builder'), __('Germany', 'profile-builder'), __('Ghana', 'profile-builder'), __('Gibraltar', 'profile-builder'), __('Greece', 'profile-builder'), __('Greenland', 'profile-builder'), __('Grenada', 'profile-builder'), __('Guadeloupe', 'profile-builder'), __('Guam', 'profile-builder'), __('Guatemala', 'profile-builder'), __('Guernsey', 'profile-builder'), __('Guinea', 'profile-builder'), __('Guinea-Bissau', 'profile-builder'), __('Guyana', 'profile-builder'), __('Haiti', 'profile-builder'), __('Heard Island and McDonald Islands', 'profile-builder'), __('Holy See (Vatican City State)', 'profile-builder'), __('Honduras', 'profile-builder'), __('Hong Kong', 'profile-builder'), __('Hungary', 'profile-builder'), __('Iceland', 'profile-builder'), __('India', 'profile-builder'), __('Indonesia', 'profile-builder'), __('Iran, __( Islamic Republic of', 'profile-builder'), __('Iraq', 'profile-builder'), __('Ireland', 'profile-builder'), __('Isle of Man', 'profile-builder'), __('Israel', 'profile-builder'), __('Italy', 'profile-builder'), __('Jamaica', 'profile-builder'), __('Japan', 'profile-builder'), __('Jersey', 'profile-builder'), __('Jordan', 'profile-builder'), __('Kazakhstan', 'profile-builder'), __('Kenya', 'profile-builder'), __('Kiribati', 'profile-builder'), __('Korea, __( Democratic Peoples Republic of', 'profile-builder'), __('Korea, __( Republic of', 'profile-builder'), __('Kuwait', 'profile-builder'), __('Kyrgyzstan', 'profile-builder'), __('Lao Peoples Democratic Republic', 'profile-builder'), __('Latvia', 'profile-builder'), __('Lebanon', 'profile-builder'), __('Lesotho', 'profile-builder'), __('Liberia', 'profile-builder'), __('Libya', 'profile-builder'), __('Liechtenstein', 'profile-builder'), __('Lithuania', 'profile-builder'), __('Luxembourg', 'profile-builder'), __('Macao', 'profile-builder'), __('Macedonia, __( the former Yugoslav Republic of', 'profile-builder'), __('Madagascar', 'profile-builder'), __('Malawi', 'profile-builder'), __('Malaysia', 'profile-builder'), __('Maldives', 'profile-builder'), __('Mali', 'profile-builder'), __('Malta', 'profile-builder'), __('Marshall Islands', 'profile-builder'), __('Martinique', 'profile-builder'), __('Mauritania', 'profile-builder'), __('Mauritius', 'profile-builder'), __('Mayotte', 'profile-builder'), __('Mexico', 'profile-builder'), __('Micronesia, __( Federated States of', 'profile-builder'), __('Moldova, __( Republic of', 'profile-builder'), __('Monaco', 'profile-builder'), __('Mongolia', 'profile-builder'), __('Montenegro', 'profile-builder'), __('Montserrat', 'profile-builder'), __('Morocco', 'profile-builder'), __('Mozambique', 'profile-builder'), __('Myanmar', 'profile-builder'), __('Namibia', 'profile-builder'), __('Nauru', 'profile-builder'), __('Nepal', 'profile-builder'), __('Netherlands', 'profile-builder'), __('New Caledonia', 'profile-builder'), __('New Zealand', 'profile-builder'), __('Nicaragua', 'profile-builder'), __('Niger', 'profile-builder'), __('Nigeria', 'profile-builder'), __('Niue', 'profile-builder'), __('Norfolk Island', 'profile-builder'), __('Northern Mariana Islands', 'profile-builder'), __('Norway', 'profile-builder'), __('Oman', 'profile-builder'), __('Pakistan', 'profile-builder'), __('Palau', 'profile-builder'), __('Palestine, __( State of', 'profile-builder'), __('Panama', 'profile-builder'), __('Papua New Guinea', 'profile-builder'), __('Paraguay', 'profile-builder'), __('Peru', 'profile-builder'), __('Philippines', 'profile-builder'), __('Pitcairn', 'profile-builder'), __('Poland', 'profile-builder'), __('Portugal', 'profile-builder'), __('Puerto Rico', 'profile-builder'), __('Qatar', 'profile-builder'), __('Reunion', 'profile-builder'), __('Romania', 'profile-builder'), __('Russian Federation', 'profile-builder'), __('Rwanda', 'profile-builder'), __('Saint Barthelemy', 'profile-builder'), __('Saint Helena, __( Ascension and Tristan da Cunha', 'profile-builder'), __('Saint Kitts and Nevis', 'profile-builder'), __('Saint Lucia', 'profile-builder'), __('Saint Martin (French part)', 'profile-builder'), __('Saint Pierre and Miquelon', 'profile-builder'), __('Saint Vincent and the Grenadines', 'profile-builder'), __('Samoa', 'profile-builder'), __('San Marino', 'profile-builder'), __('Sao Tome and Principe', 'profile-builder'), __('Saudi Arabia', 'profile-builder'), __('Senegal', 'profile-builder'), __('Serbia', 'profile-builder'), __('Seychelles', 'profile-builder'), __('Sierra Leone', 'profile-builder'), __('Singapore', 'profile-builder'), __('Sint Maarten (Dutch part)', 'profile-builder'), __('Slovakia', 'profile-builder'), __('Slovenia', 'profile-builder'), __('Solomon Islands', 'profile-builder'), __('Somalia', 'profile-builder'), __('South Africa', 'profile-builder'), __('South Georgia and the South Sandwich Islands', 'profile-builder'), __('South Sudan', 'profile-builder'), __('Spain', 'profile-builder'), __('Sri Lanka', 'profile-builder'), __('Sudan', 'profile-builder'), __('Suriname', 'profile-builder'), __('Svalbard and Jan Mayen', 'profile-builder'), __('Swaziland', 'profile-builder'), __('Sweden', 'profile-builder'), __('Switzerland', 'profile-builder'), __('Syrian Arab Republic', 'profile-builder'), __('Taiwan, __( Province of China', 'profile-builder'), __('Tajikistan', 'profile-builder'), __('Tanzania, __( United Republic of', 'profile-builder'), __('Thailand', 'profile-builder'), __('Timor-Leste', 'profile-builder'), __('Togo', 'profile-builder'), __('Tokelau', 'profile-builder'), __('Tonga', 'profile-builder'), __('Trinidad and Tobago', 'profile-builder'), __('Tunisia', 'profile-builder'), __('Turkey', 'profile-builder'), __('Turkmenistan', 'profile-builder'), __('Turks and Caicos Islands', 'profile-builder'), __('Tuvalu', 'profile-builder'), __('Uganda', 'profile-builder'), __('Ukraine', 'profile-builder'), __('United Arab Emirates', 'profile-builder'), __('United Kingdom', 'profile-builder'), __('United States', 'profile-builder'), __('United States Minor Outlying Islands', 'profile-builder'), __('Uruguay', 'profile-builder'), __('Uzbekistan', 'profile-builder'), __('Vanuatu', 'profile-builder'), __('Venezuela, __( Bolivarian Republic of', 'profile-builder'), __('Viet Nam', 'profile-builder'), __('Virgin Islands, __( British', 'profile-builder'), __('Virgin Islands, __( U.S.', 'profile-builder'), __('Wallis and Futuna', 'profile-builder'), __('Western Sahara', 'profile-builder'), __('Yemen', 'profile-builder'), __('Zambia', 'profile-builder'), __('Zimbabwe', 'profile-builder'));
        $extra_attr = apply_filters('wppb_extra_attribute', '', $field);
        if ($form_location != 'register') {
            // change current user country meta_value with country ISO code
            $user_country_option = wppb_user_meta_exists($user_id, $field['meta-name']);
            if ($user_country_option != null) {
                if (in_array($user_country_option->meta_value, $old_country_array)) {
                    $country_iso = array_search($user_country_option->meta_value, $country_array);
                    update_user_meta($user_id, $field['meta-name'], $country_iso);
                }
            }
            $input_value = $user_country_option != null ? $country_array[stripslashes(get_user_meta($user_id, $field['meta-name'], true))] : $country_array[$field['default-option-country']];
        } else {
            $input_value = !empty($field['default-option-country']) ? $country_array[trim($field['default-option-country'])] : '';
        }
        $input_value = isset($request_data[wppb_handle_meta_name($field['meta-name'])]) ? $country_array[trim($request_data[wppb_handle_meta_name($field['meta-name'])])] : $input_value;
        if ($form_location != 'back_end') {
            $error_mark = $field['required'] == 'Yes' ? '<span class="wppb-required" title="' . wppb_required_field_error($field["field-title"]) . '">*</span>' : '';
            if (array_key_exists($field['id'], $field_check_errors)) {
                $error_mark = '<img src="' . WPPB_PLUGIN_URL . 'assets/images/pencil_delete.png" title="' . wppb_required_field_error($field["field-title"]) . '"/>';
            }
            $output = '
				<label for="' . $field['meta-name'] . '">' . $item_title . $error_mark . '</label>
				<select name="' . $field['meta-name'] . '" id="' . $field['meta-name'] . '" class="custom_field_country_select ' . apply_filters('wppb_fields_extra_css_class', '', $field) . '" ' . $extra_attr . '>';
            $extra_select_option = apply_filters('wppb_extra_select_option', '', $field, $item_title);
            if (!empty($extra_select_option)) {
                $output .= $extra_select_option;
                $country_array = array_filter($country_array);
            }
            foreach ($country_array as $iso => $country) {
                $output .= '<option value="' . $iso . '"';
                if ($input_value === $country) {
                    $output .= ' selected';
                }
                $output .= '>' . $country . '</option>';
            }
            $output .= '
				</select>';
            if (!empty($item_description)) {
                $output .= '<span class="wppb-description-delimiter">' . $item_description . '</span>';
            }
        } else {
            $output = '
				<table class="form-table">
					<tr>
						<th><label for="' . $field['meta-name'] . '">' . $item_title . '</label></th>
						<td>
							<select name="' . $field['meta-name'] . '" class="custom_field_country_select" id="' . $field['meta-name'] . '" ' . $extra_attr . '>';
            foreach ($country_array as $iso => $country) {
                $output .= '<option value="' . $iso . '"';
                if ($input_value === $country) {
                    $output .= ' selected';
                }
                $output .= '>' . $country . '</option>';
            }
            $output .= '</select>
							<span class="description">' . $item_description . '</span>
						</td>
					</tr>
				</table>';
        }
        return apply_filters('wppb_' . $form_location . '_country_select_custom_field_' . $field['id'], $output, $form_location, $field, $user_id, $field_check_errors, $request_data, $input_value);
    }
}