Skip to:
Content

BuddyPress.org

Opened 9 years ago

Closed 7 years ago

#6924 closed enhancement (maybelater)

Allow 'description' to be saved for xprofile field options

Reported by: locomo's profile locomo Owned by:
Milestone: Priority: normal
Severity: normal Version: 1.0
Component: Extended Profile Keywords: trac-tidy-2018
Cc:

Description

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

Change History (8)

#1 @locomo
9 years ago

oops $sql should be changed to this:

$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, $this->description, $counter, $is_default );

#2 @locomo
9 years ago

Sorry .. i went down the rabbit hole a bit with this and I don't think what I proposed is going to work without a number of additional changes.

At the end of the day I'm trying to have some more flexibility with the display of options on the front end. I'd like to store a value (say a country code) but display more user friendly text (i.e. a country name).

Any suggestions? Should I be using the xprofile_meta table for this?

Last edited 9 years ago by locomo (previous) (diff)

#3 @r-a-y
9 years ago

  • Keywords good-first-bug added
  • Milestone changed from Awaiting Review to Under Consideration
  • Version changed from 2.4.0 to 1.0

Sounds like a good enhancement!

I think using the description column sounds like a good idea for this.

or we could simply provide an optional 2nd field for each option

The value:description syntax seems too technical for me.

So the second field option sounds like the right way to go. Perhaps make this a toggleable field so it isn't shown at first to avoid cluttering up the UI. Could use some other feedback from UI mavens, @hnla and @mercime, as well.

If you feel comfortable tackling this, we can look to include this in BP 2.6. We'll help you along the way if you need any help.

#4 @DJPaul
8 years ago

  • Milestone changed from Under Consideration to Awaiting Review

#5 @DJPaul
8 years ago

  • Milestone changed from Awaiting Review to Future Release

Good idea!

#6 @DJPaul
8 years ago

  • Keywords good-first-bug removed

#7 @DJPaul
7 years ago

  • Keywords trac-tidy-2018 added

We're closing this ticket because it has not received any contribution or comments for at least two years. We have decided that it is better to close tickets that are good ideas, which have not gotten (or are unlikely to get) contributions, rather than keep things open indefinitely. This will help us share a more realistic roadmap for BuddyPress with you.

Everyone very much appreciates the time and effort that you spent sharing your idea with us. On behalf of the entire BuddyPress team, thank you.

If you feel strongly that this enhancement should still be added to BuddyPress, and you are able to contribute effort towards it, we encourage you to re-open the ticket, or start a discussion about it in our Slack channel. Please consider that time has proven that good ideas without contributions do not get built.

For more information, see https://bpdevel.wordpress.com/2018/01/21/our-awaiting-contributions-milestone-contains/
or find us on Slack, in the #buddypress channel: https://make.wordpress.org/chat/

#8 @DJPaul
7 years ago

  • Milestone Awaiting Contributions deleted
  • Resolution set to maybelater
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.