/** * Handle performing an asynchronous push request. * * @access public * @param int $post_id * @param int $user_id * @since 1.0.0 */ public function async_push($post_id, $user_id) { // This hook could be used for an ini_set to increase max execution time // for asynchronous publishing to handle large push requests. // Since some hosts wouldn't support it, the code isn't added directly here. // // On WordPress VIP this isn't necessary since the plugin // will automatically use the jobs system which can handle requests up to 12 hours. do_action('apple_news_before_async_push'); // Ensure that the job can't be picked up twice $in_progress = get_post_meta($post_id, 'apple_news_api_async_in_progress', true); if (!empty($in_progress)) { return; } update_post_meta($post_id, 'apple_news_api_async_in_progress', time()); // Ensure that the post is still published $post = get_post($post_id); if ('publish' != $post->post_status) { Admin_Apple_Notice::error(sprintf(__('Article %s is no longer published and cannot be pushed to Apple News.', 'apple-news'), $post->post_title), $user_id); return; } $action = new Apple_Actions\Index\Push($this->settings, $post_id); try { $action->perform(true, $user_id); Admin_Apple_Notice::success(sprintf(__('Article %s has been pushed successfully to Apple News!', 'apple-news'), $post->post_title), $user_id); } catch (Apple_Actions\Action_Exception $e) { Admin_Apple_Notice::error($e->getMessage(), $user_id); } do_action('apple_news_after_async_push'); }
/** * Check for a publish action from the meta box. * * @since 0.9.0 * @param int $post_id * @param WP_Post $post * @access public */ public function do_publish($post_id, $post) { // Check if the values we want are present in $_REQUEST params. if (empty($_POST['apple_news_nonce']) || empty($_POST['post_ID'])) { return; } // Check the nonce if (!wp_verify_nonce($_POST['apple_news_nonce'], $this->publish_action)) { return; } // Save meta box fields $post_id = absint($_POST['post_ID']); self::save_post_meta($post_id); // If this is set to autosync or no action is set, we're done here if ('yes' == $this->settings->get('api_autosync') || 'publish' != $post->post_status || empty($_POST['apple_news_publish_action']) || $this->publish_action != $_POST['apple_news_publish_action']) { return; } // Proceed with the push $action = new Apple_Actions\Index\Push($this->settings, $post_id); try { $action->perform(); // In async mode, success or failure will be displayed later if ('yes' !== $this->settings->get('api_async')) { Admin_Apple_Notice::success(__('Your article has been pushed successfully to Apple News!', 'apple-news')); } else { Admin_Apple_Notice::success(__('Your article will be pushed shortly to Apple News.', 'apple-news')); } } catch (Apple_Actions\Action_Exception $e) { Admin_Apple_Notice::error($e->getMessage()); } }
/** * Shows a success message. * * @param string $message * @access public */ private function notice_success($message) { Admin_Apple_Notice::success($message); wp_safe_redirect(menu_page_url($this->plugin_slug . '_index', false)); exit; }
/** * Shows a success message. * * @param string $message * @access public */ private function notice_success($message) { Admin_Apple_Notice::success($message); $this->do_redirect(); }