[buddypress-trac] [BuddyPress Trac] #6924: Allow 'description' to be saved for xprofile field options
buddypress-trac
noreply at wordpress.org
Tue Feb 23 17:19:49 UTC 2016
#6924: Allow 'description' to be saved for xprofile field options
----------------------------------+-----------------------------
Reporter: locomo | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Component - XProfile | Version: 2.4.0
Severity: normal | Keywords:
----------------------------------+-----------------------------
I'd like to be able to save a description for select field options. I will
use the description as the option text and will continue to use name as
the option value. I'm adding the description values programmatically so my
proposed changed below doesn't require any changes to the xprofile user
interface (although that would be a nice additional enhancement)
my use case is that id like to be able to render selection options that
look like this
{{{
<option value="blar">The Blar</option>
}}}
as it currently stands we are limited in that key/values for options must
be the same based on the name field, ie either
{{{
<option value="The Blar">The Blar</option>
<option value="blar">blar</option>
}}}
i'm proposing a small change in 'class-bp-xprofile-field.php' >> 'public
function save()' >> ~line 467
change:
{{{
$sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields}
(group_id, parent_id, type, name, description, is_required, option_order,
is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)",
$this->group_id, $parent_id, $option_value, $counter, $is_default );
}}}
to: (basically, allow the value of description to be passed thru rather
than forced to be empty)
{{{
$sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields}
(group_id, parent_id, type, name, description, is_required, option_order,
is_default_option) VALUES (%d, %d, 'option', %s, %s, 0, %d, %d)",
$this->group_id, $parent_id, $option_value, $counter, $is_default );
}}}
then i can use the filter 'bp_get_the_profile_field_options_select' to
dynamically render my options like this
{{{
$html = '<option' . $selected . ' value="' . esc_attr( stripslashes(
$option->name ) ) . '">' . esc_html( stripslashes( $option->name . ' - ' .
$option->description ) ) . '</option>';
}}}
if this change is amenable, i'm up for taking a stab at a change to the
user interface that would allow key => value (name, description) to be
saved for field options
i was thinking something along the lines of filtering the option field for
a structure like 'blar:The Blar' and storing those into name:description
...
or we could simply provide an optional 2nd field for each option
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6924>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list