/** * Update an existing event */ public static function updateEvent($eventId, $args) { $args['ID'] = $eventId; if (wp_update_post($args)) { TribeEventsAPI::saveEventMeta($eventId, $args, get_post($eventId)); } return $eventId; }
/** * 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; if (!in_array(TribeEvents::POSTTYPE, (array) $args['post_type'])) { return false; } if (wp_update_post($args)) { TribeEventsAPI::saveEventMeta($eventId, $args, get_post($eventId)); } return $eventId; }
/** * Adds / removes the event details as meta tags to the post. * * @param string $postId * @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; } // remove these actions even if nonce is not set // note: we're removing these because these actions are actually for PRO, // these functions are used when editing an existing venue or organizer remove_action('save_post', array($this, 'save_venue_data'), 16, 2); remove_action('save_post', array($this, 'save_organizer_data'), 16, 2); if (!isset($_POST['ecp_nonce'])) { return; } if (!wp_verify_nonce($_POST['ecp_nonce'], TribeEvents::POSTTYPE)) { return; } if (!current_user_can('edit_tribe_events')) { return; } $_POST['Organizer'] = isset($_POST['organizer']) ? stripslashes_deep($_POST['organizer']) : null; $_POST['Venue'] = isset($_POST['venue']) ? stripslashes_deep($_POST['venue']) : null; /** * When using pro and we have a VenueID/OrganizerID, we just save the ID, because we're not * editing the venue/organizer from within the event. */ if (isset($_POST['Venue']['VenueID']) && !empty($_POST['Venue']['VenueID']) && class_exists('TribeEventsPro')) { $_POST['Venue'] = array('VenueID' => intval($_POST['Venue']['VenueID'])); } if (isset($_POST['Organizer']['OrganizerID']) && !empty($_POST['Organizer']['OrganizerID']) && class_exists('TribeEventsPro')) { $_POST['Organizer'] = array('OrganizerID' => intval($_POST['Organizer']['OrganizerID'])); } TribeEventsAPI::saveEventMeta($postId, $_POST, $post); }
/** * 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) { // 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_' . self::POSTTYPE, array($this, 'addEventMeta'), 15, 2); // 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'], TribeEvents::POSTTYPE)) { return; } if (!current_user_can('edit_tribe_events')) { return; } $_POST['Organizer'] = isset($_POST['organizer']) ? stripslashes_deep($_POST['organizer']) : null; $_POST['Venue'] = isset($_POST['venue']) ? stripslashes_deep($_POST['venue']) : null; /** * When using pro and we have a VenueID/OrganizerID, we just save the ID, because we're not * editing the venue/organizer from within the event. */ if (isset($_POST['Venue']['VenueID']) && !empty($_POST['Venue']['VenueID'])) { $_POST['Venue'] = array('VenueID' => intval($_POST['Venue']['VenueID'])); } if (isset($_POST['Organizer']['OrganizerID']) && !empty($_POST['Organizer']['OrganizerID'])) { $_POST['Organizer'] = array('OrganizerID' => intval($_POST['Organizer']['OrganizerID'])); } TribeEventsAPI::saveEventMeta($postId, $_POST, $post); // Add this hook back in add_action('save_post_' . self::POSTTYPE, array($this, 'addEventMeta'), 15, 2); }