コード例 #1
0
function wppb_timezone_select_handler($output, $form_location, $field, $user_id, $field_check_errors, $request_data)
{
    if ($field['field'] == 'Select (Timezone)') {
        $item_title = apply_filters('wppb_' . $form_location . '_timezone_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']);
        $timezone_array = wppb_timezone_select_options($form_location);
        $extra_attr = apply_filters('wppb_extra_attribute', '', $field);
        if ($form_location != 'register') {
            $input_value = wppb_user_meta_exists($user_id, $field['meta-name']) != null ? stripslashes(get_user_meta($user_id, $field['meta-name'], true)) : $field['default-option-timezone'];
        } else {
            $input_value = !empty($field['default-option-timezone']) ? trim($field['default-option-timezone']) : '';
        }
        $input_value = isset($request_data[wppb_handle_meta_name($field['meta-name'])]) ? 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_timezone_select ' . apply_filters('wppb_fields_extra_css_class', '', $field) . '" ' . $extra_attr . '>';
            foreach ($timezone_array as $timezone) {
                $output .= '<option value="' . $timezone . '"';
                if ($input_value === $timezone) {
                    $output .= ' selected';
                }
                $output .= '>' . $timezone . '</option>';
            }
            $output .= '
				</select>';
            if (!empty($item_description)) {
                $output .= '<span class="wppb-description-delimiter">' . $item_description . '</span>';
            }
        } else {
            $item_title = $field['required'] == 'Yes' ? $item_title . ' <span class="description">(' . __('required', 'profile-builder') . ')</span>' : $item_title;
            $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_timezone_select" id="' . $field['meta-name'] . '" ' . $extra_attr . '>';
            foreach ($timezone_array as $timezone) {
                $output .= '<option value="' . $timezone . '"';
                if ($input_value === $timezone) {
                    $output .= ' selected';
                }
                $output .= '>' . $timezone . '</option>';
            }
            $output .= '</select>
							<span class="description">' . $item_description . '</span>
						</td>
					</tr>
				</table>';
        }
        return apply_filters('wppb_' . $form_location . '_timezone_select_custom_field_' . $field['id'], $output, $form_location, $field, $user_id, $field_check_errors, $request_data, $input_value);
    }
}
コード例 #2
0
/**
 * 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);
}