Admin_Apple_Meta_Boxes::save_post_meta PHP Method

save_post_meta() public static method

Saves the Apple News meta fields associated with a post
public static save_post_meta ( integer $post_id )
$post_id integer
    public static function save_post_meta($post_id)
    {
        // Save fields from the meta box
        if (!empty($_POST['apple_news_sections'])) {
            $sections = array_map('sanitize_text_field', $_POST['apple_news_sections']);
        } else {
            $sections = array();
        }
        update_post_meta($post_id, 'apple_news_sections', $sections);
        if (!empty($_POST['apple_news_is_preview']) && 1 === intval($_POST['apple_news_is_preview'])) {
            $is_preview = true;
        } else {
            $is_preview = false;
        }
        update_post_meta($post_id, 'apple_news_is_preview', $is_preview);
        if (!empty($_POST['apple_news_pullquote'])) {
            $pullquote = sanitize_text_field($_POST['apple_news_pullquote']);
        } else {
            $pullquote = '';
        }
        update_post_meta($post_id, 'apple_news_pullquote', $pullquote);
        if (!empty($_POST['apple_news_pullquote_position'])) {
            $pullquote_position = sanitize_text_field($_POST['apple_news_pullquote_position']);
        } else {
            $pullquote_position = 'middle';
        }
        update_post_meta($post_id, 'apple_news_pullquote_position', $pullquote_position);
    }

Usage Example

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