Tribe__Events__REST__V1__Endpoints__Linked_Post_Base::insert( int|array $data )
Inserts a post of the linked post type.
Contents
Parameters
- $data
-
(int|array) (Required) Either an existing linked post ID or the linked post data.
Return
(false|array|WP_Error) false if the linked post data is empty, the linked post ID (in an array as requested by the linked posts engine) or a WP_Error if the linked post insertion failed.
Source
File: src/Tribe/REST/V1/Endpoints/Linked_Post_Base.php
public function insert( $data ) {
if ( empty( $data ) ) {
return false;
}
if ( is_numeric( $data ) && $this->is_post_type( $data ) ) {
return array( $this->get_id_index() => $data );
}
if ( ! empty( $data['id'] ) ) {
if ( $this->is_post_type( $data['id'] ) ) {
return array( $this->get_id_index() => $data['id'] );
}
$message = $this->messages->get_message( 'invalid-linked-post-id' );
return new WP_Error( 'invalid-linked-post-id', $message, array( 'status' => 400 ) );
}
$data_request = new WP_REST_Request();
$data_request->set_param( 'args', $this->CREATE_args() );
$body_params = (array) $data;
foreach ( $body_params as $key => $value ) {
$data_request->set_param( $key, $value );
}
$post_id = $this->create( $data_request, true );
if ( $post_id instanceof WP_Error ) {
return $post_id;
}
return array( $this->get_id_index() => $post_id );
}