BP_REST_Members_Endpoint::get_endpoint_args_for_item_schema( string $method = WP_REST_Server::CREATABLE )

Make sure to retrieve the needed arguments for the endpoint CREATABLE method.

Description

Parameters

$method

(Optional) HTTP method of the request.

Default value: WP_REST_Server::CREATABLE

Return

(array) Endpoint arguments.

Source

File: bp-members/classes/class-bp-rest-members-endpoint.php

953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
    $args = WP_REST_Controller::get_endpoint_args_for_item_schema( $method );
    $key  = 'get_item';
 
    // Add member type args.
    $member_type_args = array(
        'description'       => __( 'Set type(s) for a member.', 'buddyboss' ),
        'type'              => 'string',
        'enum'              => bp_get_member_types(),
        'context'           => array( 'edit' ),
        'sanitize_callback' => 'bp_rest_sanitize_member_types',
        'validate_callback' => 'bp_rest_sanitize_member_types',
    );
 
    if ( WP_REST_Server::CREATABLE === $method ) {
        $key = 'create_item';
 
        // We don't need the mention name to create a user.
        unset( $args['mention_name'] );
 
        // Add member type args.
        $args['types'] = $member_type_args;
 
        // But we absolutely need the email.
        $args['email'] = array(
            'description' => __( 'The email address for the member.', 'buddyboss' ),
            'type'        => 'string',
            'format'      => 'email',
            'context'     => array( 'edit' ),
            'required'    => true,
        );
    } elseif ( WP_REST_Server::EDITABLE === $method ) {
        $key = 'update_item';
 
        /**
         * 1. The mention name or user login are not updatable.
         * 2. The password belongs to the Settings endpoint parameter.
         */
        unset( $args['mention_name'], $args['user_login'], $args['password'] );
 
        // Add member type args.
        $args['types'] = $member_type_args;
 
    } elseif ( WP_REST_Server::DELETABLE === $method ) {
        $key = 'delete_item';
    }
 
    /**
     * Filters the method query arguments.
     *
     * @param array $args Query arguments.
     * @param string $method HTTP method of the request.
     *
     * @since 0.1.0
     */
    return apply_filters( "bp_rest_members_{$key}_query_arguments", $args, $method );
}

Changelog

Changelog
Version Description
0.1.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.