/** * Update an existing event * * @param int $eventId The event ID to update. * @param array $args The post args. * * @return false|int The event ID. */ public static function updateEvent($eventId, $args) { $args['ID'] = $eventId; $args['post_type'] = Tribe__Events__Main::POSTTYPE; if (wp_update_post($args)) { Tribe__Events__API::saveEventMeta($eventId, $args, get_post($eventId)); } return $eventId; }
/** * Adds / removes the event details as meta tags to the post. * * @param int $postId * @param WP_Post $post * * @return void */ public function addEventMeta($postId, $post) { // only continue if it's an event post if ($post->post_type !== self::POSTTYPE || defined('DOING_AJAX')) { return; } // don't do anything on autosave or auto-draft either or massupdates if (wp_is_post_autosave($postId) || $post->post_status == 'auto-draft' || isset($_GET['bulk_edit']) || isset($_REQUEST['action']) && $_REQUEST['action'] == 'inline-save') { return; } // don't do anything on other wp_insert_post calls if (isset($_POST['post_ID']) && $postId != $_POST['post_ID']) { return; } if (!isset($_POST['ecp_nonce'])) { return; } if (!wp_verify_nonce($_POST['ecp_nonce'], self::POSTTYPE)) { return; } if (!current_user_can('edit_tribe_events')) { return; } // Remove this hook to avoid an infinite loop, because saveEventMeta calls wp_update_post when the post is set to always show in calendar remove_action('save_post', array($this, 'addEventMeta'), 15, 2); $_POST['Organizer'] = isset($_POST['organizer']) ? stripslashes_deep($_POST['organizer']) : null; $_POST['Venue'] = isset($_POST['venue']) ? stripslashes_deep($_POST['venue']) : null; /** * handle previewed venues and organizers */ $this->manage_preview_metapost('venue', $postId); $this->manage_preview_metapost('organizer', $postId); /** * When we have a VenueID/OrganizerID, we just save the ID, because we're not * editing the venue/organizer from within the event. */ $venue_pto = get_post_type_object(self::VENUE_POST_TYPE); if (isset($_POST['Venue']['VenueID']) && !empty($_POST['Venue']['VenueID'])) { $_POST['Venue'] = array('VenueID' => intval($_POST['Venue']['VenueID'])); } elseif (empty($venue_pto->cap->create_posts) || !current_user_can($venue_pto->cap->create_posts)) { $_POST['Venue'] = array(); } $_POST['Organizer'] = $this->normalize_organizer_submission($_POST['Organizer']); Tribe__Events__API::saveEventMeta($postId, $_POST, $post); // Add this hook back in add_action('save_post_' . self::POSTTYPE, array($this, 'addEventMeta'), 15, 2); }
/** * Save the meta for the event if the user has the capability to. * * @return bool `true` if event meta was updated, `false` otherwise. */ public function save() { if (!$this->context->has_nonce()) { return false; } if (!$this->context->verify_nonce()) { return false; } if (!$this->context->current_user_can_edit_events()) { return false; } // Remove this hook to avoid an infinite loop, because saveEventMeta calls wp_update_post when the post is set to always show in calendar remove_action('save_post', array(Tribe__Events__Main::instance(), 'addEventMeta'), 15); $_POST['Organizer'] = isset($_POST['organizer']) ? stripslashes_deep($_POST['organizer']) : null; $_POST['Venue'] = isset($_POST['venue']) ? stripslashes_deep($_POST['venue']) : null; /** * handle previewed venues and organizers */ $this->manage_preview_metapost('venue', $this->post_id); $this->manage_preview_metapost('organizer', $this->post_id); Tribe__Events__API::saveEventMeta($this->post_id, $_POST, $this->post); // Add this hook back in add_action('save_post_' . Tribe__Events__Main::POSTTYPE, array(Tribe__Events__Main::instance(), 'addEventMeta'), 15, 2); return true; }
/** * If a ticket is edited via the WooCommerce product editor (vs the ticket meta * box exposed in the event editor) then we need to trigger an update to ensure * cost meta in particular stays up-to-date on our side. * * @param $product_id */ public function syncronize_product_editor_changes($product_id) { $event = $this->get_event_for_ticket($product_id); // This product is not connected with an event if (!$event) { return; } // Trigger an update Tribe__Events__API::saveEventMeta($event->ID, array()); }