Skip to:
Content

BuddyPress.org

Changeset 10163


Ignore:
Timestamp:
10/01/2015 04:18:13 AM (9 years ago)
Author:
tw2113
Message:

First pass of documentation cleanup for the XProfile Component.

See #6406.

Location:
trunk/src/bp-xprofile
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-actions.php

    r10140 r10163  
    2020 * The function will delete the active avatar for a user.
    2121 *
    22  * @package BuddyPress Xprofile
    2322 * @uses bp_core_delete_avatar() Deletes the active avatar for the logged in user.
    2423 * @uses add_action() Runs a specific function for an action when it fires.
     
    3029    }
    3130
    32     // Check the nonce
     31    // Check the nonce.
    3332    check_admin_referer( 'bp_delete_avatar_link' );
    3433
     
    4847
    4948/**
    50  * Handles the saving of xprofile field visibilities
     49 * Handles the saving of xprofile field visibilities.
    5150 *
    5251 * @since 1.9.0
     
    5453function bp_xprofile_action_settings() {
    5554
    56     // Bail if not a POST action
     55    // Bail if not a POST action.
    5756    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
    5857        return;
    5958    }
    6059
    61     // Bail if no submit action
     60    // Bail if no submit action.
    6261    if ( ! isset( $_POST['xprofile-settings-submit'] ) ) {
    6362        return;
    6463    }
    6564
    66     // Bail if not in settings
     65    // Bail if not in settings.
    6766    if ( ! bp_is_user_settings_profile() ) {
    6867        return;
     
    7574    }
    7675
    77     // Nonce check
     76    // Nonce check.
    7877    check_admin_referer( 'bp_xprofile_settings' );
    7978
     
    8786    /** Save ******************************************************************/
    8887
    89     // Only save if there are field ID's being posted
     88    // Only save if there are field ID's being posted.
    9089    if ( ! empty( $_POST['field_ids'] ) ) {
    9190
    92         // Get the POST'ed field ID's
     91        // Get the POST'ed field ID's.
    9392        $posted_field_ids = explode( ',', $_POST['field_ids'] );
    9493
     
    104103        }
    105104
    106         // Save the visibility settings
     105        // Save the visibility settings.
    107106        foreach ( $posted_field_ids as $field_id ) {
    108107
     
    126125    do_action( 'bp_xprofile_settings_after_save' );
    127126
    128     // Redirect to the root domain
     127    // Redirect to the root domain.
    129128    bp_core_redirect( bp_displayed_user_domain() . bp_get_settings_slug() . '/profile' );
    130129}
  • trunk/src/bp-xprofile/bp-xprofile-activity.php

    r10140 r10163  
    1414
    1515/**
    16  * Register the activity actions for the Extended Profile component
    17  *
    18  * @since 1.0.0
    19  *
    20  * @uses bp_activity_set_action() To setup the individual actions
     16 * Register the activity actions for the Extended Profile component.
     17 *
     18 * @since 1.0.0
     19 *
     20 * @uses bp_activity_set_action() To setup the individual actions.
    2121 */
    2222function xprofile_register_activity_actions() {
    2323
    24     // Register the activity stream actions for this component
     24    // Register the activity stream actions for this component.
    2525    bp_activity_set_action(
    26         // older avatar activity items use 'profile' for component
    27         // see r4273
     26        // Older avatar activity items use 'profile' for component. See r4273.
    2827        'profile',
    2928        'new_avatar',
     
    5655 * @since 2.0.0
    5756 *
    58  * @param string $action Static activity action.
     57 * @param string $action   Static activity action.
    5958 * @param object $activity Activity object.
     59 *
    6060 * @return string
    6161 */
     
    6464    $action   = sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink );
    6565
    66     // Legacy filter - pass $user_id instead of $activity
     66    // Legacy filter - pass $user_id instead of $activity.
    6767    if ( has_filter( 'bp_xprofile_new_avatar_action' ) ) {
    6868        $action = apply_filters( 'bp_xprofile_new_avatar_action', $action, $activity->user_id );
     
    8585 * @since 2.0.0
    8686 *
    87  * @param string $action Static activity action.
     87 * @param string $action   Static activity action.
    8888 * @param object $activity Activity object.
     89 *
    8990 * @return string
    9091 */
     
    111112/**
    112113 * Records activity for the logged in user within the profile component so that
    113  * it will show in the users activity stream (if installed)
    114  *
    115  * @since 1.0.0
    116  *
    117  * @package BuddyPress
    118  * @subpackage XProfileActivity
    119  * @param string $args String containing all variables used after extract() call
    120  * @uses bp_activity_add() Adds an entry to the activity component tables for a specific activity
     114 * it will show in the users activity stream (if installed).
     115 *
     116 * @since 1.0.0
     117 *
     118 * @uses bp_activity_add() Adds an entry to the activity component tables for a specific activity.
     119 *
     120 * @param array|string $args String containing all variables used after bp_parse_args() call.
     121 *
     122 * @return array
    121123 */
    122124function xprofile_record_activity( $args = '' ) {
    123125
    124     // Bail if activity component is not active
    125     if ( ! bp_is_active( 'activity' ) ) {
    126         return false;
    127     }
    128 
    129     // Parse the arguments
     126    // Bail if activity component is not active.
     127    if ( ! bp_is_active( 'activity' ) ) {
     128        return false;
     129    }
     130
     131    // Parse the arguments.
    130132    $r = bp_parse_args( $args, array(
    131133        'user_id'           => bp_loggedin_user_id(),
     
    146148/**
    147149 * Deletes activity for a user within the profile component so that it will be
    148  * removed from the users activity stream and sitewide stream (if installed)
    149  *
    150  * @since 1.0.0
    151  *
    152  * @package BuddyPress XProfile
    153  * @param string $args Containing all variables used after extract() call
     150 * removed from the users activity stream and sitewide stream (if installed).
     151 *
     152 * @since 1.0.0
     153 *
    154154 * @uses bp_activity_delete() Deletes an entry to the activity component tables
    155  *                            for a specific activity
     155 *                            for a specific activity.
     156 *
     157 * @param array|string $args Containing all variables used after bp_parse_args() call.
     158 *
     159 * @return bool
    156160 */
    157161function xprofile_delete_activity( $args = '' ) {
    158162
    159     // Bail if activity component is not active
    160     if ( ! bp_is_active( 'activity' ) ) {
    161         return false;
    162     }
    163 
    164     // Parse the arguments
     163    // Bail if activity component is not active.
     164    if ( ! bp_is_active( 'activity' ) ) {
     165        return false;
     166    }
     167
     168    // Parse the arguments.
    165169    $r = bp_parse_args( $args, array(
    166170        'component' => buddypress()->profile->id
    167171    ), 'xprofile_delete_activity' );
    168172
    169     // Delete the activity item
     173    // Delete the activity item.
    170174    bp_activity_delete_by_item_id( $r );
    171175}
    172176
    173177/**
    174  * Register an activity action for the Extended Profiles component
    175  *
    176  * @since 1.0.0
    177  *
    178  * @param string $key
    179  * @param string $value
    180  * @return bool True if success, false on failure
     178 * Register an activity action for the Extended Profiles component.
     179 *
     180 * @since 1.0.0
     181 *
     182 * @param string $key Key.
     183 * @param string $value Value.
     184 *
     185 * @return bool True if success, false on failure.
    181186 */
    182187function xprofile_register_activity_action( $key, $value ) {
    183188
    184     // Bail if activity component is not active
     189    // Bail if activity component is not active.
    185190    if ( ! bp_is_active( 'activity' ) ) {
    186191        return false;
     
    203208 *
    204209 * @since 1.0.0
    205  * @since 2.3.4 Add new parameter to get the user id the avatar was set for
    206  *
    207  * @package BuddyPress XProfile
     210 * @since 2.3.4 Add new parameter to get the user id the avatar was set for.
     211 *
    208212 * @uses bp_activity_add() Adds an entry to the activity component tables for a
    209213 *                         specific activity
    210214 *
    211  * @param  int $user_id The user id the avatar was set for
     215 * @param int $user_id The user id the avatar was set for.
     216 *
     217 * @return bool
    212218 */
    213219function bp_xprofile_new_avatar_activity( $user_id = 0 ) {
    214220
    215     // Bail if activity component is not active
     221    // Bail if activity component is not active.
    216222    if ( ! bp_is_active( 'activity' ) ) {
    217223        return false;
     
    231237    $user_id = apply_filters( 'bp_xprofile_new_avatar_user_id', $user_id );
    232238
    233     // Add the activity
     239    // Add the activity.
    234240    bp_activity_add( array(
    235241        'user_id'   => $user_id,
     
    245251 * @since 2.0.0
    246252 *
    247  * @param int $user_id ID of the user who has updated his profile.
    248  * @param array $field_ids IDs of the fields submitted.
    249  * @param bool $errors True if validation or saving errors occurred, otherwise
    250  *        false.
    251  * @param array $old_values Pre-save xprofile field values and visibility
    252  *        levels.
    253  * @param array $new_values Post-save xprofile field values and visibility
    254  *        levels.
     253 * @param int   $user_id    ID of the user who has updated his profile.
     254 * @param array $field_ids  IDs of the fields submitted.
     255 * @param bool  $errors     True if validation or saving errors occurred, otherwise false.
     256 * @param array $old_values Pre-save xprofile field values and visibility levels.
     257 * @param array $new_values Post-save xprofile field values and visibility levels.
     258 *
    255259 * @return bool True on success, false on failure.
    256260 */
    257261function bp_xprofile_updated_profile_activity( $user_id, $field_ids = array(), $errors = false, $old_values = array(), $new_values = array() ) {
    258262
    259     // If there were errors, don't post
     263    // If there were errors, don't post.
    260264    if ( ! empty( $errors ) ) {
    261265        return false;
    262266    }
    263267
    264     // Bail if activity component is not active
     268    // Bail if activity component is not active.
    265269    if ( ! bp_is_active( 'activity' ) ) {
    266270        return false;
     
    268272
    269273    // Don't post if there have been no changes, or if the changes are
    270     // related solely to non-public fields
     274    // related solely to non-public fields.
    271275    $public_changes = false;
    272276    foreach ( $new_values as $field_id => $new_value ) {
    273277        $old_value = isset( $old_values[ $field_id ] ) ? $old_values[ $field_id ] : '';
    274278
    275         // Don't register changes to private fields
     279        // Don't register changes to private fields.
    276280        if ( empty( $new_value['visibility'] ) || ( 'public' !== $new_value['visibility'] ) ) {
    277281            continue;
    278282        }
    279283
    280         // Don't register if there have been no changes
     284        // Don't register if there have been no changes.
    281285        if ( $new_value === $old_value ) {
    282286            continue;
    283287        }
    284288
    285         // Looks like we have public changes - no need to keep checking
     289        // Looks like we have public changes - no need to keep checking.
    286290        $public_changes = true;
    287291        break;
    288292    }
    289293
    290     // Bail if no public changes
     294    // Bail if no public changes.
    291295    if ( empty( $public_changes ) ) {
    292296        return false;
    293297    }
    294298
    295     // Throttle to one activity of this type per 2 hours
     299    // Throttle to one activity of this type per 2 hours.
    296300    $existing = bp_activity_get( array(
    297301        'max'    => 1,
     
    303307    ) );
    304308
    305     // Default throttle time is 2 hours. Filter to change (in seconds)
     309    // Default throttle time is 2 hours. Filter to change (in seconds).
    306310    if ( ! empty( $existing['activities'] ) ) {
    307311
     
    317321        $now             = strtotime( bp_core_current_time() );
    318322
    319         // Bail if throttled
     323        // Bail if throttled.
    320324        if ( ( $now - $then ) < $throttle_period ) {
    321325            return false;
     
    323327    }
    324328
    325     // If we've reached this point, assemble and post the activity item
     329    // If we've reached this point, assemble and post the activity item.
    326330    $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . bp_get_profile_slug() );
    327331
  • trunk/src/bp-xprofile/bp-xprofile-admin.php

    r10140 r10163  
    1414 * tables are set up.
    1515 *
    16  * @package BuddyPress XProfile
    17  * @uses bp_current_user_can() returns true if the current user is a site admin, false if not
    18  * @uses add_users_page() Adds a submenu tab to a top level tab in the admin area
    19  * @return
     16 * @uses bp_current_user_can() returns true if the current user is a site admin, false if not.
     17 * @uses add_users_page() Adds a submenu tab to a top level tab in the admin area.
     18 *
     19 * @return bool
    2020 */
    2121function xprofile_add_admin_menu() {
    2222
    23     // Bail if current user cannot moderate community
     23    // Bail if current user cannot moderate community.
    2424    if ( ! bp_current_user_can( 'bp_moderate' ) ) {
    2525        return false;
     
    3333 * Handles all actions for the admin area for creating, editing and deleting
    3434 * profile groups and fields.
     35 *
     36 * @param string $message Message to display.
     37 * @param string $type    Type of action to be displayed.
    3538 */
    3639function xprofile_admin( $message = '', $type = 'error' ) {
     
    6770 * @since 2.3.0
    6871 *
    69  * @param string $message Feedback message
    70  * @param string $type    Feedback type
     72 * @param string $message Feedback message.
     73 * @param string $type    Feedback type.
    7174 *
    7275 * @todo Improve error message output
     
    7477function xprofile_admin_screen( $message = '', $type = 'error' ) {
    7578
    76     // Validate type
     79    // Validate type.
    7780    $type = preg_replace( '|[^a-z]|i', '', $type );
    7881
    79     // Get all of the profile groups & fields
     82    // Get all of the profile groups & fields.
    8083    $groups = bp_xprofile_get_groups( array(
    8184        'fetch_fields' => true
     
    176179                                foreach ( $group->fields as $field ) {
    177180
    178                                     // Load the field
     181                                    // Load the field.
    179182                                    $field = new BP_XProfile_Field( $field->id );
    180183
     
    186189                                    /**
    187190                                     * This function handles the WYSIWYG profile field
    188                                      * display for the xprofile admin setup screen
     191                                     * display for the xprofile admin setup screen.
    189192                                     */
    190193                                    xprofile_admin_field( $field, $group, $class );
     
    196199                                <p class="nodrag nofields"><?php _e( 'There are no fields in this group.', 'buddypress' ); ?></p>
    197200
    198                             <?php endif; // end $group->fields ?>
     201                            <?php endif; // End $group->fields. ?>
    199202
    200203                        </fieldset>
     
    224227/**
    225228 * Handles the adding or editing of groups.
     229 *
     230 * @param int|null $group_id Group ID to manage.
    226231 */
    227232function xprofile_admin_manage_group( $group_id = null ) {
    228233    global $message, $type;
    229234
    230     // Get the field group
     235    // Get the field group.
    231236    $group = new BP_XProfile_Group( $group_id );
    232237
    233     // Updating
     238    // Updating.
    234239    if ( isset( $_POST['save_group'] ) ) {
    235240
    236         // Validate $_POSTed data
     241        // Validate $_POSTed data.
    237242        if ( BP_XProfile_Group::admin_validate() ) {
    238243
    239             // Set the group name
     244            // Set the group name.
    240245            $group->name = $_POST['group_name'];
    241246
    242             // Set the group description
     247            // Set the group description.
    243248            if ( ! empty( $_POST['group_description'] ) ) {
    244249                $group->description = $_POST['group_description'];
     
    247252            }
    248253
    249             // Attempt to save the field group
     254            // Attempt to save the field group.
    250255            if ( false === $group->save() ) {
    251256                $message = __( 'There was an error saving the group. Please try again.', 'buddypress' );
    252257                $type    = 'error';
    253258
    254             // Save successful
     259            // Save successful.
    255260            } else {
    256261                $message = __( 'The group was saved successfully.', 'buddypress' );
     
    285290/**
    286291 * Handles the deletion of profile data groups.
     292 *
     293 * @param int $group_id ID of the group to delete.
    287294 */
    288295function xprofile_admin_delete_group( $group_id ) {
     
    314321/**
    315322 * Handles the adding or editing of profile field data for a user.
     323 *
     324 * @param int      $group_id ID of the group.
     325 * @param int|null $field_id ID of the field being managed.
    316326 */
    317327function xprofile_admin_manage_field( $group_id, $field_id = null ) {
     
    371381                }
    372382
    373                 // Validate default visibility
     383                // Validate default visibility.
    374384                if ( ! empty( $_POST['default-visibility'] ) && in_array( $_POST['default-visibility'], wp_list_pluck( bp_xprofile_get_visibility_levels(), 'id' ) ) ) {
    375385                    bp_xprofile_update_field_meta( $field_id, 'default_visibility', $_POST['default-visibility'] );
    376386                }
    377387
    378                 // Validate custom visibility
     388                // Validate custom visibility.
    379389                if ( ! empty( $_POST['allow-custom-visibility'] ) && in_array( $_POST['allow-custom-visibility'], array( 'allowed', 'disabled' ) ) ) {
    380390                    bp_xprofile_update_field_meta( $field_id, 'allow_custom_visibility', $_POST['allow-custom-visibility'] );
    381391                }
    382392
    383                 // Validate signup
     393                // Validate signup.
    384394                if ( ! empty( $_POST['signup-position'] ) ) {
    385395                    bp_xprofile_update_field_meta( $field_id, 'signup_position', (int) $_POST['signup-position'] );
     
    413423
    414424/**
    415  * Handles the deletion of a profile field (or field option)
     425 * Handles the deletion of a profile field (or field option).
    416426 *
    417427 * @since 1.0.0
    418  * @global string $message The feedback message to show
    419  * @global $type The type of feedback message to show
    420  * @param int $field_id The field to delete
    421  * @param string $field_type The type of field being deleted
    422  * @param bool $delete_data Should the field data be deleted too?
     428 * @global string $message The feedback message to show.
     429 * @global $type The type of feedback message to show.
     430 *
     431 * @param int    $field_id    The field to delete.
     432 * @param string $field_type  The type of field being deleted.
     433 * @param bool   $delete_data Should the field data be deleted too.
    423434 */
    424435function xprofile_admin_delete_field( $field_id, $field_type = 'field', $delete_data = false ) {
    425436    global $message, $type;
    426437
    427     // Switch type to 'option' if type is not 'field'
    428     // @todo trust this param
     438    // Switch type to 'option' if type is not 'field'.
     439    // @todo trust this param.
    429440    $field_type  = ( 'field' == $field_type ) ? __( 'field', 'buddypress' ) : __( 'option', 'buddypress' );
    430441    $field       = new BP_XProfile_Field( $field_id );
     
    452463
    453464/**
    454  * Handles the ajax reordering of fields within a group
     465 * Handles the ajax reordering of fields within a group.
    455466 */
    456467function xprofile_ajax_reorder_fields() {
    457468
    458     // Check the nonce
     469    // Check the nonce.
    459470    check_admin_referer( 'bp_reorder_fields', '_wpnonce_reorder_fields' );
    460471
     
    474485
    475486/**
    476  * Handles the reordering of field groups
     487 * Handles the reordering of field groups.
    477488 */
    478489function xprofile_ajax_reorder_field_groups() {
    479490
    480     // Check the nonce
     491    // Check the nonce.
    481492    check_admin_referer( 'bp_reorder_groups', '_wpnonce_reorder_groups' );
    482493
     
    494505
    495506/**
    496  * Handles the WYSIWYG display of each profile field on the edit screen
     507 * Handles the WYSIWYG display of each profile field on the edit screen.
     508 *
     509 * @param object $admin_field Admin field.
     510 * @param object $admin_group Admin group object.
     511 * @param string $class       Classes to append to output.
    497512 */
    498513function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) {
     
    584599 * Print <option> elements containing the xprofile field types.
    585600 *
    586  * @param string $select_field_type The name of the field type that should be selected. Will defaults to "textbox" if NULL is passed.
    587601 * @since 2.0.0
     602 *
     603 * @param string $select_field_type The name of the field type that should be selected.
     604 *                                  Will defaults to "textbox" if NULL is passed.
    588605 */
    589606function bp_xprofile_admin_form_field_types( $select_field_type ) {
     
    594611    }
    595612
    596     // Sort each field type into its category
     613    // Sort each field type into its category.
    597614    foreach ( bp_xprofile_get_field_types() as $field_name => $field_class ) {
    598615        $field_type_obj = new $field_class;
    599616        $the_category   = $field_type_obj->category;
    600617
    601         // Fallback to a catch-all if category not set
     618        // Fallback to a catch-all if category not set.
    602619        if ( ! $the_category ) {
    603620            $the_category = _x( 'Other', 'xprofile field type category', 'buddypress' );
     
    611628    }
    612629
    613     // Sort the categories alphabetically. ksort()'s SORT_NATURAL is only in PHP >= 5.4 :((
     630    // Sort the categories alphabetically. ksort()'s SORT_NATURAL is only in PHP >= 5.4 :((.
    614631    uksort( $categories, 'strnatcmp' );
    615632
    616     // Loop through each category and output form <options>
     633    // Loop through each category and output form <options>.
    617634    foreach ( $categories as $category => $fields ) {
    618         printf( '<optgroup label="%1$s">', esc_attr( $category ) );  // Already i18n'd in each profile type class
    619 
    620         // Sort these fields types alphabetically
     635        printf( '<optgroup label="%1$s">', esc_attr( $category ) );  // Already i18n'd in each profile type class.
     636
     637        // Sort these fields types alphabetically.
    621638        uasort( $fields, create_function( '$a, $b', 'return strnatcmp( $a[1]->name, $b[1]->name );' ) );
    622639
     
    633650
    634651if ( ! class_exists( 'BP_XProfile_User_Admin' ) ) :
     652
    635653/**
    636654 * Load xProfile Profile admin area.
    637  *
    638  * @package BuddyPress
    639  * @subpackage xProfileAdministration
    640655 *
    641656 * @since 2.0.0
     
    649664     * @since 2.0.0
    650665     *
    651      * @uses buddypress() to get BuddyPress main instance
     666     * @uses buddypress() to get BuddyPress main instance.
    652667     */
    653668    public static function register_xprofile_user_admin() {
    654669
    655         // Bail if not in admin
     670        // Bail if not in admin.
    656671        if ( ! is_admin() ) {
    657672            return;
     
    684699     */
    685700    private function setup_actions() {
    686         // Enqueue scripts
     701        // Enqueue scripts.
    687702        add_action( 'bp_members_admin_enqueue_scripts',  array( $this, 'enqueue_scripts'    ), 10, 1 );
    688703
    689         // Register the metabox in Member's community admin profile
     704        // Register the metabox in Member's community admin profile.
    690705        add_action( 'bp_members_admin_xprofile_metabox', array( $this, 'register_metaboxes' ), 10, 3 );
    691706
    692         // Saves the profile actions for user ( avatar, profile fields )
     707        // Saves the profile actions for user ( avatar, profile fields ).
    693708        add_action( 'bp_members_admin_update_user',      array( $this, 'user_admin_load'    ), 10, 4 );
    694709    }
     
    699714     * @access public
    700715     * @since 2.3.0
     716     *
     717     * @param int $screen_id Screen ID being displayed.
    701718     */
    702719    public function enqueue_scripts( $screen_id ) {
     
    710727
    711728        /**
    712          * Get Thickbox
     729         * Get Thickbox.
    713730         *
    714731         * We cannot simply use add_thickbox() here as WordPress is not playing
     
    720737        wp_enqueue_script( 'media-upload' );
    721738
    722         // Get Avatar Uploader
     739        // Get Avatar Uploader.
    723740        bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
    724741    }
     
    730747     * @since 2.0.0
    731748     *
    732      * @param int $user_id ID of the user being edited.
    733      * @param string $screen_id Screen ID to load the metabox in.
     749     * @param int    $user_id      ID of the user being edited.
     750     * @param string $screen_id     Screen ID to load the metabox in.
    734751     * @param object $stats_metabox Context and priority for the stats metabox.
    735752     */
    736753    public function register_metaboxes( $user_id = 0, $screen_id = '', $stats_metabox = null ) {
    737754
    738         // Set the screen ID if none was passed
     755        // Set the screen ID if none was passed.
    739756        if ( empty( $screen_id ) ) {
    740757            $screen_id = buddypress()->members->admin->user_page;
    741758        }
    742759
    743         // Setup a new metabox class if none was passed
     760        // Setup a new metabox class if none was passed.
    744761        if ( empty( $stats_metabox ) ) {
    745762            $stats_metabox = new StdClass();
    746763        }
    747764
    748         // Moving the Stats Metabox
     765        // Moving the Stats Metabox.
    749766        $stats_metabox->context  = 'side';
    750767        $stats_metabox->priority = 'low';
    751768
    752         // Each Group of fields will have his own metabox
     769        // Each Group of fields will have his own metabox.
    753770        $profile_args = array(
    754771            'fetch_fields' => false,
     
    758775        if ( ! bp_is_user_spammer( $user_id ) && bp_has_profile( $profile_args ) ) {
    759776
    760             // Loop through field groups and add a metabox for each one
     777            // Loop through field groups and add a metabox for each one.
    761778            while ( bp_profile_groups() ) : bp_the_profile_group();
    762779                add_meta_box(
     
    771788            endwhile;
    772789
    773         // If member is already a spammer, show a generic metabox
     790        // If member is already a spammer, show a generic metabox.
    774791        } else {
    775792            add_meta_box(
     
    784801
    785802        if ( buddypress()->avatar->show_avatars ) {
    786             // Avatar Metabox
     803            // Avatar Metabox.
    787804            add_meta_box(
    788805                'bp_xprofile_user_admin_avatar',
     
    804821     * @access public
    805822     * @since 2.0.0
     823     *
     824     * @param string $doaction    Action being run.
     825     * @param int    $user_id     ID for the user whose profile is being saved.
     826     * @param array  $request     Request being made.
     827     * @param string $redirect_to Where to redirect user to.
    806828     */
    807829    public function user_admin_load( $doaction = '', $user_id = 0, $request = array(), $redirect_to = '' ) {
    808830
    809         // Eventually delete avatar
     831        // Eventually delete avatar.
    810832        if ( 'delete_avatar' === $doaction ) {
    811833
     
    822844            bp_core_redirect( $redirect_to );
    823845
    824         // Update profile fields
     846        // Update profile fields.
    825847        } elseif ( isset( $_POST['field_ids'] ) ) {
    826848
    827             // Check the nonce
     849            // Check the nonce.
    828850            check_admin_referer( 'edit-bp-profile_' . $user_id );
    829851
    830             // Check we have field ID's
     852            // Check we have field ID's.
    831853            if ( empty( $_POST['field_ids'] ) ) {
    832854                $redirect_to = add_query_arg( 'error', '1', $redirect_to );
     
    846868            $merge_ids = join( ',', $_POST['field_ids'] );
    847869
    848             // Explode the posted field IDs into an array so we know which fields have been submitted
     870            // Explode the posted field IDs into an array so we know which fields have been submitted.
    849871            $posted_field_ids = wp_parse_id_list( $merge_ids );
    850872            $is_required      = array();
    851873
    852             // Loop through the posted fields formatting any datebox values then validate the field
     874            // Loop through the posted fields formatting any datebox values then validate the field.
    853875            foreach ( (array) $posted_field_ids as $field_id ) {
    854876                if ( ! isset( $_POST['field_' . $field_id ] ) ) {
    855877                    if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) {
    856878
    857                         // Concatenate the values
     879                        // Concatenate the values.
    858880                        $date_value =   $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
    859881
    860                         // Turn the concatenated value into a timestamp
     882                        // Turn the concatenated value into a timestamp.
    861883                        $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) );
    862884                    }
     
    870892            }
    871893
    872             // Set the errors var
     894            // Set the errors var.
    873895            $errors = false;
    874896
     
    896918                }
    897919
    898                 // Save the visibility level
     920                // Save the visibility level.
    899921                $visibility_level = ! empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
    900922                xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
     
    912934            do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, $errors );
    913935
    914             // Set the feedback messages
     936            // Set the feedback messages.
    915937            if ( ! empty( $errors ) ) {
    916938                $redirect_to = add_query_arg( 'error',   '3', $redirect_to );
     
    930952     *
    931953     * @param WP_User $user The WP_User object for the user being edited.
     954     * @param array   $args Aray of arguments for metaboxes.
    932955     */
    933956    public function user_admin_profile_metaboxes( $user = null, $args = array() ) {
    934957
    935         // Bail if no user ID
     958        // Bail if no user ID.
    936959        if ( empty( $user->ID ) ) {
    937960            return;
     
    943966        ), 'bp_xprofile_user_admin_profile_loop_args' );
    944967
    945         // We really need these args
     968        // We really need these args.
    946969        if ( empty( $r['profile_group_id'] ) || empty( $r['user_id'] ) ) {
    947970            return;
    948971        }
    949972
    950         // Bail if no profile fields are available
     973        // Bail if no profile fields are available.
    951974        if ( ! bp_has_profile( $r ) ) {
    952975            return;
    953976        }
    954977
    955         // Loop through profile groups & fields
     978        // Loop through profile groups & fields.
    956979        while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
    957980
     
    10241047                </div>
    10251048
    1026             <?php endwhile; // bp_profile_fields() ?>
    1027 
    1028         <?php endwhile; // bp_profile_groups
     1049            <?php endwhile; // End bp_profile_fields(). ?>
     1050
     1051        <?php endwhile; // End bp_profile_groups.
    10291052    }
    10301053
     
    10841107            <?php endif;
    10851108
    1086             // Load the Avatar UI templates if user avatar uploads are enabled and current WordPress version is supported
     1109            // Load the Avatar UI templates if user avatar uploads are enabled and current WordPress version is supported.
    10871110            if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) && bp_attachments_is_wp_version_supported() ) : ?>
    10881111                <a href="#TB_inline?width=800px&height=400px&inlineId=bp-xprofile-avatar-editor" title="<?php esc_attr_e( 'Edit Profile Photo', 'buddypress' );?>" class="thickbox bp-xprofile-avatar-user-edit"><?php esc_html_e( 'Edit Profile Photo', 'buddypress' ); ?></a>
     
    10971120
    10981121}
    1099 endif; // class_exists check
    1100 
    1101 // Load the xprofile user admin
     1122endif; // End class_exists check.
     1123
     1124// Load the xprofile user admin.
    11021125add_action( 'bp_init', array( 'BP_XProfile_User_Admin', 'register_xprofile_user_admin' ), 11 );
  • trunk/src/bp-xprofile/bp-xprofile-cache.php

    r10140 r10163  
    1818 * @since 2.2.0
    1919 *
    20  * @param int   $user_id   User ID to check
     20 * @param int   $user_id   User ID to check.
    2121 * @param array $field_ids XProfile field IDs.
     22 *
    2223 * @return array
    2324 */
     
    5152 *
    5253 * @param array $object_ids Multi-dimensional array of object_ids, keyed by
    53  *        object type ('group', 'field', 'data')
     54 *                          object type ('group', 'field', 'data').
     55 *
     56 * @return bool
    5457 */
    5558function bp_xprofile_update_meta_cache( $object_ids = array() ) {
    5659    global $wpdb;
    5760
    58     // Bail if no objects
     61    // Bail if no objects.
    5962    if ( empty( $object_ids ) ) {
    6063        return false;
     
    6366    $bp = buddypress();
    6467
    65     // Define the array where uncached object IDs will be stored
     68    // Define the array where uncached object IDs will be stored.
    6669    $uncached_object_ids = array(
    6770        'group',
     
    7073    );
    7174
    72     // Define the cache groups for the 3 types of XProfile metadata
     75    // Define the cache groups for the 3 types of XProfile metadata.
    7376    $cache_groups = array(
    7477        'group' => 'xprofile_group_meta',
     
    7780    );
    7881
    79     // No reason to query yet
     82    // No reason to query yet.
    8083    $do_query = false;
    8184
    82     // Loop through object types and look for uncached data
     85    // Loop through object types and look for uncached data.
    8386    foreach ( $uncached_object_ids as $object_type ) {
    8487
    85         // Skip if empty object type
     88        // Skip if empty object type.
    8689        if ( empty( $object_ids[ $object_type ] ) ) {
    8790            continue;
    8891        }
    8992
    90         // Sanitize $object_ids passed to the function
     93        // Sanitize $object_ids passed to the function.
    9194        $object_type_ids = wp_parse_id_list( $object_ids[ $object_type ] );
    9295
    93         // Get non-cached IDs for each object type
     96        // Get non-cached IDs for each object type.
    9497        $uncached_object_ids[ $object_type ] = bp_get_non_cached_ids( $object_type_ids, $cache_groups[ $object_type ] );
    9598
    96         // Set the flag to do the meta query
     99        // Set the flag to do the meta query.
    97100        if ( ! empty( $uncached_object_ids[ $object_type ] ) && ( false === $do_query ) ) {
    98101            $do_query = true;
     
    100103    }
    101104
    102     // Bail if no uncached items
     105    // Bail if no uncached items.
    103106    if ( false === $do_query ) {
    104107        return;
    105108    }
    106109
    107     // Setup where conditions for query
     110    // Setup where conditions for query.
    108111    $where_sql        = '';
    109112    $where_conditions = array();
    110113
    111     // Loop through uncached objects and prepare to query for them
     114    // Loop through uncached objects and prepare to query for them.
    112115    foreach ( $uncached_object_ids as $otype => $oids ) {
    113116
    114         // Skip empty object IDs
     117        // Skip empty object IDs.
    115118        if ( empty( $oids ) ) {
    116119            continue;
    117120        }
    118121
    119         // Compile WHERE query conditions for uncached metadata
     122        // Compile WHERE query conditions for uncached metadata.
    120123        $oids_sql           = implode( ',', wp_parse_id_list( $oids ) );
    121124        $where_conditions[] = $wpdb->prepare( "( object_type = %s AND object_id IN ({$oids_sql}) )", $otype );
    122125    }
    123126
    124     // Bail if no where conditions
     127    // Bail if no where conditions.
    125128    if ( empty( $where_conditions ) ) {
    126129        return;
    127130    }
    128131
    129     // Setup the WHERE query part
     132    // Setup the WHERE query part.
    130133    $where_sql = implode( " OR ", $where_conditions );
    131134
    132     // Attempt to query meta values
     135    // Attempt to query meta values.
    133136    $meta_list = $wpdb->get_results( "SELECT object_id, object_type, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE {$where_sql}" );
    134137
    135     // Bail if no results found
     138    // Bail if no results found.
    136139    if ( empty( $meta_list ) || is_wp_error( $meta_list ) ) {
    137140        return;
    138141    }
    139142
    140     // Setup empty cache array
     143    // Setup empty cache array.
    141144    $cache = array();
    142145
    143     // Loop through metas
     146    // Loop through metas.
    144147    foreach ( $meta_list as $meta ) {
    145148        $oid    = $meta->object_id;
     
    148151        $ovalue = $meta->meta_value;
    149152
    150         // Force subkeys to be array type
     153        // Force subkeys to be array type.
    151154        if ( ! isset( $cache[ $otype ][ $oid ] ) || ! is_array( $cache[ $otype ][ $oid ] ) ) {
    152155            $cache[ $otype ][ $oid ] = array();
     
    157160        }
    158161
    159         // Add to the cache array
     162        // Add to the cache array.
    160163        $cache[ $otype ][ $oid ][ $okey ][] = maybe_unserialize( $ovalue );
    161164    }
    162165
    163     // Loop through data and cache to the appropriate object
     166    // Loop through data and cache to the appropriate object.
    164167    foreach ( $cache as $object_type => $object_caches ) {
    165168
    166         // Determine the cache group for this data
     169        // Determine the cache group for this data.
    167170        $cache_group = $cache_groups[ $object_type ];
    168171
    169         // Loop through objects and cache appropriately
     172        // Loop through objects and cache appropriately.
    170173        foreach ( $object_caches as $object_id => $object_cache ) {
    171174            wp_cache_set( $object_id, $object_cache, $cache_group );
     
    175178
    176179/**
    177  * Clear cached XProfile field group data
     180 * Clear cached XProfile field group data.
    178181 *
    179182 * @since 2.1.0
    180183 *
    181  * @param object $group_obj
     184 * @param object $group_obj Groub object to clear.
    182185 */
    183186function xprofile_clear_profile_groups_object_cache( $group_obj ) {
     
    189192
    190193/**
    191  * Clear cached XProfile fullname data for user
     194 * Clear cached XProfile fullname data for user.
    192195 *
    193196 * @since 2.1.0
    194197 *
    195  * @param int $user_id ID of user whose fullname cache to delete
     198 * @param int $user_id ID of user whose fullname cache to delete.
    196199 */
    197200function xprofile_clear_profile_data_object_cache( $user_id = 0 ) {
     
    203206 * Clear the fullname cache when field 1 is updated.
    204207 *
    205  * xprofile_clear_profile_data_object_cache() will make this redundant in most
    206  * cases, except where the field is updated directly with xprofile_set_field_data()
    207  *
    208  * @since 2.0.0
     208 * The xprofile_clear_profile_data_object_cache() will make this redundant in most
     209 * cases, except where the field is updated directly with xprofile_set_field_data().
     210 *
     211 * @since 2.0.0
     212 *
     213 * @param object $data Data object to clear.
    209214 */
    210215function xprofile_clear_fullname_cache_on_profile_field_edit( $data ) {
     
    220225 * @since 2.0.0
    221226 *
    222  * @param BP_XProfile_Field
     227 * @param BP_XProfile_Field $field_obj Field object cache to delete.
    223228 */
    224229function xprofile_clear_profile_field_object_cache( $field_obj ) {
    225230
    226     // Clear default visibility level cache
     231    // Clear default visibility level cache.
    227232    wp_cache_delete( 'default_visibility_levels', 'bp_xprofile' );
    228233
    229234    // Modified fields can alter parent group status, in particular when
    230235    // the group goes from empty to non-empty. Bust its cache, as well as
    231     // the global 'all' cache
     236    // the global 'all' cache.
    232237    wp_cache_delete( 'all',                'bp_xprofile_groups' );
    233238    wp_cache_delete( $field_obj->group_id, 'bp_xprofile_groups' );
     
    251256 * @since 2.0.0
    252257 *
    253  * @param BP_XProfile_ProfileData $data_obj
     258 * @param BP_XProfile_ProfileData $data_obj Field data object to delete.
    254259 */
    255260function xprofile_clear_profiledata_object_cache( $data_obj ) {
     
    279284add_action( 'update_option_bp-xprofile-fullname-field-name', 'xprofile_clear_fullname_field_id_cache' );
    280285
    281 // List actions to clear super cached pages on, if super cache is installed
     286// List actions to clear super cached pages on, if super cache is installed.
    282287add_action( 'xprofile_updated_profile', 'bp_core_clear_cache' );
  • trunk/src/bp-xprofile/bp-xprofile-caps.php

    r10140 r10163  
    1212
    1313/**
    14  * Maps XProfile caps to built in WordPress caps
     14 * Maps XProfile caps to built in WordPress caps.
    1515 *
    1616 * @since 1.6.0
    1717 *
    18  * @param array $caps Capabilities for meta capability
    19  * @param string $cap Capability name
    20  * @param int $user_id User id
    21  * @param mixed $args Arguments
    22  * @uses get_post() To get the post
    23  * @uses get_post_type_object() To get the post type object
    24  * @uses apply_filters() Calls 'bp_map_meta_caps' with caps, cap, user id and
    25  *                        args
    26  * @return array Actual capabilities for meta capability
     18 * @param array  $caps    Capabilities for meta capability.
     19 * @param string $cap     Capability name.
     20 * @param int    $user_id User id.
     21 * @param mixed  $args    Arguments.
     22 *
     23 * @uses get_post() To get the post.
     24 * @uses get_post_type_object() To get the post type object.
     25 * @uses apply_filters() Calls 'bp_map_meta_caps' with caps, cap, user id and args.
     26 *
     27 * @return array Actual capabilities for meta capability.
    2728 */
    2829function bp_xprofile_map_meta_caps( $caps, $cap, $user_id, $args ) {
    2930    switch ( $cap ) {
    3031        case 'bp_xprofile_change_field_visibility' :
    31             $caps = array( 'exist' ); // Must allow for logged-out users during registration
     32            $caps = array( 'exist' ); // Must allow for logged-out users during registration.
    3233
    33             // You may pass args manually: $field_id, $profile_user_id
     34            // You may pass args manually: $field_id, $profile_user_id.
    3435            $field_id        = isset( $args[0] ) ? (int)$args[0] : bp_get_the_profile_field_id();
    3536            $profile_user_id = isset( $args[1] ) ? (int)$args[1] : bp_displayed_user_id();
    3637
    37             // Visibility on the fullname field is not editable
     38            // Visibility on the fullname field is not editable.
    3839            if ( 1 == $field_id ) {
    3940                $caps[] = 'do_not_allow';
     
    4748            }
    4849
    49             // Friends don't let friends edit each other's visibility
     50            // Friends don't let friends edit each other's visibility.
    5051            if ( $profile_user_id != bp_displayed_user_id() && !bp_current_user_can( 'bp_moderate' ) ) {
    5152                $caps[] = 'do_not_allow';
  • trunk/src/bp-xprofile/bp-xprofile-cssjs.php

    r10140 r10163  
    1111
    1212/**
    13  * Enqueue the CSS for XProfile admin styling
     13 * Enqueue the CSS for XProfile admin styling.
    1414 *
    1515 * @since 1.1.0
     
    3030
    3131/**
    32  * Enqueue the jQuery libraries for handling drag/drop/sort
     32 * Enqueue the jQuery libraries for handling drag/drop/sort.
    3333 *
    3434 * @since 1.5.0
     
    4949        // supports_options_field_types is a dynamic list of field
    5050        // types that support options, for use in showing/hiding the
    51         // "please enter options for this field" section
     51        // "please enter options for this field" section.
    5252        $strings = array(
    5353            'supports_options_field_types' => array(),
  • trunk/src/bp-xprofile/bp-xprofile-filters.php

    r10140 r10163  
    5555add_filter( 'xprofile_filtered_data_value_before_save', 'trim', 2 );
    5656
    57 // Save field groups
     57// Save field groups.
    5858add_filter( 'xprofile_group_name_before_save',        'wp_filter_kses' );
    5959add_filter( 'xprofile_group_description_before_save', 'wp_filter_kses' );
    6060
    61 // Save fields
     61// Save fields.
    6262add_filter( 'xprofile_field_name_before_save',         'wp_filter_kses' );
    6363add_filter( 'xprofile_field_type_before_save',         'wp_filter_kses' );
     
    6969add_filter( 'xprofile_field_can_delete_before_save',   'absint' );
    7070
    71 // Save field options
     71// Save field options.
    7272add_filter( 'xprofile_field_options_before_save', 'bp_xprofile_sanitize_field_options' );
    7373add_filter( 'xprofile_field_default_before_save', 'bp_xprofile_sanitize_field_default' );
    7474
    7575/**
    76  * Sanitize each field option name for saving to the database
     76 * Sanitize each field option name for saving to the database.
    7777 *
    7878 * @since 2.3.0
    7979 *
    80  * @param  mixed $field_options
     80 * @param  mixed $field_options Options to sanitize.
     81 *
    8182 * @return mixed
    8283 */
     
    9091
    9192/**
    92  * Sanitize each field option default for saving to the database
     93 * Sanitize each field option default for saving to the database.
    9394 *
    9495 * @since 2.3.0
    9596 *
    96  * @param  mixed $field_default
     97 * @param  mixed $field_default Field defaults to sanitize.
     98 *
    9799 * @return mixed
    98100 */
     
    106108
    107109/**
    108  * xprofile_filter_kses ( $content )
    109  *
    110110 * Run profile field values through kses with filterable allowed tags.
    111111 *
    112  * @param string $content
    113  * @param object $data_obj The BP_XProfile_ProfileData object
     112 * @param string $content  Content to filter.
     113 * @param object $data_obj The BP_XProfile_ProfileData object.
     114 *
    114115 * @return string $content
    115116 */
     
    135136 * Safely runs profile field data through kses and force_balance_tags.
    136137 *
    137  * @param string $field_value
    138  * @param int $field_id
    139  * @param bool $reserialize Whether to reserialize arrays before returning. Defaults to true
    140  * @param object $data_obj The BP_XProfile_ProfileData object
     138 * @param string $field_value Field value being santized.
     139 * @param int    $field_id    Field ID being sanitized.
     140 * @param bool   $reserialize Whether to reserialize arrays before returning. Defaults to true.
     141 * @param object $data_obj    The BP_XProfile_ProfileData object.
     142 *
    141143 * @return string
    142144 */
    143145function xprofile_sanitize_data_value_before_save( $field_value, $field_id = 0, $reserialize = true, $data_obj = null ) {
    144146
    145     // Return if empty
     147    // Return if empty.
    146148    if ( empty( $field_value ) ) {
    147149        return $field_value;
    148150    }
    149151
    150     // Value might be serialized
     152    // Value might be serialized.
    151153    $field_value = maybe_unserialize( $field_value );
    152154
    153     // Filter single value
     155    // Filter single value.
    154156    if ( !is_array( $field_value ) ) {
    155157        $kses_field_value     = xprofile_filter_kses( $field_value, $data_obj );
     
    167169        $filtered_field_value = apply_filters( 'xprofile_filtered_data_value_before_save', $filtered_field_value, $field_value, $data_obj );
    168170
    169     // Filter each array item independently
     171    // Filter each array item independently.
    170172    } else {
    171173        $filtered_values = array();
     
    195197 *
    196198 * @param string $field_value XProfile field_value to be filtered.
    197  * @param string $field_type XProfile field_type to be filtered.
     199 * @param string $field_type  XProfile field_type to be filtered.
     200 *
    198201 * @return string $field_value Filtered XProfile field_value. False on failure.
    199202 */
    200203function xprofile_filter_format_field_value( $field_value, $field_type = '' ) {
    201204
    202     // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731
     205    // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731.
    203206    if ( ! isset( $field_value ) || empty( $field_value ) && ( '0' !== $field_value ) ) {
    204207        return false;
     
    213216
    214217/**
    215  * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched inside a bp_has_profile() loop.
     218 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched inside
     219 * a bp_has_profile() loop.
    216220 *
    217221 * @since 2.1.0
    218222 *
    219  * @param mixed $field_value Field value.
    220  * @param string $field_type Field type.
     223 * @param mixed  $field_value Field value.
     224 * @param string $field_type  Field type.
     225 *
    221226 * @return mixed
    222227 */
     
    236241
    237242/**
    238  * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched by xprofile_get_field_data().
     243 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched
     244 * by xprofile_get_field_data().
    239245 *
    240246 * @since 2.1.0
    241247 *
    242248 * @param mixed $field_value Field value.
    243  * @param int $field_id Field type.
     249 * @param int   $field_id    Field type.
     250 *
     251 * @return string
    244252 */
    245253function xprofile_filter_format_field_value_by_field_id( $field_value, $field_id ) {
     
    253261 * @since 2.1.0
    254262 *
    255  * @param mixed $value Value passed to the bp_xprofile_set_field_data_pre_validate
    256  *        filter.
    257  * @param BP_XProfile_Field $field Field object.
    258  * @param BP_XProfile_Field_Type Field type object.
     263 * @param mixed                  $value          Value passed to the bp_xprofile_set_field_data_pre_validate filter.
     264 * @param BP_XProfile_Field      $field          Field object.
     265 * @param BP_XProfile_Field_Type $field_type_obj Field type object.
     266 *
    259267 * @return mixed
    260268 */
     
    271279 * to members search results out of them.
    272280 *
    273  * - Not run on datebox field types
    274  * - Not run on values without commas with less than 5 words
    275  * - URL's are made clickable
     281 * - Not run on datebox field types.
     282 * - Not run on values without commas with less than 5 words.
     283 * - URL's are made clickable.
    276284 * - To disable: remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    277285 *
    278286 * @since 1.1.0
    279287 *
    280  * @param string $field_value
    281  * @param string  $field_type
     288 * @param string $field_value Profile field data value.
     289 * @param string $field_type  Profile field type.
     290 *
    282291 * @return string
    283292 */
     
    302311                $new_values[] = make_clickable( $value );
    303312
    304             // Is not clickable
     313            // Is not clickable.
    305314            } else {
    306315
    307                 // More than 5 spaces
     316                // More than 5 spaces.
    308317                if ( count( explode( ' ', $value ) ) > 5 ) {
    309318                    $new_values[] = $value;
    310319
    311                 // Less than 5 spaces
     320                // Less than 5 spaces.
    312321                } else {
    313322                    $search_url   = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
     
    324333
    325334/**
    326  * Ensures that BP data appears in comments array
     335 * Ensures that BP data appears in comments array.
    327336 *
    328337 * This filter loops through the comments return by a normal WordPress request
    329  * and swaps out user data with BP xprofile data, where available
    330  *
    331  * @param array $comments
    332  * @param int $post_id
     338 * and swaps out user data with BP xprofile data, where available.
     339 *
     340 * @param array $comments Comments to filter in.
     341 * @param int   $post_id  Post ID the comments are for.
     342 *
    333343 * @return array $comments
    334344 */
    335345function xprofile_filter_comments( $comments, $post_id = 0 ) {
    336346
    337     // Locate comment authors with WP accounts
     347    // Locate comment authors with WP accounts.
    338348    foreach( (array) $comments as $comment ) {
    339349        if ( $comment->user_id ) {
     
    342352    }
    343353
    344     // If none are found, just return the comments array
     354    // If none are found, just return the comments array.
    345355    if ( empty( $user_ids ) ) {
    346356        return $comments;
    347357    }
    348358
    349     // Pull up the xprofile fullname of each commenter
     359    // Pull up the xprofile fullname of each commenter.
    350360    if ( $fullnames = bp_core_get_user_displaynames( $user_ids ) ) {
    351361        foreach( (array) $fullnames as $user_id => $user_fullname ) {
     
    354364    }
    355365
    356     // Loop through and match xprofile fullname with commenters
     366    // Loop through and match xprofile fullname with commenters.
    357367    foreach( (array) $comments as $i => $comment ) {
    358368        if ( ! empty( $comment->user_id ) ) {
     
    368378
    369379/**
    370  * Filter BP_User_Query::populate_extras to override each queries users fullname
     380 * Filter BP_User_Query::populate_extras to override each queries users fullname.
    371381 *
    372382 * @since 1.7.0
    373383 *
    374  * @param BP_User_Query $user_query
    375  * @param string $user_ids_sql
     384 * @param BP_User_Query $user_query   User query to filter.
     385 * @param string        $user_ids_sql SQL statement to use.
    376386 */
    377387function bp_xprofile_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql = '' ) {
     
    383393    $user_id_names = bp_core_get_user_displaynames( $user_query->user_ids );
    384394
    385     // Loop through names and override each user's fullname
     395    // Loop through names and override each user's fullname.
    386396    foreach ( $user_id_names as $user_id => $user_fullname ) {
    387397        if ( isset( $user_query->results[ $user_id ] ) ) {
     
    397407 * @since 2.2.0
    398408 *
    399  * @param BP_User_Query User query object.
     409 * @param BP_User_Query $q User query object.
    400410 */
    401411function bp_xprofile_add_xprofile_query_to_user_query( BP_User_Query $q ) {
    402412
    403     // Bail if no `xprofile_query` clause
     413    // Bail if no `xprofile_query` clause.
    404414    if ( empty( $q->query_vars['xprofile_query'] ) ) {
    405415        return;
     
    424434 *
    425435 * @param string $q SQL query.
     436 *
    426437 * @return string
    427438 */
     
    439450    $q = preg_replace( $quoted_regex, '__QUOTE__', $q );
    440451
    441     // Get the first word of the command
     452    // Get the first word of the command.
    442453    preg_match( '/^(\S+)/', $q, $first_word_matches );
    443454
     
    446457    }
    447458
    448     // Get the field type
     459    // Get the field type.
    449460    preg_match( '/xprofile_(group|field|data)_id/', $q, $matches );
    450461
  • trunk/src/bp-xprofile/bp-xprofile-functions.php

    r10140 r10163  
    2525 *
    2626 * @param array $args See {@link BP_XProfile_Group::get()} for description of
    27  *        arguments.
     27 *                    arguments.
     28 *
    2829 * @return array $groups
    2930 */
     
    4445
    4546/**
    46  * Insert a new profile field group
     47 * Insert a new profile field group.
    4748 *
    4849 * @since 1.0.0
    4950 *
    50  * @param type $args
     51 * @param array|string $args Array of arguments for field group insertion.
     52 *
    5153 * @return boolean
    5254 */
    5355function xprofile_insert_field_group( $args = '' ) {
    5456
    55     // Parse the arguments
     57    // Parse the arguments.
    5658    $r = bp_parse_args( $args, array(
    5759        'field_group_id' => false,
     
    6163    ), 'xprofile_insert_field_group' );
    6264
    63     // Bail if no group name
     65    // Bail if no group name.
    6466    if ( empty( $r['name'] ) ) {
    6567        return false;
    6668    }
    6769
    68     // Create new field group object, maybe using an existing ID
     70    // Create new field group object, maybe using an existing ID.
    6971    $field_group              = new BP_XProfile_Group( $r['field_group_id'] );
    7072    $field_group->name        = $r['name'];
     
    7678
    7779/**
    78  * Get a specific profile field group
     80 * Get a specific profile field group.
    7981 *
    8082 * @since 1.0.0
    8183 *
    82  * @param int $field_group_id
     84 * @param int $field_group_id Field group ID to fetch.
     85 *
    8386 * @return boolean|BP_XProfile_Group
    8487 */
    8588function xprofile_get_field_group( $field_group_id = 0 ) {
    8689
    87     // Try to get a specific field group by ID
     90    // Try to get a specific field group by ID.
    8891    $field_group = new BP_XProfile_Group( $field_group_id );
    8992
    90     // Bail if group was not found
     93    // Bail if group was not found.
    9194    if ( empty( $field_group->id ) ) {
    9295        return false;
    9396    }
    9497
    95     // Return field group
     98    // Return field group.
    9699    return $field_group;
    97100}
    98101
    99102/**
    100  * Delete a specific profile field group
     103 * Delete a specific profile field group.
    101104 *
    102105 * @since 1.0.0
    103106 *
    104  * @param int $field_group_id
     107 * @param int $field_group_id Field group ID to delete.
     108 *
    105109 * @return boolean
    106110 */
    107111function xprofile_delete_field_group( $field_group_id = 0 ) {
    108112
    109     // Try to get a specific field group by ID
     113    // Try to get a specific field group by ID.
    110114    $field_group = xprofile_get_field_group( $field_group_id );
    111115
    112     // Bail if group was not found
     116    // Bail if group was not found.
    113117    if ( false === $field_group ) {
    114118        return false;
    115119    }
    116120
    117     // Return the results of trying to delete the field group
     121    // Return the results of trying to delete the field group.
    118122    return $field_group->delete();
    119123}
    120124
    121125/**
    122  * Update the position of a specific profile field group
     126 * Update the position of a specific profile field group.
    123127 *
    124128 * @since 1.0.0
    125129 *
    126  * @param int $field_group_id
    127  * @param int $position
    128  * @return bool
     130 * @param int $field_group_id Field group ID to update.
     131 * @param int $position       Field group position to update to.
     132 *
     133 * @return boolean
    129134 */
    130135function xprofile_update_field_group_position( $field_group_id = 0, $position = 0 ) {
     
    132137}
    133138
    134 
    135139/*** Field Management *********************************************************/
    136140
     
    138142 * Get details of all xprofile field types.
    139143 *
     144 * @since 2.0.0
     145 *
    140146 * @return array Key/value pairs (field type => class name).
    141  * @since 2.0.0
    142147 */
    143148function bp_xprofile_get_field_types() {
     
    169174 * Creates the specified field type object; used for validation and templating.
    170175 *
     176 * @since 2.0.0
     177 *
    171178 * @param string $type Type of profile field to create. See {@link bp_xprofile_get_field_types()} for default core values.
    172  * @return object If field type unknown, returns BP_XProfile_Field_Type_Textarea. Otherwise returns an instance of the relevant child class of BP_XProfile_Field_Type.
    173  * @since 2.0.0
     179 *
     180 * @return object $value If field type unknown, returns BP_XProfile_Field_Type_Textarea.
     181 *                       Otherwise returns an instance of the relevant child class of BP_XProfile_Field_Type.
    174182 */
    175183function bp_xprofile_create_field_type( $type ) {
     
    191199 * Insert or update an xprofile field.
    192200 *
    193  * @param array $args {
     201 * @param array|string $args {
    194202 *     Array of arguments.
    195203 *     @type int    $field_id          Optional. Pass the ID of an existing field to edit that field.
     
    231239    ) );
    232240
    233     // field_group_id is required
     241    // Field_group_id is required.
    234242    if ( empty( $r['field_group_id'] ) ) {
    235243        return false;
     
    241249    }
    242250
    243     // Instantiate a new field object
     251    // Instantiate a new field object.
    244252    if ( ! empty( $r['field_id'] ) ) {
    245253        $field = new BP_XProfile_Field( $r['field_id'] );
     
    277285}
    278286
    279 
    280287/*** Field Data Management *****************************************************/
     288
    281289
    282290/**
     
    286294 * each item in the array.
    287295 *
    288  * @package BuddyPress Core
    289  * @param mixed $field         The ID of the field, or the $name of the field.
    290  * @param int $user_id         The ID of the user
     296 * @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed.
     297 *
     298 * @param mixed  $field        The ID of the field, or the $name of the field.
     299 * @param int    $user_id      The ID of the user.
    291300 * @param string $multi_format How should array data be returned? 'comma' if you want a
    292  *                             comma-separated string; 'array' if you want an array
    293  * @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed.
     301 *                             comma-separated string; 'array' if you want an array.
     302 *
    294303 * @return mixed The profile field data.
    295304 */
     
    342351    return $data;
    343352}
    344 
    345353/**
    346354 * A simple function to set profile data for a specific field for a specific user.
    347355 *
    348  * @package BuddyPress Core
    349  * @param int|string $field The ID of the field, or the $name of the field.
    350  * @param int|$user_id      The ID of the user
    351  * @param mixed $value      The value for the field you want to set for the user.
    352  * @param $is_required      Whether or not the field is required
    353  * @uses xprofile_get_field_id_from_name() Gets the ID for the field based on the name.
     356 * @uses xprofile_get_field_id_from_name() Gets the ID from the field based on the name.
     357 *
     358 * @param int|string $field       The ID of the field, or the $name of the field.
     359 * @param int        $user_id     The ID of the user.
     360 * @param mixed      $value       The value for the field you want to set for the user.
     361 * @param bool       $is_required Whether or not the field is required.
     362 *
    354363 * @return bool True on success, false on failure.
    355364 */
     
    378387     * @since 2.1.0
    379388     *
    380      * @param mixed $value Value passed to xprofile_set_field_data()
    381      * @param BP_XProfile_Field $field Field object.
     389     * @param mixed                  $value          Value passed to xprofile_set_field_data().
     390     * @param BP_XProfile_Field      $field          Field object.
    382391     * @param BP_XProfile_Field_Type $field_type_obj Field type object.
    383392     */
    384393    $value = apply_filters( 'bp_xprofile_set_field_data_pre_validate', $value, $field, $field_type_obj );
    385394
    386     // Special-case support for integer 0 for the number field type
     395    // Special-case support for integer 0 for the number field type.
    387396    if ( $is_required && ! is_integer( $value ) && $value !== '0' && ( empty( $value ) || ! is_array( $value ) && ! strlen( trim( $value ) ) ) ) {
    388397        return false;
     
    399408    }
    400409
    401     // If the value is empty, then delete any field data that exists, unless the field is of a type where null values are semantically meaningful
     410    // If the value is empty, then delete any field data that exists, unless the field is of a type
     411    // where null values are semantically meaningful.
    402412    if ( empty( $value ) && ! is_integer( $value ) && $value !== '0' && ! $field_type_obj->accepts_null_value ) {
    403413        xprofile_delete_field_data( $field_id, $user_id );
     
    424434
    425435/**
    426  * Set the visibility level for this field
    427  *
    428  * @param int $field_id The ID of the xprofile field
    429  * @param int $user_id The ID of the user to whom the data belongs
    430  * @param string $visibility_level
     436 * Set the visibility level for this field.
     437 *
     438 * @param int    $field_id         The ID of the xprofile field.
     439 * @param int    $user_id          The ID of the user to whom the data belongs.
     440 * @param string $visibility_level What the visibity setting should be.
     441 *
    431442 * @return bool True on success
    432443 */
     
    436447    }
    437448
    438     // Check against a whitelist
     449    // Check against a whitelist.
    439450    $allowed_values = bp_xprofile_get_visibility_levels();
    440451    if ( !array_key_exists( $visibility_level, $allowed_values ) ) {
     
    442453    }
    443454
    444     // Stored in an array in usermeta
     455    // Stored in an array in usermeta.
    445456    $current_visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true );
    446457
     
    461472 * @param int $field_id The ID of the xprofile field.
    462473 * @param int $user_id The ID of the user to whom the data belongs.
     474 *
    463475 * @return string
    464476 */
     
    473485    $current_level  = isset( $current_levels[ $field_id ] ) ? $current_levels[ $field_id ] : '';
    474486
    475     // Use the user's stored level, unless custom visibility is disabled
     487    // Use the user's stored level, unless custom visibility is disabled.
    476488    $field = new BP_XProfile_Field( $field_id );
    477489    if ( isset( $field->allow_custom_visibility ) && 'disabled' === $field->allow_custom_visibility ) {
     
    490502function xprofile_delete_field_data( $field = '', $user_id = 0 ) {
    491503
    492     // Get the field ID
     504    // Get the field ID.
    493505    if ( is_numeric( $field ) ) {
    494506        $field_id = (int) $field;
     
    497509    }
    498510
    499     // Bail if field or user ID are empty
     511    // Bail if field or user ID are empty.
    500512    if ( empty( $field_id ) || empty( $user_id ) ) {
    501513        return false;
    502514    }
    503515
    504     // Get the profile field data to delete
     516    // Get the profile field data to delete.
    505517    $field = new BP_XProfile_ProfileData( $field_id, $user_id );
    506518
    507     // Delete the field data
     519    // Delete the field data.
    508520    return $field->delete();
    509521}
     
    512524    $field = new BP_Xprofile_Field( $field_id );
    513525
    514     // Define locale variable(s)
     526    // Define locale variable(s).
    515527    $retval = false;
    516528
    517     // Super admins can skip required check
     529    // Super admins can skip required check.
    518530    if ( bp_current_user_can( 'bp_moderate' ) && ! is_admin() ) {
    519531        $retval = false;
    520532
    521     // All other users will use the field's setting
     533    // All other users will use the field's setting.
    522534    } elseif ( isset( $field->is_required ) ) {
    523535        $retval = $field->is_required;
     
    541553 * Fetches a random piece of profile data for the user.
    542554 *
    543  * @package BuddyPress Core
    544  * @param int $user_id User ID of the user to get random data for
    545  * @param bool $exclude_fullname Optional; whether or not to exclude the full name field as random data. Defaults to true.
    546  * @global BuddyPress $bp The one true BuddyPress instance
    547  * @global $wpdb WordPress DB access object.
    548  * @global $current_user WordPress global variable containing current logged in user information
     555 * @global BuddyPress $bp           The one true BuddyPress instance.
     556 * @global object     $wpdb         WordPress DB access object.
     557 * @global object     $current_user WordPress global variable containing current logged in user information.
    549558 * @uses xprofile_format_profile_field() Formats profile field data so it is suitable for display.
     559 *
     560 * @param int  $user_id          User ID of the user to get random data for.
     561 * @param bool $exclude_fullname Optional; whether or not to exclude the full name field as random data.
     562 *                               Defaults to true.
     563 *
    550564 * @return string|bool The fetched random data for the user, or false if no data or no match.
    551565 */
     
    576590 * Formats a profile field according to its type. [ TODO: Should really be moved to filters ]
    577591 *
    578  * @package BuddyPress Core
    579  * @param string $field_type The type of field: datebox, selectbox, textbox etc
    580  * @param string $field_value The actual value
    581  * @return string|bool The formatted value, or false if value is empty
     592 * @param string $field_type  The type of field: datebox, selectbox, textbox etc.
     593 * @param string $field_value The actual value.
     594 *
     595 * @return string|bool The formatted value, or false if value is empty.
    582596 */
    583597function xprofile_format_profile_field( $field_type, $field_value ) {
     
    644658function xprofile_avatar_upload_dir( $directory = 'avatars', $user_id = 0 ) {
    645659
    646     // Use displayed user if no user ID was passed
     660    // Use displayed user if no user ID was passed.
    647661    if ( empty( $user_id ) ) {
    648662        $user_id = bp_displayed_user_id();
    649663    }
    650664
    651     // Failsafe against accidentally nooped $directory parameter
     665    // Failsafe against accidentally nooped $directory parameter.
    652666    if ( empty( $directory ) ) {
    653667        $directory = 'avatars';
     
    682696 * @since 2.0.0
    683697 *
    684  * @param array $sql Clauses in the user_id SQL query.
    685  * @param BP_User_Query User query object.
     698 * @param array         $sql   Clauses in the user_id SQL query.
     699 * @param BP_User_Query $query User query object.
     700 *
     701 * @return array
    686702 */
    687703function bp_xprofile_bp_user_query_search( $sql, BP_User_Query $query ) {
     
    708724
    709725    // Combine the core search (against wp_users) into a single OR clause
    710     // with the xprofile_data search
     726    // with the xprofile_data search.
    711727    $search_xprofile = $wpdb->prepare(
    712728        "u.{$query->uid_name} IN ( SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE %s OR value LIKE %s )",
     
    726742 * Syncs Xprofile data to the standard built in WordPress profile data.
    727743 *
    728  * @package BuddyPress Core
     744 * @param int $user_id ID of the user to sync.
     745 *
     746 * @return bool
    729747 */
    730748function xprofile_sync_wp_profile( $user_id = 0 ) {
    731749
    732     // Bail if profile syncing is disabled
     750    // Bail if profile syncing is disabled.
    733751    if ( bp_disable_profile_sync() ) {
    734752        return true;
     
    771789 *
    772790 * @since 1.2.4
    773  * @package BuddyPress Core
     791 *
     792 * @param object $errors Array of errors. Passed by reference.
     793 * @param bool   $update Whether or not being upated.
     794 * @param object $user   User object whose profile is being synced. Passed by reference.
    774795 */
    775796function xprofile_sync_bp_profile( &$errors, $update, &$user ) {
    776797
    777     // Bail if profile syncing is disabled
     798    // Bail if profile syncing is disabled.
    778799    if ( bp_disable_profile_sync() || ! $update || $errors->get_error_codes() ) {
    779800        return;
     
    790811 * usermeta table that this component uses.
    791812 *
    792  * @package BuddyPress XProfile
    793  * @param int $user_id The ID of the deleted user
     813 * @param int $user_id The ID of the deleted user.
    794814 */
    795815function xprofile_remove_data( $user_id ) {
     
    805825 * Delete a piece of xprofile metadata.
    806826 *
    807  * @param int $object_id ID of the object the metadata belongs to.
    808  * @param string $object_type Type of object. 'group', 'field', or 'data'.
    809  * @param string $meta_key Key of the metadata being deleted. If omitted, all
    810  *        metadata for the object will be deleted.
    811  * @param mixed $meta_value Optional. If provided, only metadata that matches
    812  *        the value will be permitted.
    813  * @param bool $delete_all Optional. If true, delete matching metadata entries
    814  *    for all objects, ignoring the specified object_id. Otherwise, only
    815  *    delete matching metadata entries for the specified object.
    816  *    Default: false.
     827 * @param int         $object_id   ID of the object the metadata belongs to.
     828 * @param string      $object_type Type of object. 'group', 'field', or 'data'.
     829 * @param string|bool $meta_key    Key of the metadata being deleted. If omitted, all
     830 *                                 metadata for the object will be deleted.
     831 * @param mixed       $meta_value  Optional. If provided, only metadata that matches
     832 *                                 the value will be permitted.
     833 * @param bool        $delete_all  Optional. If true, delete matching metadata entries
     834 *                                 for all objects, ignoring the specified object_id. Otherwise, only
     835 *                                 delete matching metadata entries for the specified object.
     836 *                                 Default: false.
     837 *
    817838 * @return bool True on success, false on failure.
    818839 */
     
    820841    global $wpdb;
    821842
    822     // Sanitize object type
     843    // Sanitize object type.
    823844    if ( ! in_array( $object_type, array( 'group', 'field', 'data' ) ) ) {
    824845        return false;
    825846    }
    826847
    827     // Legacy - if no meta_key is passed, delete all for the item
     848    // Legacy - if no meta_key is passed, delete all for the item.
    828849    if ( empty( $meta_key ) ) {
    829850        $table_key  = 'xprofile_' . $object_type . 'meta';
     
    831852        $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$table_name} WHERE object_type = %s AND object_id = %d", $object_type, $object_id ) );
    832853
    833         // Force delete_all to false if deleting all for object
     854        // Force delete_all to false if deleting all for object.
    834855        $delete_all = false;
    835856    } else {
     
    857878 * underlying get_metadata() function. This is for backward compatibility.
    858879 *
    859  * @param int $object_id ID of the object the metadata belongs to.
     880 * @param int    $object_id  ID of the object the metadata belongs to.
    860881 * @param string $object_type Type of object. 'group', 'field', or 'data'.
    861  * @param string $meta_key Key of the metadata being fetched. If omitted, all
    862  *        metadata for the object will be retrieved.
    863  * @param bool $single Optional. If true, return only the first value of the
    864  *    specified meta_key. This parameter has no effect if meta_key is not
    865  *    specified. Default: true.
     882 * @param string $meta_key    Key of the metadata being fetched. If omitted, all
     883 *                            metadata for the object will be retrieved.
     884 * @param bool   $single      Optional. If true, return only the first value of the
     885 *                            specified meta_key. This parameter has no effect if meta_key is not
     886 *                            specified. Default: true.
     887 *
    866888 * @return mixed Meta value if found. False on failure.
    867889 */
    868890function bp_xprofile_get_meta( $object_id, $object_type, $meta_key = '', $single = true ) {
    869     // Sanitize object type
     891    // Sanitize object type.
    870892    if ( ! in_array( $object_type, array( 'group', 'field', 'data' ) ) ) {
    871893        return false;
     
    884906 * Update a piece of xprofile metadata.
    885907 *
    886  * @param int $object_id ID of the object the metadata belongs to.
     908 * @param int    $object_id  ID of the object the metadata belongs to.
    887909 * @param string $object_type Type of object. 'group', 'field', or 'data'.
    888  * @param string $meta_key Key of the metadata being updated.
    889  * @param mixed $meta_value Value of the metadata being updated.
    890  * @param mixed $prev_value Optional. If specified, only update existing
    891  *        metadata entries with the specified value. Otherwise, update all
    892  *        entries.
     910 * @param string $meta_key    Key of the metadata being updated.
     911 * @param mixed  $meta_value  Value of the metadata being updated.
     912 * @param mixed  $prev_value  Optional. If specified, only update existing
     913 *                            metadata entries with the specified value.
     914 *                            Otherwise update all entries.
     915 *
    893916 * @return bool|int Returns false on failure. On successful update of existing
    894  *         metadata, returns true. On successful creation of new metadata,
    895  *         returns the integer ID of the new metadata row.
     917 *                  metadata, returns true. On successful creation of new metadata,
     918 *                  returns the integer ID of the new metadata row.
    896919 */
    897920function bp_xprofile_update_meta( $object_id, $object_type, $meta_key, $meta_value, $prev_value = '' ) {
     
    910933 * @since 2.0.0
    911934 *
    912  * @param int $object_id ID of the object the metadata belongs to.
     935 * @param int    $object_id  ID of the object the metadata belongs to.
    913936 * @param string $object_type Type of object. 'group', 'field', or 'data'.
    914  * @param string $meta_key Metadata key.
    915  * @param mixed $meta_value Metadata value.
    916  * @param bool $unique Optional. Whether to enforce a single metadata value
    917  *        for the given key. If true, and the object already has a value for
    918  *        the key, no change will be made. Default: false.
     937 * @param string $meta_key    Metadata key.
     938 * @param mixed  $meta_value  Metadata value.
     939 * @param bool   $unique      Optional. Whether to enforce a single metadata value
     940 *                            for the given key. If true, and the object already
     941 *                            has a value for the key, no change will be made.
     942 *                            Default false.
     943 *
    919944 * @return int|bool The meta ID on successful update, false on failure.
    920945 */
     
    964989
    965990/**
    966  * Return the field name for the Full Name xprofile field
     991 * Return the field name for the Full Name xprofile field.
    967992 *
    968993 * @package BuddyPress
    969994 * @since 1.5.0
    970995 *
    971  * @return string The field name
     996 * @return string The field name.
    972997 */
    973998function bp_xprofile_fullname_field_name() {
     
    9841009
    9851010/**
    986  * Get visibility levels out of the $bp global
     1011 * Get visibility levels out of the $bp global.
    9871012 *
    9881013 * @return array
     
    10011026
    10021027/**
    1003  * Get the ids of fields that are hidden for this displayed/loggedin user pair
     1028 * Get the ids of fields that are hidden for this displayed/loggedin user pair.
    10041029 *
    10051030 * This is the function primarily responsible for profile field visibility. It works by determining
     
    10111036 * @see BP_XProfile_Group::get()
    10121037 * @uses apply_filters() Filter bp_xprofile_get_hidden_fields_for_user to modify visibility levels,
    1013  *   or if you have added your own custom levels
    1014  *
    1015  * @param int $displayed_user_id The id of the user the profile fields belong to
    1016  * @param int $current_user_id The id of the user viewing the profile
     1038 *   or if you have added your own custom levels.
     1039 *
     1040 * @param int $displayed_user_id The id of the user the profile fields belong to.
     1041 * @param int $current_user_id   The id of the user viewing the profile.
     1042 *
    10171043 * @return array An array of field ids that should be excluded from the profile query
    10181044 */
     
    10471073
    10481074/**
    1049  * Get the visibility levels that should be hidden for this user pair
     1075 * Get the visibility levels that should be hidden for this user pair.
    10501076 *
    10511077 * Field visibility is determined based on the relationship between the
     
    10581084 * @see bp_xprofile_get_hidden_fields_for_user()
    10591085 *
    1060  * @param int $displayed_user_id The id of the user the profile fields belong to
    1061  * @param int $current_user_id The id of the user viewing the profile
    1062  * @return array An array of visibility levels hidden to the current user
     1086 * @param int $displayed_user_id The id of the user the profile fields belong to.
     1087 * @param int $current_user_id   The id of the user viewing the profile.
     1088 *
     1089 * @return array An array of visibility levels hidden to the current user.
    10631090 */
    10641091function bp_xprofile_get_hidden_field_types_for_user( $displayed_user_id = 0, $current_user_id = 0 ) {
    10651092
    1066     // Current user is logged in
     1093    // Current user is logged in.
    10671094    if ( ! empty( $current_user_id ) ) {
    10681095
    10691096        // Nothing's private when viewing your own profile, or when the
    1070         // current user is an admin
     1097        // current user is an admin.
    10711098        if ( $displayed_user_id == $current_user_id || bp_current_user_can( 'bp_moderate' ) ) {
    10721099            $hidden_levels = array();
    10731100
    1074         // If the current user and displayed user are friends, show all
     1101        // If the current user and displayed user are friends, show all.
    10751102        } elseif ( bp_is_active( 'friends' ) && friends_check_friendship( $displayed_user_id, $current_user_id ) ) {
    10761103            $hidden_levels = array( 'adminsonly', );
    10771104
    1078         // current user is logged in but not friends, so exclude friends-only
     1105        // Current user is logged in but not friends, so exclude friends-only.
    10791106        } else {
    10801107            $hidden_levels = array( 'friends', 'adminsonly', );
     
    10991126
    11001127/**
    1101  * Fetch an array of the xprofile fields that a given user has marked with certain visibility levels
     1128 * Fetch an array of the xprofile fields that a given user has marked with certain visibility levels.
    11021129 *
    11031130 * @since 1.6.0
    11041131 * @see bp_xprofile_get_hidden_fields_for_user()
    11051132 *
    1106  * @param int $user_id The id of the profile owner
    1107  * @param array $levels An array of visibility levels ('public', 'friends', 'loggedin', 'adminsonly' etc) to be
    1108  *    checked against
    1109  * @return array $field_ids The fields that match the requested visibility levels for the given user
     1133 * @param int   $user_id The id of the profile owner.
     1134 * @param array $levels  An array of visibility levels ('public', 'friends', 'loggedin', 'adminsonly' etc) to be
     1135 *                       checked against.
     1136 *
     1137 * @return array $field_ids The fields that match the requested visibility levels for the given user.
    11101138 */
    11111139function bp_xprofile_get_fields_by_visibility_levels( $user_id, $levels = array() ) {
     
    11171145
    11181146    // Parse the user-provided visibility levels with the default levels, which may take
    1119     // precedence
     1147    // precedence.
    11201148    $default_visibility_levels = BP_XProfile_Group::fetch_default_visibility_levels();
    11211149
    11221150    foreach( (array) $default_visibility_levels as $d_field_id => $defaults ) {
    11231151        // If the admin has forbidden custom visibility levels for this field, replace
    1124         // the user-provided setting with the default specified by the admin
     1152        // the user-provided setting with the default specified by the admin.
    11251153        if ( isset( $defaults['allow_custom'] ) && isset( $defaults['default'] ) && 'disabled' == $defaults['allow_custom'] ) {
    11261154            $user_visibility_levels[$d_field_id] = $defaults['default'];
     
    11351163    }
    11361164
    1137     // Never allow the fullname field to be excluded
     1165    // Never allow the fullname field to be excluded.
    11381166    if ( in_array( 1, $field_ids ) ) {
    11391167        $key = array_search( 1, $field_ids );
  • trunk/src/bp-xprofile/bp-xprofile-loader.php

    r10157 r10163  
    1616
    1717    /**
    18      * Profile field types
     18     * Profile field types.
    1919     *
    2020     * @since 1.5.0
     
    3333
    3434    /**
    35      * Start the xprofile component creation process
     35     * Start the xprofile component creation process.
    3636     *
    3737     * @since 1.5.0
     
    5151
    5252    /**
    53      * Include files
     53     * Include files.
     54     *
     55     * @param array $includes
    5456     */
    5557    public function includes( $includes = array() ) {
     
    7678
    7779    /**
    78      * Setup globals
     80     * Setup globals.
    7981     *
    8082     * The BP_XPROFILE_SLUG constant is deprecated, and only used here for
     
    8284     *
    8385     * @since 1.5.0
     86     *
     87     * @param array $args Array of globals to set up.
    8488     */
    8589    public function setup_globals( $args = array() ) {
    8690        $bp = buddypress();
    8791
    88         // Define a slug, if necessary
     92        // Define a slug, if necessary.
    8993        if ( !defined( 'BP_XPROFILE_SLUG' ) ) {
    9094            define( 'BP_XPROFILE_SLUG', 'profile' );
     
    9397        // Assign the base group and fullname field names to constants
    9498        // to use in SQL statements.
    95         // Defined conditionally to accommodate unit tests
     99        // Defined conditionally to accommodate unit tests.
    96100        if ( ! defined( 'BP_XPROFILE_BASE_GROUP_NAME' ) ) {
    97101            define( 'BP_XPROFILE_BASE_GROUP_NAME', stripslashes( bp_core_get_root_option( 'avatar_default' ) ) );
     
    113117        // 'option' is a special case. It is not a top-level field, so
    114118        // does not have an associated BP_XProfile_Field_Type class,
    115         // but it must be whitelisted
     119        // but it must be whitelisted.
    116120        $this->field_types[] = 'option';
    117121
    118         // Register the visibility levels. See bp_xprofile_get_visibility_levels() to filter
     122        // Register the visibility levels. See bp_xprofile_get_visibility_levels() to filter.
    119123        $this->visibility_levels = array(
    120124            'public' => array(
     
    139143        }
    140144
    141         // Tables
     145        // Tables.
    142146        $global_tables = array(
    143147            'table_name_data'   => $bp->table_prefix . 'bp_xprofile_data',
     
    168172     *
    169173     * @global BuddyPress $bp The one true BuddyPress instance
     174     *
     175     * @param array $main_nav Array of main nav items to set up.
     176     * @param array $sub_nav  Array of sub nav items to set up.
    170177     */
    171178    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    172179
    173         // Determine user to use
     180        // Determine user to use.
    174181        if ( bp_displayed_user_domain() ) {
    175182            $user_domain = bp_displayed_user_domain();
     
    184191        $profile_link = trailingslashit( $user_domain . $slug );
    185192
    186         // Add 'Profile' to the main navigation
     193        // Add 'Profile' to the main navigation.
    187194        $main_nav = array(
    188195            'name'                => _x( 'Profile', 'Profile header menu', 'buddypress' ),
     
    194201        );
    195202
    196         // Add the subnav items to the profile
     203        // Add the subnav items to the profile.
    197204        $sub_nav[] = array(
    198205            'name'            => _x( 'View', 'Profile header sub menu', 'buddypress' ),
     
    204211        );
    205212
    206         // Edit Profile
     213        // Edit Profile.
    207214        $sub_nav[] = array(
    208215            'name'            => _x( 'Edit','Profile header sub menu', 'buddypress' ),
     
    215222        );
    216223
    217         // Change Avatar
     224        // Change Avatar.
    218225        if ( buddypress()->avatar->show_avatars ) {
    219226            $sub_nav[] = array(
     
    242249
    243250        // The Settings > Profile nav item can only be set up after
    244         // the Settings component has run its own nav routine
     251        // the Settings component has run its own nav routine.
    245252        add_action( 'bp_settings_setup_nav', array( $this, 'setup_settings_nav' ) );
    246253
     
    261268        }
    262269
    263         // Determine user to use
     270        // Determine user to use.
    264271        if ( bp_displayed_user_domain() ) {
    265272            $user_domain = bp_displayed_user_domain();
     
    270277        }
    271278
    272         // Get the settings slug
     279        // Get the settings slug.
    273280        $settings_slug = bp_get_settings_slug();
    274281
     
    285292
    286293    /**
    287      * Set up the Toolbar
     294     * Set up the Admin Bar.
     295     *
     296     * @param array $wp_admin_nav Admin Bar items.
    288297     */
    289298    public function setup_admin_bar( $wp_admin_nav = array() ) {
    290299
    291         // Menus for logged in user
     300        // Menus for logged in user.
    292301        if ( is_user_logged_in() ) {
    293302
    294             // Profile link
     303            // Profile link.
    295304            $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
    296305
    297             // Add the "Profile" sub menu
     306            // Add the "Profile" sub menu.
    298307            $wp_admin_nav[] = array(
    299308                'parent' => buddypress()->my_account_menu_id,
     
    303312            );
    304313
    305             // View Profile
     314            // View Profile.
    306315            $wp_admin_nav[] = array(
    307316                'parent' => 'my-account-' . $this->id,
     
    311320            );
    312321
    313             // Edit Profile
     322            // Edit Profile.
    314323            $wp_admin_nav[] = array(
    315324                'parent' => 'my-account-' . $this->id,
     
    319328            );
    320329
    321             // Edit Avatar
     330            // Edit Avatar.
    322331            if ( buddypress()->avatar->show_avatars ) {
    323332                $wp_admin_nav[] = array(
     
    352361
    353362    /**
    354      * Sets up the title for pages and <title>
     363     * Sets up the title for pages and <title>.
    355364     */
    356365    public function setup_title() {
     
    375384
    376385    /**
    377      * Setup cache groups
     386     * Setup cache groups.
    378387     *
    379388     * @since 2.2.0
     
    381390    public function setup_cache_groups() {
    382391
    383         // Global groups
     392        // Global groups.
    384393        wp_cache_add_global_groups( array(
    385394            'bp_xprofile',
     
    398407     *
    399408     * @param array $wp_admin_nav The settings adminbar nav array.
     409     *
    400410     * @return array
    401411     */
    402412    public function setup_settings_admin_nav( $wp_admin_nav ) {
    403413
    404         // Setup the logged in user variables
     414        // Setup the logged in user variables.
    405415        $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
    406416
    407         // Add the "Profile" subnav item
     417        // Add the "Profile" subnav item.
    408418        $wp_admin_nav[] = array(
    409419            'parent' => 'my-account-' . buddypress()->settings->id,
  • trunk/src/bp-xprofile/bp-xprofile-screens.php

    r10157 r10163  
    1717 * Handles the display of the profile page by loading the correct template file.
    1818 *
    19  * @package BuddyPress XProfile
    20  * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
     19 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename).
    2120 */
    2221function xprofile_screen_display_profile() {
     
    4645 * Also checks to make sure this can only be accessed for the logged in users profile.
    4746 *
    48  * @package BuddyPress XProfile
    49  * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
    50  * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
     47 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user.
     48 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename).
    5149 */
    5250function xprofile_screen_edit_profile() {
     
    6159    }
    6260
    63     // Check the field group exists
     61    // Check the field group exists.
    6462    if ( ! bp_is_action_variable( 'group' ) || ! xprofile_get_field_group( bp_action_variable( 1 ) ) ) {
    6563        bp_do_404();
     
    6765    }
    6866
    69     // No errors
     67    // No errors.
    7068    $errors = false;
    7169
    72     // Check to see if any new information has been submitted
     70    // Check to see if any new information has been submitted.
    7371    if ( isset( $_POST['field_ids'] ) ) {
    7472
    75         // Check the nonce
     73        // Check the nonce.
    7674        check_admin_referer( 'bp_xprofile_edit' );
    7775
    78         // Check we have field ID's
     76        // Check we have field ID's.
    7977        if ( empty( $_POST['field_ids'] ) ) {
    8078            bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . bp_action_variable( 1 ) ) );
     
    8280
    8381        // Explode the posted field IDs into an array so we know which
    84         // fields have been submitted
     82        // fields have been submitted.
    8583        $posted_field_ids = wp_parse_id_list( $_POST['field_ids'] );
    8684        $is_required      = array();
    8785
    8886        // Loop through the posted fields formatting any datebox values
    89         // then validate the field
     87        // then validate the field.
    9088        foreach ( (array) $posted_field_ids as $field_id ) {
    9189            if ( !isset( $_POST['field_' . $field_id] ) ) {
    9290
    9391                if ( !empty( $_POST['field_' . $field_id . '_day'] ) && !empty( $_POST['field_' . $field_id . '_month'] ) && !empty( $_POST['field_' . $field_id . '_year'] ) ) {
    94                     // Concatenate the values
     92                    // Concatenate the values.
    9593                    $date_value =   $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
    9694
    97                     // Turn the concatenated value into a timestamp
     95                    // Turn the concatenated value into a timestamp.
    9896                    $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) );
    9997                }
     
    107105        }
    108106
    109         // There are errors
     107        // There are errors.
    110108        if ( !empty( $errors ) ) {
    111109            bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' );
    112110
    113         // No errors
     111        // No errors.
    114112        } else {
    115113
    116             // Reset the errors var
     114            // Reset the errors var.
    117115            $errors = false;
    118116
     
    128126                // Save the old and new values. They will be
    129127                // passed to the filter and used to determine
    130                 // whether an activity item should be posted
     128                // whether an activity item should be posted.
    131129                $old_values[ $field_id ] = array(
    132130                    'value'      => xprofile_get_field_data( $field_id, bp_displayed_user_id() ),
     
    134132                );
    135133
    136                 // Update the field data and visibility level
     134                // Update the field data and visibility level.
    137135                xprofile_set_field_visibility_level( $field_id, bp_displayed_user_id(), $visibility_level );
    138136                $field_updated = xprofile_set_field_data( $field_id, bp_displayed_user_id(), $value, $is_required[ $field_id ] );
     
    173171            do_action( 'xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors, $old_values, $new_values );
    174172
    175             // Set the feedback messages
     173            // Set the feedback messages.
    176174            if ( !empty( $errors ) ) {
    177175                bp_core_add_message( __( 'There was a problem updating some of your profile information. Please try again.', 'buddypress' ), 'error' );
     
    180178            }
    181179
    182             // Redirect back to the edit screen to display the updates and message
     180            // Redirect back to the edit screen to display the updates and message.
    183181            bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . bp_action_variable( 1 ) ) );
    184182        }
     
    205203 * Handles the uploading and cropping of a user avatar. Displays the change avatar page.
    206204 *
    207  * @package BuddyPress XProfile
    208  * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
    209  * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
     205 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user.
     206 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename).
    210207 */
    211208function xprofile_screen_change_avatar() {
    212209
    213     // Bail if not the correct screen
     210    // Bail if not the correct screen.
    214211    if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
    215212        return false;
    216213    }
    217214
    218     // Bail if there are action variables
     215    // Bail if there are action variables.
    219216    if ( bp_action_variables() ) {
    220217        bp_do_404();
     
    232229    if ( !empty( $_FILES ) ) {
    233230
    234         // Check the nonce
     231        // Check the nonce.
    235232        check_admin_referer( 'bp_avatar_upload' );
    236233
    237         // Pass the file to the avatar upload handler
     234        // Pass the file to the avatar upload handler.
    238235        if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) {
    239236            $bp->avatar_admin->step = 'crop-image';
    240237
    241             // Make sure we include the jQuery jCrop file for image cropping
     238            // Make sure we include the jQuery jCrop file for image cropping.
    242239            add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
    243240        }
    244241    }
    245242
    246     // If the image cropping is done, crop the image and save a full/thumb version
     243    // If the image cropping is done, crop the image and save a full/thumb version.
    247244    if ( isset( $_POST['avatar-crop-submit'] ) ) {
    248245
    249         // Check the nonce
     246        // Check the nonce.
    250247        check_admin_referer( 'bp_avatar_cropstore' );
    251248
     
    268265             * @since 1.1.0
    269266             * @since 2.3.4 Add two new parameters to inform about the user id and
    270              *              about the way the avatar was set (eg: 'crop' or 'camera')
     267             *              about the way the avatar was set (eg: 'crop' or 'camera').
    271268             *
    272              * @param string $item_id Inform about the user id the avatar was set for
    273              * @param string $value Inform about the way the avatar was set ('crop')
     269             * @param string $item_id Inform about the user id the avatar was set for.
     270             * @param string $value   Inform about the way the avatar was set ('crop').
    274271             */
    275272            do_action( 'xprofile_avatar_uploaded', (int) $args['item_id'], 'crop' );
     
    328325
    329326/**
    330  * Show the xprofile settings template
     327 * Show the xprofile settings template.
    331328 *
    332329 * @since 2.0.0
     
    334331function bp_xprofile_screen_settings() {
    335332
    336     // Redirect if no privacy settings page is accessible
     333    // Redirect if no privacy settings page is accessible.
    337334    if ( bp_action_variables() || ! bp_is_active( 'xprofile' ) ) {
    338335        bp_do_404();
  • trunk/src/bp-xprofile/bp-xprofile-settings.php

    r10140 r10163  
    1111
    1212/**
    13  * Query all profile fields and their visibility data for display in settings
     13 * Query all profile fields and their visibility data for display in settings.
    1414 *
    1515 * @since 2.0.0
    1616 *
    17  * @param array $args
     17 * @param array|string $args Array of args for the settings fields.
    1818 *
    1919 * @return array
     
    2121function bp_xprofile_get_settings_fields( $args = '' ) {
    2222
    23     // Parse the possible arguments
     23    // Parse the possible arguments.
    2424    $r = bp_parse_args( $args, array(
    2525        'user_id'                => bp_displayed_user_id(),
     
    3838
    3939/**
    40  * Adds feedback messages when successfully saving profile field settings
     40 * Adds feedback messages when successfully saving profile field settings.
    4141 *
    4242 * @since 2.0.0
     
    4747function bp_xprofile_settings_add_feedback_message() {
    4848
    49     // Default message type is success
     49    // Default message type is success.
    5050    $type    = 'success';
    5151    $message = __( 'Your profile settings have been saved.',        'buddypress' );
    5252
    53     // Community moderator editing another user's settings
     53    // Community moderator editing another user's settings.
    5454    if ( ! bp_is_my_profile() && bp_core_can_edit_settings() ) {
    5555        $message = __( "This member's profile settings have been saved.", 'buddypress' );
    5656    }
    5757
    58     // Add the message
     58    // Add the message.
    5959    bp_core_add_message( $message, $type );
    6060}
  • trunk/src/bp-xprofile/bp-xprofile-template.php

    r10140 r10163  
    116116     * @since 2.4.0 Introduced `$member_type` argument.
    117117     *
    118      * @param array $args {
     118     * @param array|string $args {
    119119     *     An array of arguments. All items are optional.
    120120     *
     
    134134    public function __construct( $args = '' ) {
    135135
    136         // Backward compatibility with old method of passing arguments
     136        // Backward compatibility with old method of passing arguments.
    137137        if ( ! is_array( $args ) || func_num_args() > 1 ) {
    138138            _deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     
    224224            do_action( 'xprofile_template_loop_end' );
    225225
    226             // Do some cleaning up after the loop
     226            // Do some cleaning up after the loop.
    227227            $this->rewind_groups();
    228228        }
     
    238238        $group = $this->next_group();
    239239
    240         // loop has just started
     240        // Loop has just started.
    241241        if ( 0 === $this->current_group ) {
    242242
     
    285285            return true;
    286286        } elseif ( $this->current_field + 1 == $this->field_count ) {
    287             // Do some cleaning up after the loop
     287            // Do some cleaning up after the loop.
    288288            $this->rewind_fields();
    289289        }
     
    297297        $field = $this->next_field();
    298298
    299         // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731
     299        // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731.
    300300        if ( ! empty( $field->data ) && ( ! empty( $field->data->value ) || ( '0' === $field->data->value ) ) ) {
    301301            $value = maybe_unserialize( $field->data->value );
     
    313313
    314314/**
    315  * Query for XProfile groups and fields
     315 * Query for XProfile groups and fields.
    316316 *
    317317 * @since 1.0.0
     
    320320 * @see BP_XProfile_Group::get() for full description of `$args` array.
    321321 *
    322  * @param array $args {
     322 * @param array|string $args {
    323323 *     Array of arguments. See BP_XProfile_Group::get() for full description. Those arguments whose defaults differ
    324324 *     from that method are described here:
     
    339339
    340340    // Only show empty fields if we're on the Dashboard, or we're on a user's
    341     // profile edit page, or this is a registration page
     341    // profile edit page, or this is a registration page.
    342342    $hide_empty_fields_default = ( ! is_network_admin() && ! is_admin() && ! bp_is_user_profile_edit() && ! bp_is_register_page() );
    343343
    344     // We only need to fetch visibility levels when viewing your own profile
     344    // We only need to fetch visibility levels when viewing your own profile.
    345345    if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) || bp_is_register_page() ) {
    346346        $fetch_visibility_level_default = true;
     
    349349    }
    350350
    351     // Parse arguments
     351    // Parse arguments.
    352352    $r = bp_parse_args( $args, array(
    353353        'user_id'                => bp_displayed_user_id(),
     
    359359        'fetch_field_data'       => true,
    360360        'fetch_visibility_level' => $fetch_visibility_level_default,
    361         'exclude_groups'         => false, // Comma-separated list of profile field group IDs to exclude
    362         'exclude_fields'         => false, // Comma-separated list of profile field IDs to exclude
     361        'exclude_groups'         => false, // Comma-separated list of profile field group IDs to exclude.
     362        'exclude_fields'         => false, // Comma-separated list of profile field IDs to exclude.
    363363        'update_meta_cache'      => true,
    364364    ), 'has_profile' );
    365365
    366     // Populate the template loop global
     366    // Populate the template loop global.
    367367    $profile_template = new BP_XProfile_Data_Template( $r );
    368368
     
    405405        }
    406406
    407         // Set a class with the field ID
     407        // Set a class with the field ID.
    408408        $css_classes[] = 'field_' . $profile_template->field->id;
    409409
    410         // Set a class with the field name (sanitized)
     410        // Set a class with the field name (sanitized).
    411411        $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name );
    412412
    413         // Set a class indicating whether the field is required or optional
     413        // Set a class indicating whether the field is required or optional.
    414414        if ( ! empty( $profile_template->field->is_required ) ) {
    415415            $css_classes[] = 'required-field';
     
    418418        }
    419419
    420         // Add the field visibility level
     420        // Add the field visibility level.
    421421        $css_classes[] = 'visibility-' . esc_attr( bp_get_the_profile_field_visibility_level() );
    422422
     
    531531        global $group;
    532532
    533         // Build the form action URL
     533        // Build the form action URL.
    534534        $form_action = trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . $group->id );
    535535
     
    750750
    751751/**
    752  * Returns the action name for any signup errors related to this profile field
     752 * Returns the action name for any signup errors related to this profile field.
    753753 *
    754754 * In the registration templates, signup errors are pulled from the global
     
    759759 *
    760760 * @since 1.8.0
    761  * @return string The _errors action name corresponding to this profile field
     761 *
     762 * @return string The _errors action name corresponding to this profile field.
    762763 */
    763764function bp_get_the_profile_field_errors_action() {
     
    767768
    768769/**
    769  * bp_the_profile_field_options()
    770  *
    771770 * Displays field options HTML for field types of 'selectbox', 'multiselectbox',
    772771 * 'radio', 'checkbox', and 'datebox'.
    773772 *
    774  * @package BuddyPress Xprofile
    775773 * @since 1.1.0
    776774 *
     
    783781}
    784782    /**
    785      * bp_get_the_profile_field_options()
    786      *
    787783     * Retrieves field options HTML for field types of 'selectbox', 'multiselectbox', 'radio', 'checkbox', and 'datebox'.
    788784     *
    789      * @package BuddyPress Xprofile
    790785     * @since 1.1.0
    791786     *
     
    795790     * @param array $args {
    796791     *     Array of optional arguments.
    797      *     @type string|bool $type Type of datebox. False if it's not a
    798      *           datebox, otherwise 'day, 'month', or 'year'. Default: false.
    799      *     @type int $user_id ID of the user whose profile values should be
    800      *           used when rendering options. Default: displayed user.
     792     *     @type string|bool $type    Type of datebox. False if it's not a
     793     *                                datebox, otherwise 'day, 'month', or 'year'. Default: false.
     794     *     @type int         $user_id ID of the user whose profile values should be
     795     *                                used when rendering options. Default: displayed user.
    801796     * }
     797     *
     798     * @return string $vaue Field options markup.
    802799     */
    803800    function bp_get_the_profile_field_options( $args = array() ) {
     
    839836        global $field;
    840837
    841         // Define locale variable(s)
     838        // Define locale variable(s).
    842839        $retval = false;
    843840
    844         // Super admins can skip required check
     841        // Super admins can skip required check.
    845842        if ( bp_current_user_can( 'bp_moderate' ) && !is_admin() ) {
    846843            $retval = false;
    847844
    848         // All other users will use the field's setting
     845        // All other users will use the field's setting.
    849846        } elseif ( isset( $field->is_required ) ) {
    850847            $retval = $field->is_required;
     
    862859
    863860/**
    864  * Echo the visibility level of this field
     861 * Echo the visibility level of this field.
    865862 */
    866863function bp_the_profile_field_visibility_level() {
     
    868865}
    869866    /**
    870      * Return the visibility level of this field
     867     * Return the visibility level of this field.
    871868     */
    872869    function bp_get_the_profile_field_visibility_level() {
     
    875872        // On the registration page, values stored in POST should take
    876873        // precedence over default visibility, so that submitted values
    877         // are not lost on failure
     874        // are not lost on failure.
    878875        if ( bp_is_register_page() && ! empty( $_POST['field_' . $field->id . '_visibility'] ) ) {
    879876            $retval = esc_attr( $_POST['field_' . $field->id . '_visibility'] );
     
    893890
    894891/**
    895  * Echo the visibility level label of this field
     892 * Echo the visibility level label of this field.
    896893 */
    897894function bp_the_profile_field_visibility_level_label() {
     
    899896}
    900897    /**
    901      * Return the visibility level label of this field
     898     * Return the visibility level label of this field.
    902899     */
    903900    function bp_get_the_profile_field_visibility_level_label() {
     
    906903        // On the registration page, values stored in POST should take
    907904        // precedence over default visibility, so that submitted values
    908         // are not lost on failure
     905        // are not lost on failure.
    909906        if ( bp_is_register_page() && ! empty( $_POST['field_' . $field->id . '_visibility'] ) ) {
    910907            $level = esc_html( $_POST['field_' . $field->id . '_visibility'] );
     
    959956 * Get all profile field groups.
    960957 *
    961  * @since  2.1.0
     958 * @since 2.1.0
    962959 *
    963960 * @return object $groups
     
    984981 * Check if there is more than one group of fields for the profile being edited.
    985982 *
    986  * @since  2.1.0
     983 * @since 2.1.0
    987984 *
    988985 * @return bool True if there is more than one profile field group.
     
    10051002 *
    10061003 * @since 1.0.0
    1007  *
    1008  * @return string Field group tabs markup.
    10091004 */
    10101005function bp_profile_group_tabs() {
     
    10211016
    10221017/**
    1023  * Return the XProfile group tabs
     1018 * Return the XProfile group tabs.
    10241019 *
    10251020 * @since 2.3.0
     
    10291024function bp_get_profile_group_tabs() {
    10301025
    1031     // Get field group data
     1026    // Get field group data.
    10321027    $groups     = bp_profile_get_field_groups();
    10331028    $group_name = bp_get_profile_group_name();
    10341029    $tabs       = array();
    10351030
    1036     // Loop through field groups and put a tab-lst together
     1031    // Loop through field groups and put a tab-lst together.
    10371032    for ( $i = 0, $count = count( $groups ); $i < $count; ++$i ) {
    10381033
    1039         // Setup the selected class
     1034        // Setup the selected class.
    10401035        $selected = '';
    10411036        if ( $group_name === $groups[ $i ]->name ) {
     
    10431038        }
    10441039
    1045         // Skip if group has no fields
     1040        // Skip if group has no fields.
    10461041        if ( empty( $groups[ $i ]->fields ) ) {
    10471042            continue;
    10481043        }
    10491044
    1050         // Build the profile field group link
     1045        // Build the profile field group link.
    10511046        $link   = trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . $groups[ $i ]->id );
    10521047
    1053         // Add tab to end of tabs array
     1048        // Add tab to end of tabs array.
    10541049        $tabs[] = sprintf(
    10551050            '<li %1$s><a href="%2$s">%3$s</a></li>',
     
    10831078    function bp_get_profile_group_name() {
    10841079
    1085         // Check action variable
     1080        // Check action variable.
    10861081        $group_id = bp_action_variable( 1 );
    10871082        if ( empty( $group_id ) || ! is_numeric( $group_id ) ) {
     
    10891084        }
    10901085
    1091         // Check for cached group
     1086        // Check for cached group.
    10921087        $group = new BP_XProfile_Group( $group_id );
    10931088
     
    11431138         * Filters the current profile group ID.
    11441139         *
    1145          * Possible values are admin/profile/edit/[group-id]
     1140         * Possible values are admin/profile/edit/[group-id].
    11461141         *
    11471142         * @since 1.1.0
     
    11831178
    11841179/**
    1185  * Echo the field visibility radio buttons
     1180 * Echo the field visibility radio buttons.
     1181 *
     1182 * @param array|string $args Args for the radio buttons.
    11861183 */
    11871184function bp_profile_visibility_radio_buttons( $args = '' ) {
     
    11891186}
    11901187    /**
    1191      * Return the field visibility radio buttons
     1188     * Return the field visibility radio buttons.
     1189     *
     1190     * @param array|string $args Args for the radio buttons.
     1191     *
     1192     * @return string $retval
    11921193     */
    11931194    function bp_profile_get_visibility_radio_buttons( $args = '' ) {
    11941195
    1195         // Parse optional arguments
     1196        // Parse optional arguments.
    11961197        $r = bp_parse_args( $args, array(
    11971198            'field_id'     => bp_get_the_profile_field_id(),
     
    12031204        ), 'xprofile_visibility_radio_buttons' );
    12041205
    1205         // Empty return value, filled in below if a valid field ID is found
     1206        // Empty return value, filled in below if a valid field ID is found.
    12061207        $retval = '';
    12071208
    1208         // Only do-the-do if there's a valid field ID
     1209        // Only do-the-do if there's a valid field ID.
    12091210        if ( ! empty( $r['field_id'] ) ) :
    12101211
    1211             // Start the output buffer
     1212            // Start the output buffer.
    12121213            ob_start();
    12131214
    1214             // Output anything before
     1215            // Output anything before.
    12151216            echo $r['before']; ?>
    12161217
     
    12321233            <?php endif;
    12331234
    1234             // Output anything after
     1235            // Output anything after.
    12351236            echo $r['after'];
    12361237
    1237             // Get the output buffer and empty it
     1238            // Get the output buffer and empty it.
    12381239            $retval = ob_get_clean();
    12391240        endif;
     
    12521253
    12531254/**
    1254  * Output the XProfile field visibility select list for settings
     1255 * Output the XProfile field visibility select list for settings.
    12551256 *
    12561257 * @since 2.0.0
     1258 *
     1259 * @param array|string $args Args for the select list.
    12571260 */
    12581261function bp_profile_settings_visibility_select( $args = '' ) {
     
    12601263}
    12611264    /**
    1262      * Return the XProfile field visibility select list for settings
     1265     * Return the XProfile field visibility select list for settings.
    12631266     *
    12641267     * @since 2.0.0
     1268     *
     1269     * @param array|string $args Args for the select list.
     1270     *
     1271     * @return string $retval
    12651272     */
    12661273    function bp_profile_get_settings_visibility_select( $args = '' ) {
    12671274
    1268         // Parse optional arguments
     1275        // Parse optional arguments.
    12691276        $r = bp_parse_args( $args, array(
    12701277            'field_id' => bp_get_the_profile_field_id(),
     
    12741281        ), 'xprofile_settings_visibility_select' );
    12751282
    1276         // Empty return value, filled in below if a valid field ID is found
     1283        // Empty return value, filled in below if a valid field ID is found.
    12771284        $retval = '';
    12781285
    1279         // Only do-the-do if there's a valid field ID
     1286        // Only do-the-do if there's a valid field ID.
    12801287        if ( ! empty( $r['field_id'] ) ) :
    12811288
    1282             // Start the output buffer
     1289            // Start the output buffer.
    12831290            ob_start();
    12841291
    1285             // Output anything before
     1292            // Output anything before.
    12861293            echo $r['before']; ?>
    12871294
     
    13051312            <?php endif;
    13061313
    1307             // Output anything after
     1314            // Output anything after.
    13081315            echo $r['after'];
    13091316
    1310             // Get the output buffer and empty it
     1317            // Get the output buffer and empty it.
    13111318            $retval = ob_get_clean();
    13121319        endif;
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-checkbox.php

    r10140 r10163  
    1818
    1919    /**
    20      * Constructor for the checkbox field type
     20     * Constructor for the checkbox field type.
    2121     *
    2222     * @since 2.0.0
    23      */
     23     */
    2424    public function __construct() {
    2525        parent::__construct();
     
    5050     * Must be used inside the {@link bp_profile_fields()} template loop.
    5151     *
    52      * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.checkbox.html permitted attributes} that you want to add.
    5352     * @since 2.0.0
     53     *
     54     * @param array $raw_properties Optional key/value array of
     55     *                              {@link http://dev.w3.org/html5/markup/input.checkbox.html permitted attributes}
     56     *                              that you want to add.
    5457     */
    5558    public function edit_field_html( array $raw_properties = array() ) {
    5659
    57         // user_id is a special optional parameter that we pass to
     60        // User_id is a special optional parameter that we pass to
    5861        // {@link bp_the_profile_field_options()}.
    5962        if ( isset( $raw_properties['user_id'] ) ) {
     
    97100     * Must be used inside the {@link bp_profile_fields()} template loop.
    98101     *
     102     * @since 2.0.0
     103     *
    99104     * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
    100      * @since 2.0.0
    101105     */
    102106    public function edit_field_options_html( array $args = array() ) {
     
    108112
    109113        // Check for updated posted values, but errors preventing them from
    110         // being saved first time
     114        // being saved first time.
    111115        if ( isset( $_POST['field_' . $this->field_obj->id] ) && $option_values != maybe_serialize( $_POST['field_' . $this->field_obj->id] ) ) {
    112116            if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) {
     
    118122            $selected = '';
    119123
    120             // First, check to see whether the user's saved values match the option
     124            // First, check to see whether the user's saved values match the option.
    121125            for ( $j = 0, $count_values = count( $option_values ); $j < $count_values; ++$j ) {
    122126
    123127                // Run the allowed option name through the before_save filter,
    124                 // so we'll be sure to get a match
     128                // so we'll be sure to get a match.
    125129                $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    126130
     
    132136
    133137            // If the user has not yet supplied a value for this field, check to
    134             // see whether there is a default value available
     138            // see whether there is a default value available.
    135139            if ( empty( $option_values ) && empty( $selected ) && ! empty( $options[$k]->is_default_option ) ) {
    136140                $selected = ' checked="checked"';
     
    167171     * Must be used inside the {@link bp_profile_fields()} template loop.
    168172     *
     173     * @since 2.0.0
     174     *
    169175     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    170      * @since 2.0.0
    171176     */
    172177    public function admin_field_html( array $raw_properties = array() ) {
     
    179184     * Must be used inside the {@link bp_profile_fields()} template loop.
    180185     *
     186     * @since 2.0.0
     187     *
    181188     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    182      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    183      * @since 2.0.0
     189     * @param string            $control_type  Optional. HTML input type used to render the current
     190     *                                         field's child options.
    184191     */
    185192    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php

    r10140 r10163  
    1818
    1919    /**
    20      * Constructor for the datebox field type
    21      *
    22      * @since 2.0.0
    23      */
     20     * Constructor for the datebox field type.
     21     *
     22     * @since 2.0.0
     23     */
    2424    public function __construct() {
    2525        parent::__construct();
     
    4646     * Must be used inside the {@link bp_profile_fields()} template loop.
    4747     *
    48      * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.html permitted attributes} that you want to add.
    49      * @since 2.0.0
     48     * @since 2.0.0
     49     *
     50     * @param array $raw_properties Optional key/value array of
     51     *                              {@link http://dev.w3.org/html5/markup/input.html permitted attributes}
     52     *                              that you want to add.
    5053     */
    5154    public function edit_field_html( array $raw_properties = array() ) {
    5255
    53         // user_id is a special optional parameter that we pass to
     56        // User_id is a special optional parameter that we pass to.
    5457        // {@link bp_the_profile_field_options()}.
    5558        if ( isset( $raw_properties['user_id'] ) ) {
     
    128131     * Must be used inside the {@link bp_profile_fields()} template loop.
    129132     *
     133     * @since 2.0.0
     134     *
    130135     * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
    131      * @since 2.0.0
    132136     */
    133137    public function edit_field_options_html( array $args = array() ) {
     
    140144        $eng_months = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
    141145
    142         // Set day, month, year defaults
     146        // Set day, month, year defaults.
    143147        if ( ! empty( $date ) ) {
    144148
    145             // If Unix timestamp
     149            // If Unix timestamp.
    146150            if ( is_numeric( $date ) ) {
    147151                $day   = date( 'j', $date );
     
    149153                $year  = date( 'Y', $date );
    150154
    151             // If MySQL timestamp
     155            // If MySQL timestamp.
    152156            } else {
    153157                $day   = mysql2date( 'j', $date );
    154                 $month = mysql2date( 'F', $date, false ); // Not localized, so that selected() works below
     158                $month = mysql2date( 'F', $date, false ); // Not localized, so that selected() works below.
    155159                $year  = mysql2date( 'Y', $date );
    156160            }
     
    179183        }
    180184
    181         // $type will be passed by calling function when needed
     185        // $type will be passed by calling function when needed.
    182186        switch ( $args['type'] ) {
    183187            case 'day':
     
    242246     * Must be used inside the {@link bp_profile_fields()} template loop.
    243247     *
     248     * @since 2.0.0
     249     *
    244250     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    245      * @since 2.0.0
    246251     */
    247252    public function admin_field_html( array $raw_properties = array() ) {
     
    281286     * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out.
    282287     *
     288     * @since 2.0.0
     289     *
    283290     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    284      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    285      * @since 2.0.0
     291     * @param string            $control_type  Optional. HTML input type used to render the current
     292     *                                         field's child options.
    286293     */
    287294    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
     
    293300     *
    294301     * @param string $field_value The date value, as saved in the database.
    295      *        Typically, this is a MySQL-formatted date string (Y-m-d H:i:s).
     302     *                            Typically, this is a MySQL-formatted date
     303     *                            string (Y-m-d H:i:s).
     304     *
    296305     * @return string Date formatted by bp_format_time().
    297306     */
    298307    public static function display_filter( $field_value ) {
    299308
    300         // If Unix timestamp
     309        // If Unix timestamp.
    301310        if ( ! is_numeric( $field_value ) ) {
    302311            $field_value = strtotime( $field_value );
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-multiselectbox.php

    r10140 r10163  
    1818
    1919    /**
    20      * Constructor for the multi-selectbox field type
    21      *
    22      * @since 2.0.0
    23      */
     20     * Constructor for the multi-selectbox field type.
     21     *
     22     * @since 2.0.0
     23     */
    2424    public function __construct() {
    2525        parent::__construct();
     
    5050     * Must be used inside the {@link bp_profile_fields()} template loop.
    5151     *
    52      * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/select.html permitted attributes} that you want to add.
    53      * @since 2.0.0
     52     * @since 2.0.0
     53     *
     54     * @param array $raw_properties Optional key/value array of
     55     *                              {@link http://dev.w3.org/html5/markup/select.html permitted attributes}
     56     *                              that you want to add.
    5457     */
    5558    public function edit_field_html( array $raw_properties = array() ) {
    5659
    57         // user_id is a special optional parameter that we pass to
     60        // User_id is a special optional parameter that we pass to
    5861        // {@link bp_the_profile_field_options()}.
    5962        if ( isset( $raw_properties['user_id'] ) ) {
     
    104107     * Must be used inside the {@link bp_profile_fields()} template loop.
    105108     *
     109     * @since 2.0.0
     110     *
    106111     * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
    107      * @since 2.0.0
    108112     */
    109113    public function edit_field_options_html( array $args = array() ) {
     
    122126
    123127            // Check for updated posted values, but errors preventing them from
    124             // being saved first time
     128            // being saved first time.
    125129            foreach( $option_values as $i => $option_value ) {
    126130                if ( isset( $_POST['field_' . $this->field_obj->id] ) && $_POST['field_' . $this->field_obj->id][$i] != $option_value ) {
     
    132136
    133137            // Run the allowed option name through the before_save filter, so
    134             // we'll be sure to get a match
     138            // we'll be sure to get a match.
    135139            $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    136140
    137             // First, check to see whether the user-entered value matches
     141            // First, check to see whether the user-entered value matches.
    138142            if ( in_array( $allowed_options, $option_values ) ) {
    139143                $selected = ' selected="selected"';
    140144            }
    141145
    142             // Then, if the user has not provided a value, check for defaults
     146            // Then, if the user has not provided a value, check for defaults.
    143147            if ( ! is_array( $original_option_values ) && empty( $option_values ) && ! empty( $options[$k]->is_default_option ) ) {
    144148                $selected = ' selected="selected"';
     
    167171     * Must be used inside the {@link bp_profile_fields()} template loop.
    168172     *
     173     * @since 2.0.0
     174     *
    169175     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    170      * @since 2.0.0
    171176     */
    172177    public function admin_field_html( array $raw_properties = array() ) {
     
    183188
    184189    /**
    185      * Output HTML for this field type's children options on the wp-admin Profile Fields "Add Field" and "Edit Field" screens.
    186      *
    187      * Must be used inside the {@link bp_profile_fields()} template loop.
     190     * Output HTML for this field type's children options on the wp-admin Profile Fields,
     191     * "Add Field" and "Edit Field" screens.
     192     *
     193     * Must be used inside the {@link bp_profile_fields()} template loop.
     194     *
     195     * @since 2.0.0
    188196     *
    189197     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    190      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    191      * @since 2.0.0
     198     * @param string            $control_type  Optional. HTML input type used to render the current
     199     *                                         field's child options.
    192200     */
    193201    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-number.php

    r10142 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
     
    1818
    1919    /**
    20      * Constructor for the number field type
     20     * Constructor for the number field type.
    2121     *
    2222     * @since 2.0.0
    23      */
     23     */
    2424    public function __construct() {
    2525        parent::__construct();
     
    4646     * Must be used inside the {@link bp_profile_fields()} template loop.
    4747     *
    48      * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes} that you want to add.
    4948     * @since 2.0.0
     49     *
     50     * @param array $raw_properties Optional key/value array of
     51     *                              {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes}
     52     *                              that you want to add.
    5053     */
    5154    public function edit_field_html( array $raw_properties = array() ) {
    5255
    53         // user_id is a special optional parameter that certain other fields
     56        // User_id is a special optional parameter that certain other fields
    5457        // types pass to {@link bp_the_profile_field_options()}.
    5558        if ( isset( $raw_properties['user_id'] ) ) {
     
    8487     * Must be used inside the {@link bp_profile_fields()} template loop.
    8588     *
     89     * @since 2.0.0
     90     *
    8691     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    87      * @since 2.0.0
    8892     */
    8993    public function admin_field_html( array $raw_properties = array() ) {
     
    100104     * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out.
    101105     *
     106     * @since 2.0.0
     107     *
    102108     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    103      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    104      * @since 2.0.0
     109     * @param string            $control_type  Optional. HTML input type used to render the current
     110     *                                         field's child options.
    105111     */
    106112    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-placeholder.php

    r10142 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
     
    3131     * Prevent any HTML being output for this field type.
    3232     *
    33      * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.text.html permitted attributes} that you want to add.
    3433     * @since 2.0.1
     34     *
     35     * @param array $raw_properties Optional key/value array of
     36     *                              {@link http://dev.w3.org/html5/markup/input.text.html permitted attributes}
     37     *                              that you want to add.
    3538     */
    3639    public function edit_field_html( array $raw_properties = array() ) {
     
    4043     * Prevent any HTML being output for this field type.
    4144     *
     45     * @since 2.0.1
     46     *
    4247     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    43      * @since 2.0.1
    4448     */
    4549    public function admin_field_html( array $raw_properties = array() ) {
     
    4953     * Prevent any HTML being output for this field type.
    5054     *
     55     * @since 2.0.1
     56     *
    5157     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    52      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    53      * @since 2.0.1
     58     * @param string            $control_type  Optional. HTML input type used to render the current
     59     *                                         field's child options.
    5460     */
    5561    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-radiobutton.php

    r10142 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
     
    77 */
    88
    9 // Exit if accessed directly
     9// Exit if accessed directly.
    1010defined( 'ABSPATH' ) || exit;
    1111
     
    2121     *
    2222     * @since 2.0.0
    23      */
     23     */
    2424    public function __construct() {
    2525        parent::__construct();
     
    4848     * Must be used inside the {@link bp_profile_fields()} template loop.
    4949     *
    50      * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.radio.html permitted attributes} that you want to add.
    5150     * @since 2.0.0
     51     *
     52     * @param array $raw_properties Optional key/value array of
     53     *                              {@link http://dev.w3.org/html5/markup/input.radio.html permitted attributes}
     54     *                              that you want to add.
    5255     */
    5356    public function edit_field_html( array $raw_properties = array() ) {
    5457
    55         // user_id is a special optional parameter that we pass to
     58        // User_id is a special optional parameter that we pass to
    5659        // {@link bp_the_profile_field_options()}.
    5760        if ( isset( $raw_properties['user_id'] ) ) {
     
    102105     * Must be used inside the {@link bp_profile_fields()} template loop.
    103106     *
     107     * @since 2.0.0
     108     *
    104109     * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
    105      * @since 2.0.0
    106110     */
    107111    public function edit_field_options_html( array $args = array() ) {
     
    114118
    115119            // Check for updated posted values, but errors preventing them from
    116             // being saved first time
     120            // being saved first time.
    117121            if ( isset( $_POST['field_' . $this->field_obj->id] ) && $option_value != $_POST['field_' . $this->field_obj->id] ) {
    118122                if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) {
     
    122126
    123127            // Run the allowed option name through the before_save filter, so
    124             // we'll be sure to get a match
     128            // we'll be sure to get a match.
    125129            $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    126130            $selected        = '';
     
    160164     * Must be used inside the {@link bp_profile_fields()} template loop.
    161165     *
     166     * @since 2.0.0
     167     *
    162168     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    163      * @since 2.0.0
    164169     */
    165170    public function admin_field_html( array $raw_properties = array() ) {
     
    182187     * Must be used inside the {@link bp_profile_fields()} template loop.
    183188     *
     189     * @since 2.0.0
     190     *
    184191     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    185      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    186      * @since 2.0.0
     192     * @param string            $control_type  Optional. HTML input type used to render the current
     193     *                                         field's child options.
    187194     */
    188195    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-selectbox.php

    r10142 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
     
    1818
    1919    /**
    20      * Constructor for the selectbox field type
     20     * Constructor for the selectbox field type.
    2121     *
    2222     * @since 2.0.0
    23      */
     23     */
    2424    public function __construct() {
    2525        parent::__construct();
     
    4848     * Must be used inside the {@link bp_profile_fields()} template loop.
    4949     *
    50      * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/select.html permitted attributes} that you want to add.
    5150     * @since 2.0.0
     51     *
     52     * @param array $raw_properties Optional key/value array of
     53     *                              {@link http://dev.w3.org/html5/markup/select.html permitted attributes}
     54     *                              that you want to add.
    5255     */
    5356    public function edit_field_html( array $raw_properties = array() ) {
    5457
    55         // user_id is a special optional parameter that we pass to
     58        // User_id is a special optional parameter that we pass to
    5659        // {@link bp_the_profile_field_options()}.
    5760        if ( isset( $raw_properties['user_id'] ) ) {
     
    9295     * Must be used inside the {@link bp_profile_fields()} template loop.
    9396     *
     97     * @since 2.0.0
     98     *
    9499     * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
    95      * @since 2.0.0
    96100     */
    97101    public function edit_field_options_html( array $args = array() ) {
     
    110114
    111115            // Check for updated posted values, but errors preventing them from
    112             // being saved first time
     116            // being saved first time.
    113117            foreach( $option_values as $i => $option_value ) {
    114118                if ( isset( $_POST['field_' . $this->field_obj->id] ) && $_POST['field_' . $this->field_obj->id] != $option_value ) {
     
    120124
    121125            // Run the allowed option name through the before_save filter, so
    122             // we'll be sure to get a match
     126            // we'll be sure to get a match.
    123127            $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    124128
    125             // First, check to see whether the user-entered value matches
     129            // First, check to see whether the user-entered value matches.
    126130            if ( in_array( $allowed_options, $option_values ) ) {
    127131                $selected = ' selected="selected"';
    128132            }
    129133
    130             // Then, if the user has not provided a value, check for defaults
     134            // Then, if the user has not provided a value, check for defaults.
    131135            if ( ! is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option ) {
    132136                $selected = ' selected="selected"';
     
    155159     * Must be used inside the {@link bp_profile_fields()} template loop.
    156160     *
     161     * @since 2.0.0
     162     *
    157163     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    158      * @since 2.0.0
    159164     */
    160165    public function admin_field_html( array $raw_properties = array() ) {
     
    173178     * Must be used inside the {@link bp_profile_fields()} template loop.
    174179     *
     180     * @since 2.0.0
     181     *
    175182     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    176      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    177      * @since 2.0.0
     183     * @param string            $control_type  Optional. HTML input type used to render the current
     184     *                                         field's child options.
    178185     */
    179186    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-textarea.php

    r10142 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
     
    1818
    1919    /**
    20      * Constructor for the textarea field type
     20     * Constructor for the textarea field type.
    2121     *
    2222     * @since 2.0.0
    23      */
     23     */
    2424    public function __construct() {
    2525        parent::__construct();
     
    4646     * Must be used inside the {@link bp_profile_fields()} template loop.
    4747     *
    48      * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/textarea.html permitted attributes} that you want to add.
    4948     * @since 2.0.0
     49     *
     50     * @param array $raw_properties Optional key/value array of
     51     *                              {@link http://dev.w3.org/html5/markup/textarea.html permitted attributes}
     52     *                              that you want to add.
    5053     */
    5154    public function edit_field_html( array $raw_properties = array() ) {
    5255
    53         // user_id is a special optional parameter that certain other fields
     56        // User_id is a special optional parameter that certain other fields
    5457        // types pass to {@link bp_the_profile_field_options()}.
    5558        if ( isset( $raw_properties['user_id'] ) ) {
     
    8487     * Must be used inside the {@link bp_profile_fields()} template loop.
    8588     *
     89     * @since 2.0.0
     90     *
    8691     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    87      * @since 2.0.0
    8892     */
    8993    public function admin_field_html( array $raw_properties = array() ) {
     
    102106     * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out.
    103107     *
     108     * @since 2.0.0
     109     *
    104110     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    105      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    106      * @since 2.0.0
     111     * @param string            $control_type  Optional. HTML input type used to render the current
     112     *                                         field's child options.
    107113     */
    108114    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-textbox.php

    r10142 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
     
    1818
    1919    /**
    20      * Constructor for the textbox field type
     20     * Constructor for the textbox field type.
    2121     *
    2222     * @since 2.0.0
    23      */
     23     */
    2424    public function __construct() {
    2525        parent::__construct();
     
    4343    /**
    4444     * Output the edit field HTML for this field type.
    45      *
    4645     * Must be used inside the {@link bp_profile_fields()} template loop.
    4746     *
    48      * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.text.html permitted attributes} that you want to add.
    4947     * @since 2.0.0
     48     *
     49     * @param array $raw_properties Optional key/value array of
     50     *                              {@link http://dev.w3.org/html5/markup/input.text.html permitted attributes}
     51     *                              that you want to add.
    5052     */
    5153    public function edit_field_html( array $raw_properties = array() ) {
    5254
    53         // user_id is a special optional parameter that certain other fields
     55        // User_id is a special optional parameter that certain other fields
    5456        // types pass to {@link bp_the_profile_field_options()}.
    5557        if ( isset( $raw_properties['user_id'] ) ) {
     
    8486     * Must be used inside the {@link bp_profile_fields()} template loop.
    8587     *
     88     * @since 2.0.0
     89     *
    8690     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    87      * @since 2.0.0
    8891     */
    8992    public function admin_field_html( array $raw_properties = array() ) {
     
    102105     * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out.
    103106     *
     107     * @since 2.0.0
     108     *
    104109     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    105      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    106      * @since 2.0.0
     110     * @param string            $control_type  Optional. HTML input type used to render the
     111     *                                         current field's child options.
    107112     */
    108113    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-url.php

    r10142 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
     
    4747     *
    4848     * @param array $raw_properties Optional key/value array of
    49      *        {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes}
    50      *        that you want to add.
     49     *                              {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes}
     50     *                              that you want to add.
     51     *
    5152     * @since 2.1.0
    5253     */
     
    8889     *
    8990     * @param array $raw_properties Optional key/value array of permitted
    90      *        attributes that you want to add.
     91     *                              attributes that you want to add.
    9192     * @since 2.1.0
    9293     */
     
    107108     * for this field type, we don't want it, so it's stubbed out.
    108109     *
     110     * @since 2.1.0
     111     *
    109112     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    110      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    111      * @since 2.1.0
     113     * @param string            $control_type  Optional. HTML input type used to render the current
     114     *                                         field's child options.
    112115     */
    113116    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
     
    126129     *
    127130     * @param string $submitted_value Raw value submitted by the user.
     131     *
    128132     * @return string
    129133     */
    130134    public static function pre_validate_filter( $submitted_value = '' ) {
    131135
    132         // Allow empty URL values
     136        // Allow empty URL values.
    133137        if ( empty( $submitted_value ) ) {
    134138            return '';
    135139        }
    136140
    137         // Run some checks on the submitted value
     141        // Run some checks on the submitted value.
    138142        if ( false === strpos( $submitted_value, ':'  )
    139143             && substr( $submitted_value, 0, 1 ) !== '/'
     
    153157     *
    154158     * @param string $field_value The URL value, as saved in the database.
     159     *
    155160     * @return string URL converted to a link.
    156161     */
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type.php

    r10142 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
     
    77 */
    88
    9 // Exit if accessed directly
     9// Exit if accessed directly.
    1010defined( 'ABSPATH' ) || exit;
    1111
     
    1818
    1919    /**
    20      * @since 2.0.0
    21      * @var array Field type validation regexes
     20     * Validation regex rules for field type.
     21
     22     * @since 2.0.0
     23     * @var array Field type validation regexes.
    2224     */
    2325    protected $validation_regex = array();
    2426
    2527    /**
    26      * @since 2.0.0
    27      * @var array Field type whitelisted values
     28     * Whitelisted values for field type.
     29     *
     30     * @since 2.0.0
     31     * @var array Field type whitelisted values.
    2832     */
    2933    protected $validation_whitelist = array();
    3034
    3135    /**
    32      * @since 2.0.0
    33      * @var string The name of this field type
     36     * Name for field type.
     37     *
     38     * @since 2.0.0
     39     * @var string The name of this field type.
    3440     */
    3541    public $name = '';
     
    4450
    4551    /**
     52     * If allowed to store null/empty values.
     53     *
    4654     * @since 2.0.0
    4755     * @var bool If this is set, allow BP to store null/empty values for this field type.
     
    5866
    5967    /**
     68     * If allowed to support multiple options as default.
     69     *
    6070     * @since 2.0.0
    6171     * @var bool Does this field type support multiple options being set as default values? e.g. multiselectbox, checkbox.
     
    6474
    6575    /**
    66      * @since 2.0.0
    67      * @var BP_XProfile_Field If this object is created by instantiating a {@link BP_XProfile_Field}, this is a reference back to that object.
     76     * If object is created by an BP_XProfile_Field object.
     77     *
     78     * @since 2.0.0
     79     * @var BP_XProfile_Field If this object is created by instantiating a {@link BP_XProfile_Field},
     80     *                        this is a reference back to that object.
    6881     */
    6982    public $field_obj = null;
    7083
    7184    /**
    72      * Constructor
     85     * Constructor.
    7386     *
    7487     * @since 2.0.0
     
    93106     * it's successful as long as the new value matches any one of the registered formats.
    94107     *
    95      * @param string $format Regex string
    96      * @param string $replace_format Optional; if 'replace', replaces the format instead of adding to it. Defaults to 'add'.
     108     * @since 2.0.0
     109     *
     110     * @param string $format         Regex string.
     111     * @param string $replace_format Optional; if 'replace', replaces the format instead of adding to it.
     112     *                               Defaults to 'add'.
     113     *
    97114     * @return BP_XProfile_Field_Type
    98      * @since 2.0.0
    99115     */
    100116    public function set_format( $format, $replace_format = 'add' ) {
     
    127143     * it's successful as long as the new value matches any one of the registered formats.
    128144     *
    129      * @param string|array $values
     145     * @since 2.0.0
     146     *
     147     * @param string|array $values Whitelisted values.
     148     *
    130149     * @return BP_XProfile_Field_Type
    131      * @since 2.0.0
    132150     */
    133151    public function set_whitelist_values( $values ) {
     
    154172     * This method doesn't support chaining.
    155173     *
    156      * @param string|array $values Value to check against the registered formats
     174     * @since 2.0.0
     175     *
     176     * @param string|array $values Value to check against the registered formats.
     177     *
    157178     * @return bool True if the value validates
    158      * @since 2.0.0
    159179     */
    160180    public function is_valid( $values ) {
    161181        $validated = false;
    162182
    163         // Some types of field (e.g. multi-selectbox) may have multiple values to check
     183        // Some types of field (e.g. multi-selectbox) may have multiple values to check.
    164184        foreach ( (array) $values as $value ) {
    165185
     
    176196        }
    177197
    178         // Handle field types with accepts_null_value set if $values is an empty array
     198        // Handle field types with accepts_null_value set if $values is an empty array.
    179199        if ( ( false === $validated ) && is_array( $values ) && empty( $values ) && $this->accepts_null_value ) {
    180200            $validated = true;
     
    205225     * Must be used inside the {@link bp_profile_fields()} template loop.
    206226     *
     227     * @since 2.0.0
     228     *
    207229     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    208      * @since 2.0.0
    209230     */
    210231    abstract public function edit_field_html( array $raw_properties = array() );
     232
     233    /**
     234     * Output HTML for this field type on the wp-admin Profile Fields screen.
     235     *
     236     * Must be used inside the {@link bp_profile_fields()} template loop.
     237     *
     238     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
     239     * @since 2.0.0
     240     */
     241    abstract public function admin_field_html( array $raw_properties = array() );
    211242
    212243    /**
     
    222253     * Must be used inside the {@link bp_profile_fields()} template loop.
    223254     *
     255     * @since 2.0.0
     256     *
    224257     * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
    225      * @since 2.0.0
    226258     */
    227259    public function edit_field_options_html( array $args = array() ) {}
    228 
    229     /**
    230      * Output HTML for this field type on the wp-admin Profile Fields screen.
    231      *
    232      * Must be used inside the {@link bp_profile_fields()} template loop.
    233      *
    234      * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
    235      * @since 2.0.0
    236      */
    237     abstract public function admin_field_html( array $raw_properties = array() );
    238260
    239261    /**
     
    246268     * Must be used inside the {@link bp_profile_fields()} template loop.
    247269     *
     270     * @since 2.0.0
     271     *
    248272     * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    249      * @param string $control_type Optional. HTML input type used to render the current field's child options.
    250      * @since 2.0.0
     273     * @param string            $control_type  Optional. HTML input type used to render the current
     274     *                          field's child options.
    251275     */
    252276    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {
     
    295319                        }
    296320
    297                         // Grab the values from $_POST to use as the form's options
     321                        // Grab the values from $_POST to use as the form's options.
    298322                        $options[] = (object) array(
    299323                            'id'                => -1,
     
    315339                }
    316340
    317                 // Render the markup for the children options
     341                // Render the markup for the children options.
    318342                if ( ! empty( $options ) ) {
    319343                    $default_name = '';
     
    385409     * @since 2.1.0
    386410     *
    387      * @param mixed $submitted_value Submitted value.
     411     * @param mixed $field_value Submitted field value.
     412     *
    388413     * @return mixed
    389414     */
     
    402427     *
    403428     * @param mixed $field_value Field value.
     429     *
    404430     * @return mixed
    405431     */
     
    416442     * This method was intended to be static but couldn't be because php.net/lsb/ requires PHP >= 5.3.
    417443     *
     444     * @since 2.0.0
     445     *
    418446     * @param array $properties Optional key/value array of attributes for this edit field.
     447     *
    419448     * @return string
    420      * @since 2.0.0
    421449     */
    422450    protected function get_edit_field_html_elements( array $properties = array() ) {
     
    431459        }
    432460
    433         $html = '';
    434 
    435461        /**
    436462         * Filters the edit html elements and attributes.
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php

    r10160 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
     
    1313
    1414    /**
     15     * Field ID.
     16     *
    1517     * @since 1.0.0
    1618     *
    17      * @var int ID of field
     19     * @var int ID of field.
    1820     */
    1921    public $id;
    2022
    2123    /**
     24     * Field group ID.
     25     *
    2226     * @since 1.0.0
    2327     *
    24      * @var int Field group ID for field
     28     * @var int Field group ID for field.
    2529     */
    2630    public $group_id;
    2731
    2832    /**
     33     * Field parent ID.
     34     *
    2935     * @since 1.0.0
    3036     *
    31      * @var int Parent ID of field
     37     * @var int Parent ID of field.
    3238     */
    3339    public $parent_id;
    3440
    3541    /**
     42     * Field type.
     43     *
    3644     * @since 1.0.0
    3745     *
    38      * @var string Field type
     46     * @var string Field type.
    3947     */
    4048    public $type;
    4149
    4250    /**
     51     * Field name.
     52     *
    4353     * @since 1.0.0
    4454     *
    45      * @var string Field name
     55     * @var string Field name.
    4656     */
    4757    public $name;
    4858
    4959    /**
     60     * Field description.
     61     *
    5062     * @since 1.0.0
    5163     *
    52      * @var string Field description
     64     * @var string Field description.
    5365     */
    5466    public $description;
    5567
    5668    /**
     69     * Required field?
     70     *
    5771     * @since 1.0.0
    5872     *
     
    6276
    6377    /**
     78     * Deletable field?
     79     *
    6480     * @since 1.0.0
    6581     *
     
    6985
    7086    /**
     87     * Field position.
     88     *
    7189     * @since 1.0.0
    7290     *
    73      * @var int Field position
     91     * @var int Field position.
    7492     */
    7593    public $field_order;
    7694
    7795    /**
     96     * Option order.
     97     *
    7898     * @since 1.0.0
    7999     *
    80      * @var int Option order
     100     * @var int Option order.
    81101     */
    82102    public $option_order;
    83103
    84104    /**
     105     * Order child fields.
     106     *
    85107     * @since 1.0.0
    86108     *
    87      * @var string Order child fields by
     109     * @var string Order child fields by.
    88110     */
    89111    public $order_by;
    90112
    91113    /**
     114     * Is this the default option?
     115     *
    92116     * @since 1.0.0
    93117     *
     
    97121
    98122    /**
     123     * Field data visibility.
     124     *
    99125     * @since 1.9.0
    100126     *
    101      * @var string Default field data visibility
     127     * @var string Default field data visibility.
    102128     */
    103129    public $default_visibility = 'public';
    104130
    105131    /**
     132     * Is the visibility able to be modified?
     133     *
    106134     * @since 2.3.0
    107135     *
    108      * @var string Members are allowed/disallowed to modify data visibility
     136     * @var string Members are allowed/disallowed to modify data visibility.
    109137     */
    110138    public $allow_custom_visibility = 'allowed';
    111139
    112140    /**
     141     * Field type option.
     142     *
    113143     * @since 2.0.0
    114144     *
    115      * @var BP_XProfile_Field_Type Field type object used for validation
     145     * @var BP_XProfile_Field_Type Field type object used for validation.
    116146     */
    117147    public $type_obj = null;
    118148
    119149    /**
     150     * Field data for user ID.
     151     *
    120152     * @since 2.0.0
    121153     *
    122      * @var BP_XProfile_ProfileData Field data for user ID
     154     * @var BP_XProfile_ProfileData Field data for user ID.
    123155     */
    124156    public $data;
     
    134166
    135167    /**
    136      * Initialize and/or populate profile field
     168     * Initialize and/or populate profile field.
    137169     *
    138170     * @since 1.1.0
    139171     *
    140      * @param int  $id
    141      * @param int  $user_id
    142      * @param bool $get_data
     172     * @param int|null $id Field ID.
     173     * @param int|null $user_id User ID.
     174     * @param bool     $get_data Get data.
    143175     */
    144176    public function __construct( $id = null, $user_id = null, $get_data = true ) {
     
    147179            $this->populate( $id, $user_id, $get_data );
    148180
    149         // Initialise the type obj to prevent fatals when creating new profile fields
     181        // Initialise the type obj to prevent fatals when creating new profile fields.
    150182        } else {
    151183            $this->type_obj            = bp_xprofile_create_field_type( 'textbox' );
     
    155187
    156188    /**
    157      * Populate a profile field object
     189     * Populate a profile field object.
    158190     *
    159191     * @since 1.1.0
     
    162194     * @global object $userdata
    163195     *
    164      * @param  int    $id
    165      * @param  int    $user_id
    166      * @param  bool   $get_data
     196     * @param int  $id Field ID.
     197     * @param int  $user_id User ID.
     198     * @param bool $get_data Get data.
    167199     */
    168200    public function populate( $id, $user_id = null, $get_data = true ) {
     
    198230            }
    199231
    200             // Get metadata for field
     232            // Get metadata for field.
    201233            $default_visibility       = bp_xprofile_get_meta( $id, 'field', 'default_visibility'      );
    202234            $allow_custom_visibility  = bp_xprofile_get_meta( $id, 'field', 'allow_custom_visibility' );
    203235
    204             // Setup default visibility
     236            // Setup default visibility.
    205237            $this->default_visibility = ! empty( $default_visibility )
    206238                ? $default_visibility
    207239                : 'public';
    208240
    209             // Allow members to customize visibilty
     241            // Allow members to customize visibilty.
    210242            $this->allow_custom_visibility = ( 'disabled' === $allow_custom_visibility )
    211243                ? 'disabled'
     
    215247
    216248    /**
    217      * Delete a profile field
     249     * Delete a profile field.
    218250     *
    219251     * @since 1.1.0
    220252     *
    221      * @global object  $wpdb
    222      * @param  boolean $delete_data
     253     * @global object $wpdb
     254     *
     255     * @param boolean $delete_data Whether or not to delete data.
     256     *
    223257     * @return boolean
    224258     */
     
    226260        global $wpdb;
    227261
    228         // Prevent deletion if no ID is present
     262        // Prevent deletion if no ID is present.
    229263        // Prevent deletion by url when can_delete is false.
    230264        // Prevent deletion of option 1 since this invalidates fields with options.
     
    240274        }
    241275
    242         // delete the data in the DB for this field
     276        // Delete the data in the DB for this field.
    243277        if ( true === $delete_data ) {
    244278            BP_XProfile_ProfileData::delete_for_field( $this->id );
     
    249283
    250284    /**
    251      * Save a profile field
     285     * Save a profile field.
    252286     *
    253287     * @since 1.1.0
     
    281315         * @since 1.0.0
    282316         *
    283          * @param BP_XProfile_Field Current instance of the field being saved.
     317         * @param BP_XProfile_Field $this Current instance of the field being saved.
    284318         */
    285319        do_action_ref_array( 'xprofile_field_before_save', array( $this ) );
     
    303337            }
    304338
    305             // Only do this if we are editing an existing field
     339            // Only do this if we are editing an existing field.
    306340            if ( ! $is_new_field ) {
    307341
     
    379413             * @since 1.0.0
    380414             *
    381              * @param BP_XProfile_Field Current instance of the field being saved.
     415             * @param BP_XProfile_Field $this Current instance of the field being saved.
    382416             */
    383417            do_action_ref_array( 'xprofile_field_after_save', array( $this ) );
     
    394428
    395429    /**
    396      * Get field data for a user ID
     430     * Get field data for a user ID.
    397431     *
    398432     * @since 1.2.0
    399433     *
    400      * @param  int $user_id
     434     * @param int $user_id ID of the user to get field data for.
     435     *
    401436     * @return object
    402437     */
     
    406441
    407442    /**
    408      * Get all child fields for this field ID
     443     * Get all child fields for this field ID.
    409444     *
    410445     * @since 1.2.0
     
    412447     * @global object $wpdb
    413448     *
    414      * @param  bool  $for_editing
     449     * @param bool $for_editing Whether or not the field is for editing.
     450     *
    415451     * @return array
    416452     */
     
    418454        global $wpdb;
    419455
    420         // This is done here so we don't have problems with sql injection
     456        // This is done here so we don't have problems with sql injection.
    421457        if ( empty( $for_editing ) && ( 'asc' === $this->order_by ) ) {
    422458            $sort_sql = 'ORDER BY name ASC';
     
    428464
    429465        // This eliminates a problem with getting all fields when there is no
    430         // id for the object
     466        // id for the object.
    431467        if ( empty( $this->id ) ) {
    432468            $parent_id = -1;
     
    452488
    453489    /**
    454      * Delete all field children for this field
     490     * Delete all field children for this field.
    455491     *
    456492     * @since 1.2.0
     
    534570     * @param bool  $append       Whether to append to existing member types. If false, all existing member type
    535571     *                            associations will be deleted before adding your `$member_types`. Default false.
     572     *
    536573     * @return array Member types for the current field, after being saved.
    537574     */
     
    588625         * @since 2.4.0
    589626         *
    590          * @param BP_XProfile_Field $field Field object.
     627         * @param BP_XProfile_Field $this Field object.
    591628         */
    592629        do_action( 'bp_xprofile_field_set_member_type', $this );
     
    661698        global $wpdb;
    662699
    663         // Bail if no field ID
     700        // Bail if no field ID.
    664701        if ( empty( $field_id ) ) {
    665702            return false;
     
    670707        $type = $wpdb->get_var( $sql );
    671708
    672         // Return field type
     709        // Return field type.
    673710        if ( ! empty( $type ) ) {
    674711            return $type;
     
    679716
    680717    /**
    681      * Delete all fields in a field group
     718     * Delete all fields in a field group.
    682719     *
    683720     * @since 1.2.0
     
    685722     * @global object $wpdb
    686723     *
    687      * @param  int    $group_id
     724     * @param int $group_id ID of the field group to delete fields from.
    688725     *
    689726     * @return boolean
     
    692729        global $wpdb;
    693730
    694         // Bail if no group ID
     731        // Bail if no group ID.
    695732        if ( empty( $group_id ) ) {
    696733            return false;
     
    701738        $deleted = $wpdb->get_var( $sql );
    702739
    703         // Return true if fields were deleted
     740        // Return true if fields were deleted.
    704741        if ( false !== $deleted ) {
    705742            return true;
     
    710747
    711748    /**
    712      * Get field ID from field name
     749     * Get field ID from field name.
    713750     *
    714751     * @since 1.5.0
    715752     *
    716753     * @global object $wpdb
    717      * @param  string $field_name
     754     *
     755     * @param string $field_name Name of the field to query the ID for.
    718756     *
    719757     * @return boolean
     
    734772
    735773    /**
    736      * Update field position and/or field group when relocating
     774     * Update field position and/or field group when relocating.
    737775     *
    738776     * @since 1.5.0
     
    740778     * @global object $wpdb
    741779     *
    742      * @param  int $field_id
    743      * @param  int $position
    744      * @param  int $field_group_id
     780     * @param int      $field_id       ID of the field to update.
     781     * @param int|null $position       Field position to update.
     782     * @param int|null $field_group_id ID of the field group.
    745783     *
    746784     * @return boolean
     
    749787        global $wpdb;
    750788
    751         // Bail if invalid position or field group
     789        // Bail if invalid position or field group.
    752790        if ( ! is_numeric( $position ) || ! is_numeric( $field_group_id ) ) {
    753791            return false;
    754792        }
    755793
    756         // Get table name and field parent
     794        // Get table name and field parent.
    757795        $table_name = buddypress()->profile->table_name_fields;
    758796        $sql        = $wpdb->prepare( "UPDATE {$table_name} SET field_order = %d, group_id = %d WHERE id = %d", $position, $field_group_id, $field_id );
    759797        $parent     = $wpdb->query( $sql );
    760798
    761         // Update $field_id with new $position and $field_group_id
     799        // Update $field_id with new $position and $field_group_id.
    762800        if ( ! empty( $parent ) && ! is_wp_error( $parent ) ) {
    763801
    764             // Update any children of this $field_id
     802            // Update any children of this $field_id.
    765803            $sql = $wpdb->prepare( "UPDATE {$table_name} SET group_id = %d WHERE parent_id = %d", $field_group_id, $field_id );
    766804            $wpdb->query( $sql );
     
    779817     * @param string|array $member_types Member type or array of member types. Use 'any' to return unrestricted
    780818     *                                   fields (those available for anyone, regardless of member type).
     819     *
    781820     * @return array Multi-dimensional array, with field IDs as top-level keys, and arrays of member types
    782821     *               associated with each field as values.
     
    847886
    848887    /**
    849      * Validate form field data on sumbission
     888     * Validate form field data on sumbission.
    850889     *
    851890     * @since 2.2.0
    852891     *
    853      * @global type $message
     892     * @global $message
     893     *
    854894     * @return boolean
    855895     */
     
    857897        global $message;
    858898
    859         // Check field name
     899        // Check field name.
    860900        if ( ! isset( $_POST['title'] ) || ( '' === $_POST['title'] ) ) {
    861901            $message = esc_html__( 'Profile fields must have a name.', 'buddypress' );
     
    863903        }
    864904
    865         // Check field requirement
     905        // Check field requirement.
    866906        if ( ! isset( $_POST['required'] ) ) {
    867907            $message = esc_html__( 'Profile field requirement is missing.', 'buddypress' );
     
    869909        }
    870910
    871         // Check field type
     911        // Check field type.
    872912        if ( empty( $_POST['fieldtype'] ) ) {
    873913            $message = esc_html__( 'Profile field type is missing.', 'buddypress' );
     
    875915        }
    876916
    877         // Check that field is of valid type
     917        // Check that field is of valid type.
    878918        if ( ! in_array( $_POST['fieldtype'], array_keys( bp_xprofile_get_field_types() ), true ) ) {
    879919            $message = sprintf( esc_html__( 'The profile field type %s is not registered.', 'buddypress' ), '<code>' . esc_attr( $_POST['fieldtype'] ) . '</code>' );
     
    881921        }
    882922
    883         // Get field type so we can check for and lavidate any field options
     923        // Get field type so we can check for and lavidate any field options.
    884924        $field_type = bp_xprofile_create_field_type( $_POST['fieldtype'] );
    885925
    886         // Field type requires options
     926        // Field type requires options.
    887927        if ( true === $field_type->supports_options ) {
    888928
    889             // Build the field option key
     929            // Build the field option key.
    890930            $option_name = sanitize_key( $_POST['fieldtype'] ) . '_option';
    891931
    892             // Check for missing or malformed options
     932            // Check for missing or malformed options.
    893933            if ( empty( $_POST[ $option_name ] ) || ! is_array( $_POST[ $option_name ] ) ) {
    894934                $message = esc_html__( 'These field options are invalid.', 'buddypress' );
     
    896936            }
    897937
    898             // Trim out empty field options
     938            // Trim out empty field options.
    899939            $field_values  = array_values( $_POST[ $option_name ] );
    900940            $field_options = array_map( 'sanitize_text_field', $field_values );
    901941            $field_count   = count( $field_options );
    902942
    903             // Check for missing or malformed options
     943            // Check for missing or malformed options.
    904944            if ( 0 === $field_count ) {
    905945                $message = sprintf( esc_html__( '%s require at least one option.', 'buddypress' ), $field_type->name );
     
    907947            }
    908948
    909             // If only one option exists, it cannot be an empty string
     949            // If only one option exists, it cannot be an empty string.
    910950            if ( ( 1 === $field_count ) && ( '' === $field_options[0] ) ) {
    911951                $message = sprintf( esc_html__( '%s require at least one option.', 'buddypress' ), $field_type->name );
     
    929969
    930970    /**
    931      * Oupput the admin form for this field
     971     * Oupput the admin form for this field.
    932972     *
    933973     * @since 1.9.0
    934974     *
    935      * @param type $message
     975     * @param string $message Message to display.
    936976     */
    937977    public function render_admin_form( $message = '' ) {
     
    9761016                            <?php
    9771017
    978                             // Output the name & description fields
     1018                            // Output the name & description fields.
    9791019                            $this->name_and_description(); ?>
    9801020
     
    9851025                            <?php
    9861026
    987                             // Output the sumbit metabox
     1027                            // Output the sumbit metabox.
    9881028                            $this->submit_metabox( $button );
    9891029
    990                             // Output the required metabox
     1030                            // Output the required metabox.
    9911031                            $this->required_metabox();
    9921032
     
    9941034                            $this->member_type_metabox();
    9951035
    996                             // Output the field visibility metaboxes
     1036                            // Output the field visibility metaboxes.
    9971037                            $this->visibility_metabox();
    9981038
     
    10211061                            do_action( 'xprofile_field_before_contentbox', $this );
    10221062
    1023                             // Output the field attributes metabox
     1063                            // Output the field attributes metabox.
    10241064                            $this->type_metabox();
    10251065
    1026                             // Output hidden inputs for default field
     1066                            // Output hidden inputs for default field.
    10271067                            $this->default_field_hidden_inputs();
    10281068
     
    10461086
    10471087    /**
    1048      * Private method used to display the submit metabox
     1088     * Private method used to display the submit metabox.
    10491089     *
    10501090     * @since 2.3.0
    10511091     *
    1052      * @param string $button_text
     1092     * @param string $button_text Text to put on button.
    10531093     */
    10541094    private function submit_metabox( $button_text = '' ) {
     
    11151155
    11161156    /**
    1117      * Private method used to output field name and description fields
     1157     * Private method used to output field name and description fields.
    11181158     *
    11191159     * @since 2.3.0
     
    11931233
    11941234    /**
    1195      * Private method used to output field visibility metaboxes
     1235     * Private method used to output field visibility metaboxes.
    11961236     *
    11971237     * @since 2.3.0
    11981238     *
    1199      * @return if default field id 1
     1239     * @return void If default field id 1.
    12001240     */
    12011241    private function visibility_metabox() {
    12021242
    1203         // Default field cannot have custom visibility
     1243        // Default field cannot have custom visibility.
    12041244        if ( true === $this->is_default_field() ) {
    12051245            return;
     
    12421282
    12431283    /**
    1244      * Output the metabox for setting if field is required or not
     1284     * Output the metabox for setting if field is required or not.
    12451285     *
    12461286     * @since 2.3.0
    12471287     *
    1248      * @return if default field
     1288     * @return void If default field.
    12491289     */
    12501290    private function required_metabox() {
    12511291
    1252         // Default field is always required
     1292        // Default field is always required.
    12531293        if ( true === $this->is_default_field() ) {
    12541294            return;
     
    12691309
    12701310    /**
    1271      * Output the metabox for setting what type of field this is
     1311     * Output the metabox for setting what type of field this is.
    12721312     *
    12731313     * @since 2.3.0
    12741314     *
    1275      * @return if default field
     1315     * @return void If default field.
    12761316     */
    12771317    private function type_metabox() {
    12781318
    1279         // Default field cannot change type
     1319        // Default field cannot change type.
    12801320        if ( true === $this->is_default_field() ) {
    12811321            return;
     
    13051345
    13061346    /**
    1307      * Output hidden fields used by default field
     1347     * Output hidden fields used by default field.
    13081348     *
    13091349     * @since 2.3.0
    13101350     *
    1311      * @return if not default field
     1351     * @return void If not default field.
    13121352     */
    13131353    private function default_field_hidden_inputs() {
    13141354
    1315         // Field 1 is the fullname field, which cannot have custom visibility
     1355        // Field 1 is the fullname field, which cannot have custom visibility.
    13161356        if ( false === $this->is_default_field() ) {
    13171357            return;
     
    13251365
    13261366    /**
    1327      * Return if a field ID is the default field
     1367     * Return if a field ID is the default field.
    13281368     *
    13291369     * @since 2.3.0
    13301370     *
    1331      * @param  int $field_id ID of field to check
     1371     * @param int $field_id ID of field to check.
     1372     *
    13321373     * @return bool
    13331374     */
    13341375    private function is_default_field( $field_id = 0 ) {
    13351376
    1336         // Fallback to current field ID if none passed
     1377        // Fallback to current field ID if none passed.
    13371378        if ( empty( $field_id ) ) {
    13381379            $field_id = $this->id;
    13391380        }
    13401381
    1341         // Compare & return
     1382        // Compare & return.
    13421383        return (bool) ( 1 === (int) $field_id );
    13431384    }
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php

    r10142 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
     
    1313
    1414    /**
     15     * Field group ID.
     16     *
    1517     * @since 1.1.0
    1618     *
     
    2022
    2123    /**
     24     * Field group name.
     25     *
    2226     * @since 1.1.0
    2327     *
     
    2731
    2832    /**
     33     * Field group Description.
     34     *
    2935     * @since 1.1.0
    3036     *
     
    3440
    3541    /**
     42     * Group deletion boolean.
     43     *
    3644     * @since 1.1.0
    3745     *
     
    4149
    4250    /**
     51     * Group order.
     52     *
    4353     * @since 1.1.0
    4454     *
     
    4858
    4959    /**
     60     * Group fields.
     61     *
    5062     * @since 1.1.0
    5163     *
     
    5567
    5668    /**
    57      * Initialize and/or populate profile field group
     69     * Initialize and/or populate profile field group.
    5870     *
    5971     * @since 1.1.0
    6072     *
    61      * @param int  $id
    62      * @param int  $user_id
    63      * @param bool $get_data
     73     * @param int|null $id Field group ID.
    6474     */
    6575    public function __construct( $id = null ) {
     
    7080
    7181    /**
    72      * Populate a profile field group
     82     * Populate a profile field group.
    7383     *
    7484     * @since 1.0.0
    7585     *
    7686     * @global $wpdb $wpdb
    77      * @param  int   $id
     87     *
     88     * @param int $id Field group ID.
    7889     *
    7990     * @return boolean
     
    8192    public function populate( $id ) {
    8293
    83         // Get this group
     94        // Get this group.
    8495        $group = self::get( array(
    8596            'profile_group_id' => $id
    8697        ) );
    8798
    88         // Bail if group not found
     99        // Bail if group not found.
    89100        if ( empty( $group ) ) {
    90101            return false;
    91102        }
    92103
    93         // Get the first array element
     104        // Get the first array element.
    94105        $group = reset( $group );
    95106
    96         // Set object properties
     107        // Set object properties.
    97108        $this->id          = $group->id;
    98109        $this->name        = $group->name;
     
    103114
    104115    /**
    105      * Save a profile field group
     116     * Save a profile field group.
    106117     *
    107118     * @since 1.1.0
     
    114125        global $wpdb;
    115126
    116         // Filter the field group attributes
     127        // Filter the field group attributes.
    117128        $this->name        = apply_filters( 'xprofile_group_name_before_save',        $this->name,        $this->id );
    118129        $this->description = apply_filters( 'xprofile_group_description_before_save', $this->description, $this->id );
     
    125136         * @since 1.0.0
    126137         *
    127          * @param BP_XProfile_Group Current instance of the group being saved. Passed by reference.
     138         * @param BP_XProfile_Group $this Current instance of the group being saved. Passed by reference.
    128139         */
    129140        do_action_ref_array( 'xprofile_group_before_save', array( &$this ) );
     
    131142        $bp = buddypress();
    132143
    133         // Update or insert
     144        // Update or insert.
    134145        if ( ! empty( $this->id ) ) {
    135146            $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id );
     
    138149        }
    139150
    140         // Attempt to insert or update
     151        // Attempt to insert or update.
    141152        $query = $wpdb->query( $sql );
    142153
     
    146157        }
    147158
    148         // If not set, update the ID in the group object