bp_register_member_type( string $member_type, array $args = array() )
Register a profile type.
Description
Parameters
- $member_type
-
(Required) Unique string identifier for the profile type.
- $args
-
(Optional) Array of arguments describing the profile type.
- 'labels'
(array) Array of labels to use in various parts of the interface.- 'name'
(string) Default name. Should typically be plural. - 'singular_name'
(string) Singular name.
- 'name'
- 'has_directory'
(bool|string) Whether the profile type should have its own type-specific directory. Passtrue
to use the$member_type
string as the type's slug. Pass a string to customize the slug. Passfalse
to disable. Default: true.
Default value: array()
- 'labels'
Return
(object|WP_Error) profile type object on success, WP_Error object on failure.
Source
File: bp-members/bp-members-functions.php
function bp_register_member_type( $member_type, $args = array() ) { $bp = buddypress(); if ( isset( $bp->members->types[ $member_type ] ) ) { return new WP_Error( 'bp_member_type_exists', __( 'Profile type already exists.', 'buddyboss' ), $member_type ); } $r = bp_parse_args( $args, array( 'labels' => array(), 'has_directory' => true, ), 'register_member_type' ); $member_type = sanitize_key( $member_type ); /** * Filters the list of illegal profile type names. * * - 'any' is a special pseudo-type, representing items unassociated with any profile type. * - 'null' is a special pseudo-type, representing users without any type. * - '_none' is used internally to denote an item that should not apply to any profile types. * * @since BuddyPress 2.4.0 * * @param array $illegal_names Array of illegal names. */ $illegal_names = apply_filters( 'bp_member_type_illegal_names', array( 'any', 'null', '_none' ) ); if ( in_array( $member_type, $illegal_names, true ) ) { return new WP_Error( 'bp_member_type_illegal_name', __( 'You may not register a profile type with this name.', 'buddyboss' ), $member_type ); } // Store the post type name as data in the object (not just as the array key). $r['name'] = $member_type; // Make sure the relevant labels have been filled in. $default_name = isset( $r['labels']['name'] ) ? $r['labels']['name'] : ucfirst( $r['name'] ); $r['labels'] = array_merge( array( 'name' => $default_name, 'singular_name' => $default_name, ), $r['labels'] ); // Directory slug. if ( $r['has_directory'] ) { // A string value is intepreted as the directory slug. Otherwise fall back on profile type. if ( is_string( $r['has_directory'] ) ) { $directory_slug = $r['has_directory']; } else { $directory_slug = $member_type; } // Sanitize for use in URLs. $r['directory_slug'] = sanitize_title( $directory_slug ); $r['has_directory'] = true; } else { $r['directory_slug'] = ''; $r['has_directory'] = false; } $bp->members->types[ $member_type ] = $type = (object) $r; /** * Fires after a profile type is registered. * * @since BuddyPress 2.2.0 * * @param string $member_type profile type identifier. * @param object $type profile type object. */ do_action( 'bp_registered_member_type', $member_type, $type ); return $type; }
Changelog
Version | Description |
---|---|
BuddyPress 2.2.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.