Opened 10 years ago
Closed 10 years ago
#6272 closed enhancement (fixed)
Add new hook admin_new_field_html_additional_options to allows plugin authors to add options to multi fields without the need to replicate the code
Reported by: | svenl77 | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 2.3 | Priority: | normal |
Severity: | normal | Version: | 2.2.1 |
Component: | Extended Profile | Keywords: | needs-patch |
Cc: |
Description
I would like to add one new hook.
I need to add additional options to the multi select field. In my case minimumSelectionSize and maximumSelectionSize options.
That was not easy done because I need to replicate the admin_new_field_html and add my options under the sort_order select.
<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>
I can already save new options with "xprofile_field_after_save", but I can not add additional options to the multi field.
This new hook solves exactly this issue. I hope you can add it to the next version.
Attachments (2)
Change History (9)
#1
@
10 years ago
- Keywords reporter-feedback added
Hi sven77 - Could you give a more concrete example of how this hook would be used? Are you planning to modify the $current_field
object passed by reference to the action? What about the 'bp_xprofile_field_get_children'
filter that already exists?
#2
@
10 years ago
Hi boonebgorges,
If I understand it correctly, 'bp_xprofile_field_get_children' is perfect to get/manipulate the multiselectbox children.
The multiselectbox options in this case.
<select> <option></option> == children </select>
But I do not want to add new options to a select box, I want to add general options to the multi field type to add some js depend on this options. Not to display this options. The children are the user choices. I want options to to add attributes.
The multiselectbox and all the children should work like normal.
What I try to do is to create a multiselectbox and limit the selection a user can make to a number x.
I did it with some lines of code, but needed to replicate the multiselectbox because of the missing hook.
$xprofile_select2_maximum_selection_size = bp_xprofile_get_meta( $current_field->id, 'field', 'xprofile_select2_maximum_selection_size' ); wp_nonce_field( 'xprofile-select2-edit-action', 'xprofile-select2-edit-action' );
and add the form elements for the option under the sort order.
<p> <label for="maximum-selection-size"><?php esc_html_e( 'Maximum Selection Size:', 'buddypress' ); ?></label> <input type='number' name='xprofile-select2-maximum-selection-size' id='xprofile-select2-maximum-selection-size' class='xprofile-select2-text' value ='<?php echo $xprofile_select2_maximum_selection_size ?>' /> </p>
I have added the complete class to Github so it is more easy to understand. We talk about the public function admin_new_field_html on line 189.
I hope this makes it more clear and understandable. Sorry for my poor english. Next live I will be a native speaker ;)
Many thanks,
Sven
#4
@
10 years ago
- Component changed from API to Component - XProfile
- Keywords needs-patch added; has-patch removed
- Milestone changed from Awaiting Review to 2.3
Ah, thanks for the additional explanation, svenl77. I think the word "options" (and the hook name _additional_options
) was throwing me off - I was associating "options" with the field children.
I don't have a problem with an action here, but here are some suggestions for improvement - let me know what you think.
- Call it
'bp_admin_new_field_html_additional_settings'
- Put it at the very end of
div#inside
- right after the "Add Another Option" button
Add options to multi fields without the need to replicate the code