Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/21/2015 02:00:38 PM (10 years ago)
Author:
boonebgorges
Message:

Allow xProfile fields to be restricted to users belonging to one or more member types.

A new metabox on the profile field edit panel allows the administrator to
select the member types to which the field is applicable. Admins can also
choose to have a field apply to users who do not belong to any member type.
Information about a field's member type associations is displayed on the
Users > Profile Fields page, alongside each field name.

During registration, the only fields that are displayed are those that are
unrestricted - that is, those available to all users, regardless of member type
(or lack thereof).

This changeset introduces a number of new methods on BP_XProfile_Field that
developers should use to manipulate member type information:
get_member_types(), set_member_types(), and the static
get_fields_for_member_type(). In addition to member types that have been
explicitly registered, 'null' is a pseudo-type representing users who do not
belong to a member type.

This changeset introduces a blacklist of illegal member type names. By default,
the blacklist includes 'any', 'null', and '_none'. Use the
'bp_member_type_illegal_names' filter to add names to the blacklist.

Props Offereins, boonebgorges, tanner m, imath.
See #5192.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r9977 r10022  
    25242524    $member_type = sanitize_key( $member_type );
    25252525
     2526    /**
     2527     * Filters the list of illegal member type names.
     2528     *
     2529     * - 'any' is a special pseudo-type, representing items unassociated with any member type.
     2530     * - 'null' is a special pseudo-type, representing users without any type.
     2531     * - '_none' is used internally to denote an item that should not apply to any member types.
     2532     *
     2533     * @since BuddyPress (2.4.0)
     2534     *
     2535     * @param array $illegal_names Array of illegal names.
     2536     */
     2537    $illegal_names = apply_filters( 'bp_member_type_illegal_names', array( 'any', 'null', '_none' ) );
     2538    if ( in_array( $member_type, $illegal_names, true ) ) {
     2539        return new WP_Error( 'bp_member_type_illegal_name', __( 'You may not register a member type with this name.', 'buddypress' ), $member_type );
     2540    }
     2541
    25262542    // Store the post type name as data in the object (not just as the array key).
    25272543    $r['name'] = $member_type;
Note: See TracChangeset for help on using the changeset viewer.