Metabox::save( int $post_id, WP_Post $post, boolean $update )

Saves the metabox, which will be triggered in save_post.


Parameters

$post_id

(int) (Required) Which post ID we are dealing with when saving.

$post

(WP_Post) (Required) WP Post instance we are saving.

$update

(boolean) (Required) If we are updating the post or not.


Top ↑

Source

File: src/Tribe/Metabox.php

	public function save( $post_id, $post, $update ) {
		// Skip non-events.
		if ( ! tribe_is_event( $post_id ) ) {
			return;
		}

		// All fields will be stored in the same array for simplicity.
		$data = $this->context->get( 'events_virtual_data', [] );

		// Add nonce for security and authentication.
		$nonce_name = Arr::get( $data, 'virtual-nonce', false );

		// Check if nonce is valid.
		if ( ! wp_verify_nonce( $nonce_name, static::$nonce_action ) ) {
			return;
		}

		// Check if user has permissions to save data.
		if ( ! current_user_can( 'edit_tribe_events', $post_id ) ) {
			return;
		}

		if ( tribe_context()->is( 'bulk_edit' ) ) {
			return;
		}

		if ( tribe_context()->is( 'inline_save' ) ) {
			return;
		}

		// Check if not an autosave.
		if ( wp_is_post_autosave( $post_id ) ) {
			return;
		}

		// Check if not a revision.
		if ( wp_is_post_revision( $post_id ) ) {
			return;
		}

		$virtual = tribe_is_truthy( Arr::get( $data, 'virtual', false ) );
		if ( $virtual ) {
			$this->update_fields( $post_id, $data );
		} else {
			$this->delete_fields( $post_id, $data );
		}

		/**
		 * Fires after the Metabox saved the data from the current request.
		 *
		 * @since 1.0.0
		 *
		 * @param int $post_id The post ID of the event currently being saved.
		 * @param array<string,mixed> The whole data received by the metabox.
		 */
		do_action( 'tribe_events_virtual_metabox_save', $post_id, $data );
	}

Top ↑

Changelog

Changelog
Version Description
1.0.0 Introduced.