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

Edit some arguments for the endpoint’s CREATABLE and EDITABLE methods.

Description

Parameters

$method

(Optional) HTTP method of the request.

Default value: WP_REST_Server::CREATABLE

Return

(array) Endpoint arguments.

Source

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

811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
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';
 
    if ( WP_REST_Server::EDITABLE === $method ) {
        $key = 'update_item';
    } elseif ( WP_REST_Server::CREATABLE === $method ) {
        $key = 'create_item';
 
        // Remothe the ID for POST requests.
        unset( $args['id'] );
 
        // Those fields are required.
        $args['initiator_id']['required'] = true;
        $args['friend_id']['required']    = true;
 
        // This one is optional.
        $args['force'] = array(
            'description'       => __( 'Whether to force friendship acceptance.', 'buddyboss' ),
            'default'           => false,
            'type'              => 'boolean',
            'sanitize_callback' => 'rest_sanitize_boolean',
            'validate_callback' => 'rest_validate_request_arg',
        );
 
    } elseif ( WP_REST_Server::DELETABLE === $method ) {
        $key = 'delete_item';
        unset( $args['id'] );
        unset( $args['initiator_id'] );
        $args['friend_id']['required'] = true;
    }
 
    /**
     * 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_friends_{$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.