/** * Handles a push to Apple News action. * * @param int $id * @access private */ private function push_action($id) { // Ensure the post is published if ('publish' != get_post_status($id)) { $this->notice_error(sprintf(__('Article %s is not published and cannot be pushed to Apple News.', 'apple-news'), $id)); return; } // Check the nonce. // If it isn't set, this isn't a form submission so we need to just display the form. if (!isset($_POST['apple_news_nonce'])) { return; } // If invalid, we need to display an error. if (!wp_verify_nonce($_POST['apple_news_nonce'], 'publish')) { $this->notice_error(__('Invalid nonce.', 'apple-news')); } // Save fields \Admin_Apple_Meta_Boxes::save_post_meta($id); $message = __('Settings saved.', 'apple-news'); // Push the post $action = new Apple_Actions\Index\Push($this->settings, $id); try { $action->perform(); // In async mode, success or failure will be displayed later if ('yes' !== $this->settings->get('api_async')) { $this->notice_success(__('Your article has been pushed successfully!', 'apple-news')); } else { $this->notice_success(__('Your article will be pushed shortly.', 'apple-news')); } } catch (Apple_Actions\Action_Exception $e) { $this->notice_error($e->getMessage()); } }