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

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

Description

Parameters

$method

(string) (Optional) HTTP method of the request.

Default value: WP_REST_Server::CREATABLE

Return

(array) Endpoint arguments.

Source

File: bp-forums/classes/class-bp-rest-reply-endpoint.php

	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  = 'create_item';

		if ( WP_REST_Server::DELETABLE === $method ) {
			$key = 'delete_item';

			$args = array(
				'id' => array(
					'description' => __( 'A unique numeric ID for the reply.', 'buddyboss' ),
					'type'        => 'integer',
					'required'    => true,
				),
			);
		}

		if ( WP_REST_Server::CREATABLE === $method || WP_REST_Server::EDITABLE === $method ) {
			$unset_keys = array(
				'date',
				'date_gmt',
				'password',
				'slug',
				'status',
				'link',
				'author',
				'parent',
				'depth',
				'reply_to',
				'is_reply_anonymous',
				'anonymous_author_data',
				'classes',
				'current_user_permissions',
				'action_states',
				'revisions',
			);

			if ( ! empty( $unset_keys ) ) {
				foreach ( $unset_keys as $k ) {
					if ( array_key_exists( $k, $args ) ) {
						unset( $args[ $k ] );
					}
				}
			}

			$args['title']['type']       = 'string';
			$args['content']['type']     = 'string';
			$args['content']['required'] = true;

			$args['reply_to'] = array(
				'description'       => __( 'Parent Reply ID for reply.', 'buddyboss' ),
				'type'              => 'integer',
				'sanitize_callback' => 'absint',
				'validate_callback' => 'rest_validate_request_arg',
			);

			$args['topic_id'] = array(
				'description'       => __( 'ID of the topic to perform the reply on it.', 'buddyboss' ),
				'type'              => 'integer',
				'required'          => true,
				'sanitize_callback' => 'absint',
				'validate_callback' => 'rest_validate_request_arg',
			);

			$args['forum_id'] = array(
				'description'       => __( 'Forum ID to reply on.', 'buddyboss' ),
				'type'              => 'integer',
				'required'          => false,
				'sanitize_callback' => 'absint',
				'validate_callback' => 'rest_validate_request_arg',
			);

			$args['tags'] = array(
				'description'       => __( 'Tags to add into the topic.', 'buddyboss' ),
				'type'              => 'string',
				'sanitize_callback' => 'sanitize_text_field',
				'validate_callback' => 'rest_validate_request_arg',
			);

			$args['subscribe'] = array(
				'description'       => __( 'Whether user subscribe topic or not.', 'buddyboss' ),
				'type'              => 'boolean',
				'sanitize_callback' => 'rest_sanitize_boolean',
				'validate_callback' => 'rest_validate_request_arg',
			);
		}

		if ( WP_REST_Server::EDITABLE === $method ) {
			$key = 'update_item';

			$args['reason'] = array(
				'description'       => __( 'Reason for editing a reply.', 'buddyboss' ),
				'type'              => 'string',
				'validate_callback' => 'rest_validate_request_arg',
			);

			$args['log'] = array(
				'description'       => __( 'Keep a log of reply edit.', 'buddyboss' ),
				'type'              => 'boolean',
				'default'           => true,
				'sanitize_callback' => 'rest_sanitize_boolean',
				'validate_callback' => 'rest_validate_request_arg',
			);
		}

		/**
		 * 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_reply_{$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.