Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/27/2014 07:34:02 PM (10 years ago)
Author:
djpaul
Message:

xProfile: re-architecture profile field types and de-duplicate the templating and validation logic to make it easier for core and plugins to add new profile field types.

Until now, it's been pretty hard to add new types of profile field to BuddyPress. There are a couple of plugins that do a good job, but BuddyPress makes it much harder than it should be because, historically, we've hardcoded values and checks in templates throughout the project. For example, profile field templating was duplicated in the registration template, the member/profile/edit template, in parts of the wp-admin xProfile screens, and in the new wp-admin extended profile editor.

This change implements a new approach that creates a class for each profile field type; selectbox, textbox, textarea, and so on. They all share an abstract base class BP_XProfile_Field_Type which consolidates a lot of special behaviour that had been added to BuddyPress over the years (e.g. some fields accept null values, some accept multiple default values), and adds true field value validation. Unit tests are included.

We've also implemented a new "Numbers" field type with these changes. It behaves much the same as a regular textbox field does, but it only accepts numbers.

Fixes #5220 and #4694

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-templates/bp-legacy/buddypress/members/single/profile/edit.php

    r7965 r8178  
    2222            <div<?php bp_field_css_class( 'editfield' ); ?>>
    2323
    24                 <?php if ( 'textbox' == bp_get_the_profile_field_type() ) : ?>
     24                <?php
     25                $field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() );
     26                $field_type->edit_field_html();
    2527
    26                     <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
    27                     <input type="text" name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" value="<?php bp_the_profile_field_edit_value(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>/>
    28 
    29                 <?php endif; ?>
    30 
    31                 <?php if ( 'textarea' == bp_get_the_profile_field_type() ) : ?>
    32 
    33                     <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
    34                     <textarea rows="5" cols="40" name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>><?php bp_the_profile_field_edit_value(); ?></textarea>
    35 
    36                 <?php endif; ?>
    37 
    38                 <?php if ( 'selectbox' == bp_get_the_profile_field_type() ) : ?>
    39 
    40                     <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
    41                     <select name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>>
    42                         <?php bp_the_profile_field_options(); ?>
    43                     </select>
    44 
    45                 <?php endif; ?>
    46 
    47                 <?php if ( 'multiselectbox' == bp_get_the_profile_field_type() ) : ?>
    48 
    49                     <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
    50                     <select name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" multiple="multiple" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>>
    51 
    52                         <?php bp_the_profile_field_options(); ?>
    53 
    54                     </select>
    55 
    56                     <?php if ( !bp_get_the_profile_field_is_required() ) : ?>
    57 
    58                         <a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name(); ?>' );"><?php _e( 'Clear', 'buddypress' ); ?></a>
    59 
    60                     <?php endif; ?>
    61 
    62                 <?php endif; ?>
    63 
    64                 <?php if ( 'radio' == bp_get_the_profile_field_type() ) : ?>
    65 
    66                     <div class="radio">
    67                         <span class="label"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></span>
    68 
    69                         <?php bp_the_profile_field_options(); ?>
    70 
    71                         <?php if ( !bp_get_the_profile_field_is_required() ) : ?>
    72 
    73                             <a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name(); ?>' );"><?php _e( 'Clear', 'buddypress' ); ?></a>
    74 
    75                         <?php endif; ?>
    76                     </div>
    77 
    78                 <?php endif; ?>
    79 
    80                 <?php if ( 'checkbox' == bp_get_the_profile_field_type() ) : ?>
    81 
    82                     <div class="checkbox">
    83                         <span class="label"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></span>
    84 
    85                         <?php bp_the_profile_field_options(); ?>
    86                     </div>
    87 
    88                 <?php endif; ?>
    89 
    90                 <?php if ( 'datebox' == bp_get_the_profile_field_type() ) : ?>
    91 
    92                     <div class="datebox">
    93                         <label for="<?php bp_the_profile_field_input_name(); ?>_day"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
    94 
    95                         <select name="<?php bp_the_profile_field_input_name(); ?>_day" id="<?php bp_the_profile_field_input_name(); ?>_day" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>>
    96 
    97                             <?php bp_the_profile_field_options( 'type=day' ); ?>
    98 
    99                         </select>
    100 
    101                         <select name="<?php bp_the_profile_field_input_name(); ?>_month" id="<?php bp_the_profile_field_input_name(); ?>_month" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>>
    102 
    103                             <?php bp_the_profile_field_options( 'type=month' ); ?>
    104 
    105                         </select>
    106 
    107                         <select name="<?php bp_the_profile_field_input_name(); ?>_year" id="<?php bp_the_profile_field_input_name(); ?>_year" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>>
    108 
    109                             <?php bp_the_profile_field_options( 'type=year' ); ?>
    110 
    111                         </select>
    112                     </div>
    113 
    114                 <?php endif; ?>
    115 
    116                 <?php do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); ?>
     28                do_action( 'bp_custom_profile_edit_fields_pre_visibility' );
     29                ?>
    11730
    11831                <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?>
Note: See TracChangeset for help on using the changeset viewer.