Event_Cleaner::handle_trashed_provisional_post( int $post_id )

Handles all provisional posts that are trashed.


Parameters

$post_id

(int) (Required) The post or provisional ID.


Top ↑

Return

(WP_Post|false|null) Post data on success, false or null on failure.


Top ↑

Source

File: src/Events_Pro/Custom_Tables/V1/Events/Event_Cleaner/Event_Cleaner.php

	public function handle_trashed_provisional_post( int $post_id ) {
		$provisional = tribe( Provisional_Post::class );
		if ( ! $provisional->is_provisional_post_id( $post_id ) ) {
			return;
		}
		$occurrence_id = $provisional->normalize_provisional_post_id( $post_id );
		$occurrence    = Occurrence::find( $occurrence_id );
		if ( ! $occurrence instanceof Occurrence ) {
			return;
		}

		// If single event, don't dissect.
		$is_single = Occurrence::where( 'post_id', $occurrence->post_id )
		                       ->count() === 1;
		if ( $is_single ) {
			$post_id_to_trash = $occurrence->post_id;
		} else {
			// We need to split and create a single post when this is trashed, to leverage WP's built in `post` management.
			$post_id_to_trash = tribe( Events::class )->detach_occurrence_from_event( $occurrence );
		}

		return wp_trash_post( $post_id_to_trash );
	}

Top ↑

Changelog

Changelog
Version Description
6.0.12 Introduced.