is_active() ) { return; } wp_enqueue_media(); } public function is_visible() { return true; } public function get_slug() { return 'edit'; } public function get_label() { return esc_html__( 'Edit Import', 'the-events-calendar' ); } public function handle_submit() { $this->messages = [ 'error', 'success', 'warning', ]; if ( empty( $_POST['aggregator']['action'] ) || 'edit' !== $_POST['aggregator']['action'] ) { return; } $submission = parent::handle_submit(); if ( empty( $submission['record'] ) || empty( $submission['post_data'] ) || empty( $submission['meta'] ) ) { return; } $record = $submission['record']; $post_data = $submission['post_data']; $meta = $submission['meta']; if ( ! empty( $post_data['post_id'] ) ) { $this->finalize_schedule_edit( $record, $post_data, $meta ); return; } $post = $record->create( $meta['type'], [], $meta ); if ( is_wp_error( $post ) ) { return $post; } $result = $record->queue_import(); if ( is_wp_error( $post ) ) { return $post; } return $result; } /** * Finalizes the saving of a scheduled import * * @param Tribe__Events__Aggregator__Record__Abstract $record Record object * @param array $post_data Massaged POSTed data * @param array $meta Meta to be saved to the schedule */ public function finalize_schedule_edit( $record, $post_data, $meta ) { $this->messages = [ 'error' => [], 'success' => [], 'warning' => [], ]; $meta['post_status'] = empty( $post_data['post_status'] ) ? 'draft' : $post_data['post_status']; $meta['category'] = Tribe__Utils__Array::get( $post_data, 'category', null ); $result = $record->save( $post_data['post_id'], [], $meta ); if ( is_wp_error( $result ) ) { $this->messages['error'][] = $result->get_error_message(); ob_start(); ?>

messages['error'] ); ?>

messages['success'][] = esc_html__( 'Scheduled import was successfully updated.' ); ob_start(); ?>

messages['success'] ); ?>

messages['success'][] = __( 'Your Scheduled Import has been updated!', 'the-events-calendar' ); tribe_notice( 'tribe-aggregator-schedule-edit-complete', $html, 'type=success' ); return $result; } /** * Handles the previewing of a scheduled import edit */ public function ajax_preview_import() { $result = $this->handle_submit(); if ( is_wp_error( $result ) ) { $result = (object) [ 'message_code' => $result->get_error_code(), 'message' => $result->get_error_message(), ]; wp_send_json_error( $result ); } wp_send_json_success( $result ); } }