Metabox::update_fields( int $post_id, array $data )
Update Virtual Event Meta Fields
Contents
Parameters
- $post_id
-
(int) (Required) Which post ID we are dealing with when saving.
- $data
-
(array) (Required) An array of meta field values.
Source
File: src/Tribe/Metabox.php
public function update_fields( $post_id, $data ) {
update_post_meta( $post_id, Event_Meta::$key_type, Arr::get( $data, 'event-type', false ) );
update_post_meta( $post_id, Event_Meta::$key_virtual, Arr::get( $data, 'virtual', false ) );
update_post_meta( $post_id, Event_Meta::$key_video_source, Arr::get( $data, 'video-source', false ) );
update_post_meta( $post_id, Event_Meta::$key_virtual_url, Arr::get( $data, 'virtual-url', false ) );
update_post_meta( $post_id, Event_Meta::$key_linked_button_text, Arr::get( $data, 'virtual-button-text', false ) );
update_post_meta( $post_id, Event_Meta::$key_linked_button, Arr::get( $data, 'linked-button', false ) );
update_post_meta( $post_id, Event_Meta::$key_show_embed_at, Arr::get( $data, 'show-embed-at', false ) );
update_post_meta( $post_id, Event_Meta::$key_show_embed_to, Arr::get( $data, 'show-embed-to', false ) );
update_post_meta( $post_id, Event_Meta::$key_show_on_event, Arr::get( $data, 'show-on-event', false ) );
update_post_meta( $post_id, Event_Meta::$key_show_on_views, Arr::get( $data, 'show-on-views', false ) );
/**
* Allows extensions and Compatibilities to save their associated meta.
*
* @since 1.0.4
*
* @param int $post_id ID of the post we're saving.
* @param array $data The meta data we're trying to save.
*/
do_action( 'tribe_events_virtual_update_post_meta', $post_id, $data );
// These need some logic around them.
$embed_video = Arr::get( $data, 'embed-video', false );
$virtual_url = Arr::get( $data, 'virtual-url', false );
$video_source = Arr::get( $data, 'video-source', '' );
$autodetect_source = get_post_meta( $post_id, Event_Meta::$key_autodetect_source, true );
if ( ! $autodetect_source ) {
$autodetect_source = Arr::get( $data, 'autodetect-source', '' );
}
// If the link is not embeddable, uncheck key_embed_video.
if (
Event_Meta::$key_video_source_id !== $video_source ||
Event_Meta::$key_oembed_source_id !== $autodetect_source ||
tribe( OEmbed::class )->is_embeddable( $virtual_url )
) {
update_post_meta( $post_id, Event_Meta::$key_embed_video, $embed_video );
} else {
delete_post_meta( $post_id, Event_Meta::$key_embed_video );
}
}
Changelog
| Version | Description |
|---|---|
| 1.6.0 | - Add video source support. |
| 1.0.0 | Introduced. |