/**
* 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');
}