[buddypress-trac] [BuddyPress Trac] #6272: 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
buddypress-trac
noreply at wordpress.org
Tue Mar 3 14:32:56 UTC 2015
#6272: 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
-----------------------------------------+------------------------------
Reporter: svenl77 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: API | Version: 2.2.1
Severity: normal | Resolution:
Keywords: has-patch reporter-feedback |
-----------------------------------------+------------------------------
Comment (by svenl77):
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.
[[Image(https://dl-
web.dropbox.com/get/Screenshots/xprofile2.jpeg?_subject_uid=16188696&w=AAC1ya1R8Ym0frPTVUUfYvuCJT5PTRqrhTOgdi6vtTcuPg)]]
[[Image(https://photos-6.dropbox.com/t/2/AACNpU0VggbcnDXhYpUy9p7FXaeZojkmZmeFc0g3AJkxBw/12/16188696/jpeg/1024x768/3/1425398400/0/2/xprofile.jpeg/CJiK3AcgASACIAMoASgC/_vaRFsH7MtXRtYA4tW78M7au5ig1joJS2FlxgCNIATM)]]
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.
https://github.com/Themekraft/BuddyPress-xProfile-
Select2/blob/master/includes/field-types/multiselectbox2.php
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
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6272#comment:2>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list