[buddypress-trac] [BuddyPress Trac] #6521: Extended profile field name "Required" label produces odd HTML

buddypress-trac noreply at wordpress.org
Thu Aug 6 15:36:55 UTC 2015


#6521: Extended profile field name "Required" label produces odd HTML
----------------------------------------+--------------------
 Reporter:  dcavins                     |       Owner:
     Type:  defect (bug)                |      Status:  new
 Priority:  lowest                      |   Milestone:  2.4
Component:  Component - XProfile        |     Version:  2.3.2
 Severity:  trivial                     |  Resolution:
 Keywords:  good-first-bug needs-patch  |
----------------------------------------+--------------------

Comment (by dcavins):

 In looking into BP, this same logic appears about a zillion times:

 {{{
 <?php if ( bp_get_the_profile_field_is_required() ) : ?>
         <?php esc_html_e( '(required)', 'buddypress' ); ?>
 <?php endif; ?>
 }}}

 It's reused so much that I think we should replace it with a template
 function:
 {{{
 <?php
 function bp_the_profile_field_required_label(){
         echo bp_get_the_profile_field_required_label();
 }

         function bp_get_the_profile_field_required_label(){
                 $retval = '';

                 if ( bp_get_the_profile_field_is_required() ) {
                         $translated_string = __( ' (required)',
 'buddypress' );

                         $retval = '<span class="bp-required-field">';
                         $retval .= esc_html( apply_filters(
 'bp_get_the_profile_field_required_label', $translated_string,
 bp_get_the_profile_field_id() ) );
                         $retval .= '</span>';

                 }
                 return $retval;
         }
 ?>
 }}}

 and use it like this:
 {{{
 <label for="<?php bp_the_profile_field_input_name(); ?>">
         <?php bp_the_profile_field_name(); ?>
         <?php bp_the_profile_field_required_label(); ?>
 </label>
 }}}

 Let me know what you think. Also, I assumed that it makes sense to load
 the language file translation before applying filters. If the other
 direction makes more sense, please say so.

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6521#comment:7>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list