/** * Enqueue the jQuery libraries for handling drag/drop/sort. * * @since 1.5.0 */ function xprofile_add_admin_js() { if (!empty($_GET['page']) && strpos($_GET['page'], 'bp-profile-setup') !== false) { wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_script('jquery-ui-mouse'); wp_enqueue_script('jquery-ui-draggable'); wp_enqueue_script('jquery-ui-droppable'); wp_enqueue_script('jquery-ui-sortable'); $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('xprofile-admin-js', buddypress()->plugin_url . "bp-xprofile/admin/js/admin{$min}.js", array('jquery', 'jquery-ui-sortable'), bp_get_version()); // Localize strings. // supports_options_field_types is a dynamic list of field // types that support options, for use in showing/hiding the // "please enter options for this field" section. $strings = array('supports_options_field_types' => array()); foreach (bp_xprofile_get_field_types() as $field_type => $field_type_class) { $field = new $field_type_class(); if ($field->supports_options) { $strings['supports_options_field_types'][] = $field_type; } } wp_localize_script('xprofile-admin-js', 'XProfileAdmin', $strings); } }
/** * Setup globals * * The BP_XPROFILE_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since BuddyPress (1.5) */ public function setup_globals($args = array()) { $bp = buddypress(); // Define a slug, if necessary if (!defined('BP_XPROFILE_SLUG')) { define('BP_XPROFILE_SLUG', 'profile'); } // Assign the base group and fullname field names to constants // to use in SQL statements. // Defined conditionally to accommodate unit tests if (!defined('BP_XPROFILE_BASE_GROUP_NAME')) { define('BP_XPROFILE_BASE_GROUP_NAME', stripslashes($bp->site_options['bp-xprofile-base-group-name'])); } if (!defined('BP_XPROFILE_FULLNAME_FIELD_NAME')) { define('BP_XPROFILE_FULLNAME_FIELD_NAME', stripslashes($bp->site_options['bp-xprofile-fullname-field-name'])); } // Set the support field type ids $this->field_types = apply_filters('xprofile_field_types', array_keys(bp_xprofile_get_field_types())); // 'option' is a special case. It is not a top-level field, so // does not have an associated BP_XProfile_Field_Type class, // but it must be whitelisted $this->field_types[] = 'option'; // Register the visibility levels. See bp_xprofile_get_visibility_levels() to filter $this->visibility_levels = array('public' => array('id' => 'public', 'label' => _x('Everyone', 'Visibility level setting', 'buddypress')), 'adminsonly' => array('id' => 'adminsonly', 'label' => _x('Only Me', 'Visibility level setting', 'buddypress')), 'loggedin' => array('id' => 'loggedin', 'label' => _x('All Members', 'Visibility level setting', 'buddypress'))); if (bp_is_active('friends')) { $this->visibility_levels['friends'] = array('id' => 'friends', 'label' => _x('My Friends', 'Visibility level setting', 'buddypress')); } // Tables $global_tables = array('table_name_data' => $bp->table_prefix . 'bp_xprofile_data', 'table_name_groups' => $bp->table_prefix . 'bp_xprofile_groups', 'table_name_fields' => $bp->table_prefix . 'bp_xprofile_fields', 'table_name_meta' => $bp->table_prefix . 'bp_xprofile_meta'); $meta_tables = array('xprofile_group' => $bp->table_prefix . 'bp_xprofile_meta', 'xprofile_field' => $bp->table_prefix . 'bp_xprofile_meta', 'xprofile_data' => $bp->table_prefix . 'bp_xprofile_meta'); $globals = array('slug' => BP_XPROFILE_SLUG, 'has_directory' => false, 'notification_callback' => 'xprofile_format_notifications', 'global_tables' => $global_tables, 'meta_tables' => $meta_tables); parent::setup_globals($globals); }
/** * Enqueue the jQuery libraries for handling drag/drop/sort. * * @since 1.5.0 */ function xprofile_add_admin_js() { if (!empty($_GET['page']) && strpos($_GET['page'], 'bp-profile-setup') !== false) { wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_script('jquery-ui-mouse'); wp_enqueue_script('jquery-ui-draggable'); wp_enqueue_script('jquery-ui-droppable'); wp_enqueue_script('jquery-ui-sortable'); $min = bp_core_get_minified_asset_suffix(); wp_enqueue_script('xprofile-admin-js', buddypress()->plugin_url . "bp-xprofile/admin/js/admin{$min}.js", array('jquery', 'jquery-ui-sortable'), bp_get_version()); // Localize strings. // supports_options_field_types is a dynamic list of field // types that support options, for use in showing/hiding the // "please enter options for this field" section. $strings = array('do_settings_section_field_types' => array(), 'do_autolink' => ''); foreach (bp_xprofile_get_field_types() as $field_type => $field_type_class) { $field = new $field_type_class(); if ($field->do_settings_section()) { $strings['do_settings_section_field_types'][] = $field_type; } } // Load 'autolink' setting into JS so that we can provide smart defaults when switching field type. if (!empty($_GET['field_id'])) { $field_id = intval($_GET['field_id']); // Pull the raw data from the DB so we can tell whether the admin has saved a value yet. $strings['do_autolink'] = bp_xprofile_get_meta($field_id, 'field', 'do_autolink'); } wp_localize_script('xprofile-admin-js', 'XProfileAdmin', $strings); } }
/** * Creates the specified field type object; used for validation and templating. * * @param string $type Type of profile field to create. See {@link bp_xprofile_get_field_types()} for default core values. * @return object If field type unknown, returns BP_XProfile_Field_Type_Textarea. Otherwise returns an instance of the relevant child class of BP_XProfile_Field_Type. * @since BuddyPress (2.0.0) */ function bp_xprofile_create_field_type($type) { $field = bp_xprofile_get_field_types(); $class = isset($field[$type]) ? $field[$type] : ''; /** * To handle (missing) field types, fallback to a placeholder field object if a type is unknown. */ if ($class && class_exists($class)) { return new $class(); } else { return new BP_XProfile_Field_Type_Placeholder(); } }
/** * Output HTML for this field type's children options on the wp-admin Profile Fields "Add Field" and "Edit Field" screens. * * You don't need to implement this method for all field types. It's used in core by the * selectbox, multi selectbox, checkbox, and radio button fields, to allow the admin to * enter the child option values (e.g. the choices in a select box). * * Must be used inside the {@link bp_profile_fields()} template loop. * * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. * @param string $control_type Optional. HTML input type used to render the current field's child options. * @since BuddyPress (2.0.0) */ public function admin_new_field_html(BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Please enter options for this Field:', 'buddypress'); ?> </h3> <div class="inside"> <p> <label for="sort_order_<?php echo esc_attr($type); ?> "><?php esc_html_e('Sort Order:', 'buddypress'); ?> </label> <select name="sort_order_<?php echo esc_attr($type); ?> " id="sort_order_<?php echo esc_attr($type); ?> " > <option value="custom" <?php selected('custom', $current_field->order_by); ?> ><?php esc_html_e('Custom', 'buddypress'); ?> </option> <option value="asc" <?php selected('asc', $current_field->order_by); ?> ><?php esc_html_e('Ascending', 'buddypress'); ?> </option> <option value="desc" <?php selected('desc', $current_field->order_by); ?> ><?php esc_html_e('Descending', 'buddypress'); ?> </option> </select> </p> <?php $options = $current_field->get_children(true); // If no children options exists for this field, check in $_POST for a submitted form (e.g. on the "new field" screen). if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { // Multiselectbox and checkboxes support MULTIPLE default options; all other core types support only ONE. if ($current_type_obj->supports_options && !$current_type_obj->supports_multiple_defaults && isset($_POST["isDefault_{$type}_option"][$i]) && (int) $_POST["isDefault_{$type}_option"] === $i) { $is_default_option = true; } elseif (isset($_POST["isDefault_{$type}_option"][$i])) { $is_default_option = (bool) $_POST["isDefault_{$type}_option"][$i]; } else { $is_default_option = false; } // Grab the values from $_POST to use as the form's options $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } // If there are still no children options set, this must be the "new field" screen, so add one new/empty option. if (!$options) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => ''); } } // Render the markup for the children options if (!empty($options)) { $default_name = ''; for ($i = 0, $count = count($options); $i < $count; ++$i) { $j = $i + 1; // Multiselectbox and checkboxes support MULTIPLE default options; all other core types support only ONE. if ($current_type_obj->supports_options && $current_type_obj->supports_multiple_defaults) { $default_name = '[' . $j . ']'; } ?> <p class="sortable"> <span> Ξ </span> <input type="text" name="<?php echo esc_attr("{$type}_option[{$j}]"); ?> " id="<?php echo esc_attr("{$type}_option{$j}"); ?> " value="<?php echo esc_attr(stripslashes($options[$i]->name)); ?> " /> <input type="<?php echo esc_attr($control_type); ?> " name="<?php echo esc_attr("isDefault_{$type}_option{$default_name}"); ?> " <?php checked($options[$i]->is_default_option, true); ?> value="<?php echo esc_attr($j); ?> " /> <span><?php _e('Default Value', 'buddypress'); ?> </span> <?php if (1 <= $i) { ?> <a href="<?php echo esc_url('users.php?page=bp-profile-setup&mode=delete_option&option_id=' . $options[$i]->id); ?> " class="ajax-option-delete" id="delete-<?php echo esc_attr($options[$i]->id); ?> ">[x]</a> <?php } ?> </p> <?php } ?> <input type="hidden" name="<?php echo esc_attr("{$type}_option_number"); ?> " id="<?php echo esc_attr("{$type}_option_number"); ?> " value="<?php echo esc_attr($j + 1); ?> " /> <?php } ?> <div id="<?php echo esc_attr("{$type}_more"); ?> "></div> <p><a href="javascript:add_option('<?php echo esc_js($type); ?> ')"><?php esc_html_e('Add Another Option', 'buddypress'); ?> </a></p> </div> </div> <?php }
/** * Apply display_filter() filters as defined by BP_XProfile_Field_Type classes, when inside a bp_has_profile() loop. * * @since 2.1.0 * @since 2.4.0 Added `$field_id` parameter. * * @param mixed $field_value Field value. * @param string $field_type Field type. * @param string|int $field_id Optional. ID of the field. * * @return mixed */ function xprofile_filter_format_field_value_by_type($field_value, $field_type = '', $field_id = '') { foreach (bp_xprofile_get_field_types() as $type => $class) { if ($type !== $field_type) { continue; } if (method_exists($class, 'display_filter')) { $field_value = call_user_func(array($class, 'display_filter'), $field_value, $field_id); } } return $field_value; }
public function admin_new_field_html(\BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); $options = $current_field->get_children(true); if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { if ($current_type_obj->supports_options && !$current_type_obj->supports_multiple_defaults && isset($_POST["isDefault_{$type}_option"][$i]) && (int) $_POST["isDefault_{$type}_option"] === $i) { $is_default_option = true; } elseif (isset($_POST["isDefault_{$type}_option"][$i])) { $is_default_option = (bool) $_POST["isDefault_{$type}_option"][$i]; } else { $is_default_option = false; } $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } if (!$options) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => ''); } } $taxonomies = get_taxonomies(array('public' => true, '_builtin' => false)); ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <?php if (!$taxonomies) { ?> <h3><?php _e('There is no custom taxonomy. You need to create at least one to use this field.', 'bxcft'); ?> </h3> <?php } else { ?> <h3><?php esc_html_e('Select a custom taxonomy:', 'bxcft'); ?> </h3> <div class="inside"> <p> <?php _e('Select a custom taxonomy:', 'bxcft'); ?> <select name="<?php echo esc_attr("{$type}_option[1]"); ?> " id="<?php echo esc_attr("{$type}_option[1]"); ?> "> <option value=""><?php _e('Select...', 'bxcft'); ?> </option> <?php foreach ($taxonomies as $k => $v) { ?> <option value="<?php echo $k; ?> "<?php if ($options[0]->name == $k) { ?> selected="selected"<?php } ?> ><?php echo $v; ?> </option> <?php } ?> </select> </p> </div> <?php } ?> </div> <?php }
/** * Print <option> elements containing the xprofile field types. * * @param string $select_field_type The name of the field type that should be selected. Will defaults to "textbox" if NULL is passed. * @since BuddyPress (2.0.0) */ function bp_xprofile_admin_form_field_types($select_field_type) { $categories = array(); if (is_null($select_field_type)) { $select_field_type = 'textbox'; } // Sort each field type into its category foreach (bp_xprofile_get_field_types() as $field_name => $field_class) { $field_type_obj = new $field_class(); $the_category = $field_type_obj->category; // Fallback to a catch-all if category not set if (!$the_category) { $the_category = _x('Other', 'xprofile field type category', 'buddypress'); } if (isset($categories[$the_category])) { $categories[$the_category][] = array($field_name, $field_type_obj); } else { $categories[$the_category] = array(array($field_name, $field_type_obj)); } } // Sort the categories alphabetically. ksort()'s SORT_NATURAL is only in PHP >= 5.4 :(( uksort($categories, 'strnatcmp'); // Loop through each category and output form <options> foreach ($categories as $category => $fields) { printf('<optgroup label="%1$s">', esc_attr($category)); // Already i18n'd in each profile type class // Sort these fields types alphabetically uasort($fields, create_function('$a, $b', 'return strnatcmp( $a[1]->name, $b[1]->name );')); foreach ($fields as $field_type_obj) { $field_name = $field_type_obj[0]; $field_type_obj = $field_type_obj[1]; printf('<option value="%1$s" %2$s>%3$s</option>', esc_attr($field_name), selected($select_field_type, $field_name, false), esc_html($field_type_obj->name)); } printf('</optgroup>'); } }
/** * Output HTML for this field type's children options on the wp-admin Profile Fields "Add Field" and "Edit Field" screens. * * You don't need to implement this method for all field types. It's used in core by the * selectbox, multi selectbox, checkbox, and radio button fields, to allow the admin to * enter the child option values (e.g. the choices in a select box). * * Must be used inside the {@link bp_profile_fields()} template loop. * * @since 2.0.0 * * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. * @param string $control_type Optional. HTML input type used to render the current * field's child options. */ public function admin_new_field_html(BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Please enter options for this Field:', 'buddypress'); ?> </h3> <div class="inside" aria-live="polite" aria-atomic="true" aria-relevant="all"> <p> <label for="sort_order_<?php echo esc_attr($type); ?> "><?php esc_html_e('Sort Order:', 'buddypress'); ?> </label> <select name="sort_order_<?php echo esc_attr($type); ?> " id="sort_order_<?php echo esc_attr($type); ?> " > <option value="custom" <?php selected('custom', $current_field->order_by); ?> ><?php esc_html_e('Custom', 'buddypress'); ?> </option> <option value="asc" <?php selected('asc', $current_field->order_by); ?> ><?php esc_html_e('Ascending', 'buddypress'); ?> </option> <option value="desc" <?php selected('desc', $current_field->order_by); ?> ><?php esc_html_e('Descending', 'buddypress'); ?> </option> </select> </p> <?php // Does option have children? $options = $current_field->get_children(true); // If no children options exists for this field, check in $_POST // for a submitted form (e.g. on the "new field" screen). if (empty($options)) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { // Multiselectbox and checkboxes support MULTIPLE default options; all other core types support only ONE. if ($current_type_obj->supports_options && !$current_type_obj->supports_multiple_defaults && isset($_POST["isDefault_{$type}_option"][$i]) && (int) $_POST["isDefault_{$type}_option"] === $i) { $is_default_option = true; } elseif (isset($_POST["isDefault_{$type}_option"][$i])) { $is_default_option = (bool) $_POST["isDefault_{$type}_option"][$i]; } else { $is_default_option = false; } // Grab the values from $_POST to use as the form's options. $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } // If there are still no children options set, this must be the "new field" screen, so add one new/empty option. if (empty($options)) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => ''); } } // Render the markup for the children options. if (!empty($options)) { $default_name = ''; for ($i = 0, $count = count($options); $i < $count; ++$i) { $j = $i + 1; // Multiselectbox and checkboxes support MULTIPLE default options; all other core types support only ONE. if ($current_type_obj->supports_options && $current_type_obj->supports_multiple_defaults) { $default_name = '[' . $j . ']'; } ?> <div id="<?php echo esc_attr("{$type}_div{$j}"); ?> " class="bp-option sortable"> <span class="bp-option-icon grabber"></span> <label for="<?php echo esc_attr("{$type}_option{$j}"); ?> " class="screen-reader-text"><?php /* translators: accessibility text */ esc_html_e('Add an option', 'buddypress'); ?> </label> <input type="text" name="<?php echo esc_attr("{$type}_option[{$j}]"); ?> " id="<?php echo esc_attr("{$type}_option{$j}"); ?> " value="<?php echo esc_attr(stripslashes($options[$i]->name)); ?> " /> <label for="<?php echo esc_attr("{$type}_option{$default_name}"); ?> "> <input type="<?php echo esc_attr($control_type); ?> " id="<?php echo esc_attr("{$type}_option{$default_name}"); ?> " name="<?php echo esc_attr("isDefault_{$type}_option{$default_name}"); ?> " <?php checked($options[$i]->is_default_option, true); ?> value="<?php echo esc_attr($j); ?> " /> <?php _e('Default Value', 'buddypress'); ?> </label> <?php if (1 !== $j) { ?> <div class ="delete-button"> <a href='javascript:hide("<?php echo esc_attr("{$type}_div{$j}"); ?> ")' class="delete"><?php esc_html_e('Delete', 'buddypress'); ?> </a> </div> <?php } ?> </div> <?php } ?> <input type="hidden" name="<?php echo esc_attr("{$type}_option_number"); ?> " id="<?php echo esc_attr("{$type}_option_number"); ?> " value="<?php echo esc_attr($j + 1); ?> " /> <?php } ?> <div id="<?php echo esc_attr("{$type}_more"); ?> "></div> <p><a href="javascript:add_option('<?php echo esc_js($type); ?> ')"><?php esc_html_e('Add Another Option', 'buddypress'); ?> </a></p> <?php /** * Fires at the end of the new field additional settings area. * * @since 2.3.0 * * @param BP_XProfile_Field $current_field Current field being rendered. */ do_action('bp_xprofile_admin_new_field_additional_settings', $current_field); ?> </div> </div> <?php }
public function admin_new_field_html(\BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); $options = $current_field->get_children(true); if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { $is_default_option = true; $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } if (!$options) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => '2'); } } ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Select max number of decimals:', 'bxcft'); ?> </h3> <div class="inside"> <p> <select name="<?php echo esc_attr("{$type}_option[1]"); ?> " id="<?php echo esc_attr("{$type}_option1"); ?> "> <?php for ($j = 1; $j <= 6; $j++) { ?> <option value="<?php echo $j; ?> "<?php if ($j === (int) $options[0]->name) { ?> selected="selected"<?php } ?> ><?php echo $j; ?> </option> <?php } ?> </select> </p> </div> </div> <?php }
/** * This function populates the items for radio buttons checkboxes and drop * down boxes. */ public function render_admin_form_children() { foreach (array_keys(bp_xprofile_get_field_types()) as $field_type) { $type_obj = bp_xprofile_create_field_type($field_type); $type_obj->admin_new_field_html($this); } }
public function admin_new_field_html(\BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); $options = $current_field->get_children(true); $min = ''; $max = ''; if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { $is_default_option = true; $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } if (!$options) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => '2'); } } else { foreach ($options as $o) { if (strpos($o->name, 'min_') !== false) { $min = str_replace('min_', '', $o->name); } if (strpos($o->name, 'max_') !== false) { $max = str_replace('max_', '', $o->name); } } } ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Write min and max values. You can leave any field blank if you want.', 'bxcft'); ?> </h3> <div class="inside"> <p> <label for="<?php echo esc_attr("{$type}_option1"); ?> "> <?php esc_html_e('Minimum:', 'bxcft'); ?> </label> <input type="text" name="<?php echo esc_attr("{$type}_option[1]"); ?> " id="<?php echo esc_attr("{$type}_option1"); ?> " value="<?php echo $min; ?> " /> <label for="<?php echo esc_attr("{$type}_option2"); ?> "> <?php esc_html_e('Maximum:', 'bxcft'); ?> </label> <input type="text" name="<?php echo esc_attr("{$type}_option[2]"); ?> " id="<?php echo esc_attr("{$type}_option2"); ?> " value="<?php echo $max; ?> " /> </p> </div> </div> <script> var error_msg_number_minmax = '<?php esc_html_e("Min value cannot be bigger than max value.", "bxcft"); ?> ', error_msg_number_minmax_empty = '<?php esc_html_e("You have to fill at least one field.", "bxcft"); ?> '; </script> <?php }
public function admin_new_field_html(\BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); $text = ''; $options = $current_field->get_children(true); if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { if ($current_type_obj->supports_options && !$current_type_obj->supports_multiple_defaults && isset($_POST["isDefault_{$type}_option"][$i]) && (int) $_POST["isDefault_{$type}_option"] === $i) { $is_default_option = true; } elseif (isset($_POST["isDefault_{$type}_option"][$i])) { $is_default_option = (bool) $_POST["isDefault_{$type}_option"][$i]; } else { $is_default_option = false; } $options[] = (object) array('id' => 0, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); $text .= sanitize_text_field(stripslashes($_POST[$type . '_option'][$i])); ++$i; } if (!$options) { $options[] = (object) array('id' => 0, 'is_default_option' => false, 'name' => ''); } } else { foreach ($options as $option) { $text .= rawurldecode($option->name); } } ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Use this field to write a text that should be displayed beside the checkbox:', 'bxcft'); ?> </h3> <div class="inside"> <p> <textarea name="<?php echo esc_attr("{$type}_text"); ?> " id="<?php echo esc_attr("{$type}_text"); ?> " rows="5" cols="60"><?php echo $text; ?> </textarea> </p> </div> <?php if ($options) { $i = 1; ?> <?php foreach ($options as $option) { ?> <input type="hidden" name="<?php echo esc_attr("{$type}_option[{$i}]"); ?> " id ="<?php echo esc_attr("{$type}_option{$i}"); ?> " value="<?php echo $option->name; ?> " /> <?php $i++; } ?> <?php } ?> </div> <?php }
/** * If the current field is a Member type, add a new UI to set options description * * @param BP_XProfile_Field $current_field * @param string $control_type */ public function admin_new_field_html(BP_XProfile_Field $current_field, $control_type = '') { parent::admin_new_field_html($current_field, 'radio'); $type = array_search(get_class($this), bp_xprofile_get_field_types()); if ($current_field->type != $type) { return; } ?> <div id="member_types_description" class="postbox bp-options-box" style="margin-top: 15px;"> <h3><?php esc_html_e('Enter a description for each member type if needed', 'buddypress-group-restrictions'); ?> </h3> <div class="inside"> <?php // Get the existing options ? $options = $current_field->get_children(true); if (empty($options)) { ?> <p class="description"><?php esc_html_e('This part is not dynamic, you need to first save the options above before being able to describe them.', 'buddypress-group-restrictions'); ?> </p> <?php } else { foreach ($options as $option) { ?> <div class="bp-option"> <label style="display:block;font-weight:bold"> <?php printf(__('Description for %s', 'buddypress-group-restrictions'), esc_html($option->name)); ?> </label> <textarea style="width:95%" name="_cfbgr_option_description[<?php echo esc_attr($option->name); ?> ]"><?php echo esc_textarea($option->description); ?> </textarea> </div> <?php } } ?> </div> </div> <?php }
public function admin_new_field_html(\BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); $options = $current_field->get_children(true); if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { $is_default_option = true; $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } if (!$options) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => ''); } } ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Show age (hide birthdate):', 'bxcft'); ?> </h3> <div class="inside"> <p> <?php _e('Check this if you want to show age instead of birthdate:', 'bxcft'); ?> <input type="hidden" name="<?php echo esc_attr("{$type}_option[0]"); ?> " id="<?php echo esc_attr("{$type}_option0"); ?> " value="show_birthdate" /> <input type="checkbox" name="<?php echo esc_attr("{$type}_option[1]"); ?> " id="<?php echo esc_attr("{$type}_option1"); ?> " value="show_age" <?php if ($options[0]->name == 'show_age') { ?> checked="checked"<?php } ?> /> </p> </div> </div> <?php }
/** * Generate the settings markup for Date fields. * * @since 2.7.0 * * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. * @param string $control_type Optional. HTML input type used to render the current * field's child options. */ public function admin_new_field_html(BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $settings = self::get_field_settings($current_field->id); ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <table class="form-table bp-date-options"> <tr> <th scope="row"> <?php esc_html_e('Date format', 'buddypress'); ?> </th> <td> <fieldset> <legend class="screen-reader-text"> <?php esc_html_e('Date format', 'buddypress'); ?> </legend> <?php foreach ($this->get_date_formats() as $format) { ?> <div class="bp-date-format-option"> <label for="date-format-<?php echo esc_attr($format); ?> "> <input type="radio" name="field-settings[date_format]" id="date-format-<?php echo esc_attr($format); ?> " value="<?php echo esc_attr($format); ?> " <?php checked($format, $settings['date_format']); ?> /> <span class="date-format-label"><?php echo date_i18n($format); ?> </span> <code><?php echo esc_html($format); ?> </code> </label> </div> <?php } ?> <div class="bp-date-format-option"> <label for="date-format-elapsed"> <input type="radio" name="field-settings[date_format]" id="date-format-elapsed" <?php checked('elapsed', $settings['date_format']); ?> value="elapsed" aria-describedby="date-format-elapsed-setting" /> <span class="date-format-label" id="date-format-elapsed-setting"><?php esc_html_e('Time elapsed', 'buddypress'); ?> </span> <?php _e('<code>4 years ago</code>, <code>4 years from now</code>', 'buddypress'); ?> </label> </div> <div class="bp-date-format-option"> <label for="date-format-custom"> <input type="radio" name="field-settings[date_format]" id="date-format-custom" <?php checked('custom', $settings['date_format']); ?> value="custom" /> <span class="date-format-label"><?php esc_html_e('Custom:', 'buddypress'); ?> </span> </label> <label for="date-format-custom-value" class="screen-reader-text"><?php esc_html_e('Enter custom time format', 'buddypress'); ?> </label> <input type="text" name="field-settings[date_format_custom]" id="date-format-custom-value" class="date-format-custom-value" value="<?php echo esc_attr($settings['date_format_custom']); ?> " aria-describedby="date-format-custom-example" /> <span class="screen-reader-text"><?php esc_html_e('Example:', 'buddypress'); ?> </span><span class="date-format-custom-example" id="date-format-custom-sample"><?php if ($settings['date_format_custom']) { echo esc_html(date($settings['date_format_custom'])); } ?> </span><span class="spinner" id="date-format-custom-spinner" aria-hidden="true"></span> <p><a href="https://codex.wordpress.org/Formatting_Date_and_Time"><?php esc_html_e('Documentation on date and time formatting', 'buddypress'); ?> </a></p> </div> </fieldset> </td> </tr> <tr> <th scope="row"> <?php esc_html_e('Range', 'buddypress'); ?> </th> <td> <fieldset class="bp-range-types"> <legend class="screen-reader-text"> <?php esc_html_e('Range', 'buddypress'); ?> </legend> <div class="bp-date-format-option"> <div class="bp-date-range-type-label"> <label for="range_type_absolute"> <input type="radio" name="field-settings[range_type]" id="range_type_absolute" value="absolute" <?php checked('absolute', $settings['range_type']); ?> /> <?php esc_html_e('Absolute', 'buddypress'); ?> </label> </div> <div class="bp-date-range-type-values"> <label for="field-settings[range_absolute_start]" aria-label="Year"><?php esc_html_e('Start:', 'buddypress'); ?> </label> <?php printf('<input class="date-range-numeric" type="text" name="field-settings[range_absolute_start]" id="field-settings[range_absolute_start]" value="%s" />', esc_attr($settings['range_absolute_start'])); ?> <label for="field-settings[range_absolute_end]" aria-label="Year"><?php esc_html_e('End:', 'buddypress'); ?> </label> <?php printf('<input class="date-range-numeric" type="text" name="field-settings[range_absolute_end]" id="field-settings[range_absolute_end]" value="%s" />', esc_attr($settings['range_absolute_end'])); ?> </div> </div> <div class="bp-date-format-option"> <div class="bp-date-range-type-label"> <label for="range_type_relative"> <input type="radio" name="field-settings[range_type]" id="range_type_relative" value="relative" <?php checked('relative', $settings['range_type']); ?> /> <?php esc_html_e('Relative', 'buddypress'); ?> </label> </div> <div class="bp-date-range-type-values"> <label for="field-settings[range_relative_start]"><?php esc_html_e('Start:', 'buddypress'); ?> </label> <?php printf('<input type="text" class="date-range-numeric" name="field-settings[range_relative_start]" id="field-settings[range_relative_start]" value="%s" />', esc_attr(abs($settings['range_relative_start']))); ?> <label class="screen-reader-text" for="field-settings[range_relative_start_type]"><?php esc_html_e('Select range', 'buddypress'); ?> </label> <?php printf('<select name="field-settings[range_relative_start_type]" id="field-settings[range_relative_start_type]"><option value="past" %s>%s</option><option value="future" %s>%s</option></select>', selected(true, $settings['range_relative_start'] <= 0, false), esc_attr__('years ago', 'buddypress'), selected(true, $settings['range_relative_start'] > 0, false), esc_attr__('years from now', 'buddypress')); ?> <label for="field-settings[range_relative_end]"><?php esc_html_e('End:', 'buddypress'); ?> </label> <?php printf('<input type="text" class="date-range-numeric" name="field-settings[range_relative_end]" id="field-settings[range_relative_end]" value="%s" />', esc_attr(abs($settings['range_relative_end']))); ?> <label class="screen-reader-text" for="field-settings[range_relative_end_type]"><?php esc_html_e('Select range', 'buddypress'); ?> </label> <?php printf('<select name="field-settings[range_relative_end_type]" id="field-settings[range_relative_end_type]"><option value="past" %s>%s</option><option value="future" %s>%s</option></select>', selected(true, $settings['range_relative_end'] <= 0, false), esc_attr__('years ago', 'buddypress'), selected(true, $settings['range_relative_end'] > 0, false), esc_attr__('years from now', 'buddypress')); ?> </div> </div> </fieldset> </td> </tr> </table> </div> <?php }