Tribe__Events__Aggregator__Record__Abstract::create( string $type = 'manual', array $args = array(), array $meta = array() )

Creates an import record.


Parameters

$type

(string) (Optional) Type of record to create - manual or schedule.

Default value: 'manual'

$args

(array) (Optional) Post type args.

Default value: array()

$meta

(array) (Optional) Post meta.

Default value: array()


Top ↑

Return

(WP_Post|WP_Error)


Top ↑

Source

File: src/Tribe/Aggregator/Record/Abstract.php

	public function create( $type = 'manual', $args = array(), $meta = array() ) {
		if ( ! in_array( $type, array( 'manual', 'schedule' ) ) ) {
			return tribe_error( 'core:aggregator:invalid-create-record-type', $type );
		}

		$defaults = array(
			'parent'    => 0,
		);

		$args = (object) wp_parse_args( $args, $defaults );

		$defaults = array(
			'frequency'                 => null,
			'hash'                      => wp_generate_password( 32, true, true ),
			'preview'                   => false,
			'allow_multiple_organizers' => true,
		);

		$meta = wp_parse_args( $meta, $defaults );

		$post = $this->prep_post_args( $type, $args, $meta );

		$this->watch_for_db_errors();

		$result = wp_insert_post( $post );

		if ( is_wp_error( $result ) ) {
			$this->maybe_add_meta_via_pre_wp_44_method( $result, $post['meta_input'] );
		}

		if ( $this->db_errors_happened() ) {
			$error_message = __( 'Something went wrong while inserting the record in the database.', 'the-events-calendar' );
			wp_delete_post( $result );


			return new WP_Error( 'db-error-during-creation', $error_message );
		}

		// After Creating the Post Load and return
		return $this->load( $result );
	}