/** * Handles the event delete AJAX requests. * * @since 0.11 */ public function delete_event_over_ajax() { check_ajax_referer('wpt_event_editor_ajax_nonce', 'nonce', true); $event_id = $_POST['event_id']; // Check if this is a real event. if (is_null(get_post($event_id))) { wp_die(); } $event = new WPT_Event($event_id); $production = $event->production(); wp_delete_post($event_id, true); echo $this->get_listing_html($production->ID); wp_die(); }
/** * Update the season of events to the season of the parent production. * * Triggered by the updated_post_meta action. * * Used when: * - a production is saved through the admin screen or * - an event is attached to a production. * * @since 0.7 * */ function updated_post_meta($meta_id, $object_id, $meta_key, $meta_value) { global $wp_theatre; // A production is saved through the admin screen. if ($meta_key == WPT_Season::post_type_name) { $post = get_post($object_id); if ($post->post_type == WPT_Production::post_type_name) { // avoid loops remove_action('updated_post_meta', array($this, 'updated_post_meta'), 20, 4); remove_action('added_post_meta', array($this, 'updated_post_meta'), 20, 4); $args = array('production' => $post->ID); $events = $wp_theatre->events->get($args); foreach ($events as $event) { update_post_meta($event->ID, WPT_Season::post_type_name, $meta_value); } add_action('updated_post_meta', array($this, 'updated_post_meta'), 20, 4); add_action('added_post_meta', array($this, 'updated_post_meta'), 20, 4); } } // An event is attached to a production. if ($meta_key == WPT_Production::post_type_name) { $event = new WPT_Event($object_id); // avoid loops remove_action('updated_post_meta', array($this, 'updated_post_meta'), 20, 4); remove_action('added_post_meta', array($this, 'updated_post_meta'), 20, 4); // inherit season from production if ($season = $event->production()->season()) { update_post_meta($event->ID, WPT_Season::post_type_name, $season->ID); } // inherit categories from production $categories = wp_get_post_categories($meta_value); wp_set_post_categories($event->ID, $categories); add_action('updated_post_meta', array($this, 'updated_post_meta'), 20, 4); add_action('added_post_meta', array($this, 'updated_post_meta'), 20, 4); } }