Tribe__Events__REST__V1__Endpoints__Single_Venue::create( WP_REST_Request $request, bool $return_id = false )

Handles POST requests on the endpoint.


Parameters

$request

(WP_REST_Request) (Required)

$return_id

(bool) (Optional) Whether the created post ID should be returned or the full response object.

Default value: false


Top ↑

Return

(WP_Error|WP_REST_Response|int) An array containing the data on success or a WP_Error instance on failure.


Top ↑

Source

File: src/Tribe/REST/V1/Endpoints/Single_Venue.php

	public function create( WP_REST_Request $request, $return_id = false ) {
		$postarr = $this->prepare_postarr( $request );

		/**
		 * Filters whether the API should try to avoid inserting duplicate venues or not.
		 *
		 * @param bool  $avoid_duplicates
		 * @param array $postarr The venue data provided in the request.
		 *
		 * @since 4.6
		 */
		$avoid_duplicates = apply_filters( 'tribe_events_rest_venue_insert_avoid_duplicates', true, $postarr );

		$id = Tribe__Events__Venue::instance()->create( $postarr, $postarr['post_status'], $avoid_duplicates );

		if ( empty( $id ) ) {
			$message = $this->messages->get_message( 'could-not-create-venue' );

			return new WP_Error( 'could-not-create-venue', $message, array( 'status' => 400 ) );
		}

		if ( $return_id ) {
			return $id;
		}

		$data = $this->post_repository->get_venue_data( $id );

		$response = new WP_REST_Response( $data );
		$response->set_status( 201 );

		return $response;
	}

Top ↑

Changelog

Changelog
Version Description
bucket/full-rest-api Introduced.