/**
  * Send an update (add/change/delete) to LivePress' API
  *
  * @param string  $op     Operation (append/prepend/replace/delete)
  * @param WP_Post $post   Parent post object
  * @param WP_Post $update Update piece object
  *
  * @return array[] $region Object to send to editor
  */
 protected function send_to_livepress_incremental_post_update($op, $post, $update, $update_meta)
 {
     if (!is_object($post)) {
         $post = get_post($post);
     }
     if (!is_object($update)) {
         $update = get_post($update);
     }
     // FIXME: may be better use $update->post_author there ?
     $user = wp_get_current_user();
     if ($user->ID) {
         if (empty($user->display_name)) {
             $update_author = addslashes($user->user_login);
         }
         $update_author = addslashes($user->display_name);
     } else {
         $update_author = '';
     }
     list($_, $piece_id, $piece_gen) = explode('__', $update->post_title, 3);
     global $wp_filter;
     // Remove all the_content filters so child posts are not filtered
     // removing share, vote and other per-post items from the live update stream.
     // Store the filters first for later restoration so filters still fire outside the update stream
     $stored_wp_filter_the_content = $wp_filter;
     $this->clear_most_the_content_filters();
     $region = array('id' => $piece_id, 'lpg' => $piece_gen, 'op' => $op, 'content' => $update->post_content, 'proceed' => do_shortcode(apply_filters('the_content', $update->post_content)), 'prefix' => sprintf('<div id="livepress-update-%s" data-lpg="%d" class="livepress-update">', $piece_id, $piece_gen), 'suffix' => '</div>');
     // Restore the_content filters and carry on
     $wp_filter = $stored_wp_filter_the_content;
     $message = array('op' => $op, 'post_id' => $post->ID, 'post_title' => $post->post_title, 'post_link' => get_permalink($post->ID), 'post_author' => $update_author, 'update_id' => 'livepress-update-' . $piece_id, 'updated_at' => get_gmt_from_date(current_time('mysql')) . 'Z', 'uuid' => $piece_id . ':' . $piece_gen, 'edit' => json_encode($region));
     if ($op == 'replace') {
         $message['new_data'] = $region['prefix'] . $region['proceed'] . $region['suffix'];
     } elseif ($op == 'delete') {
         $region['content'] = '';
         // remove content from update for delete
         $region['proceed'] = '';
     } else {
         $message['data'] = $region['prefix'] . $region['proceed'] . $region['suffix'];
     }
     if (true !== $update_meta['draft']) {
         try {
             $job_uuid = $this->lp_comm->send_to_livepress_incremental_post_update($op, $message);
             LivePress_WP_Utils::save_on_post($post->ID, 'status_uuid', $job_uuid);
         } catch (livepress_communication_exception $e) {
             $e->log('incremental post update');
         }
     }
     // Set the parent post as having been updated
     $status = array('automatic' => 1, 'live' => 1);
     update_post_meta($post->ID, '_livepress_live_status', $status);
     $region['status'] = $status;
     // add meta to the child update
     update_post_meta($update->ID, '_livepress_update_meta', $update_meta);
     $region['update_meta'] = $update_meta;
     return $region;
 }