Tribe__Tickets__Tickets_Handler::update_start_date( int $post_id, WP_Post $post, boolean $update )
Updates the Start date of all non-modified tickets when an Ticket supported Post is saved
Contents
Parameters
- $post_id
-
(int) (Required) Which post we are updating here
- $post
-
(WP_Post) (Required) Object of the current post updating
- $update
-
(boolean) (Required) If we are updating or creating a post
Return
(boolean)
Source
File: src/Tribe/Tickets_Handler.php
public function update_start_date( $post_id, $post, $update ) {
// Bail on Revision
if ( wp_is_post_revision( $post_id ) ) {
return false;
}
// Bail if the CPT doens't accept tickets
if ( ! tribe_tickets_post_type_enabled( $post->post_type ) ) {
return false;
}
$meta_key = $this->key_start_date;
$tickets = $this->get_tickets_ids( $post_id );
foreach ( $tickets as $ticket_id ) {
// Skip tickets with manual updates to that meta
if ( $this->has_manual_update( $ticket_id, $meta_key ) ) {
continue;
}
$current_date = get_post_meta( $ticket_id, $meta_key, true );
// Skip if the ticket has already a date
if ( ! empty( $current_date ) ) {
continue;
}
// 30 min
$round = 30;
if ( class_exists( 'Tribe__Events__Main' ) ) {
$round = (int) tribe( 'tec.admin.event-meta-box' )->get_timepicker_step( 'start' );
}
// Convert to seconds
$round *= MINUTE_IN_SECONDS;
$date = strtotime( $post->post_date );
$date = round( $date / $round ) * $round;
$date = date( Tribe__Date_Utils::DBDATETIMEFORMAT, $date );
update_post_meta( $ticket_id, $meta_key, $date );
}
return true;
}
Changelog
| Version | Description |
|---|---|
| 4.6 | Introduced. |