/** * Handles the ajax action to push a post to Apple News. * * @access public */ public function ajax_push_post() { $id = absint($_GET['id']); // TODO: Move push action to shared $action = new Actions\Index\Push($this->settings, $id); $errors = $action->perform(); if ($errors) { echo json_encode(array('success' => false, 'error' => $errors)); } else { echo json_encode(array('success' => true)); } // This is required to terminate immediately and return a valid response wp_die(); }
/** * When a post is published, or a published post updated, trigger this * function. * * @since 0.4.0 * @param int $id * @param WP_Post $post * @access public */ public function do_publish($id, $post) { if (!current_user_can(apply_filters('apple_news_publish_capability', 'manage_options'))) { return; } // If the post has been marked as deleted from the API, ignore this update $deleted = get_post_meta($id, 'apple_news_api_deleted', true); if ($deleted) { return; } $action = new Actions\Index\Push($this->settings, $id); try { $action->perform(); } catch (Actions\Action_Exception $e) { Admin_Apple_Notice::error($e->getMessage()); } }
/** * Handles a push to Apple News action. * * @param int $id * @access private */ private function push_action($id) { $action = new Actions\Index\Push($this->settings, $id); try { $action->perform(); $this->notice_success(__('Your article has been pushed successfully!', 'apple-news')); } catch (Actions\Action_Exception $e) { $this->notice_error($e->getMessage()); } }