/**
  * Saves the layout and returns the layout ID key.
  * Layout ID key is *not* the same as layout ID,
  * it's a hash used to resolve this particular layout.
  * @param Upfront_Layout $layout layout to store
  * @return mixed (bool)false on failure, (string)layout ID key on success
  */
 public function save_revision($layout)
 {
     $cascade = $layout->get_cascade();
     $store = $layout->to_php();
     $layout_id_key = self::to_hash($store);
     $existing_revision = $this->get_revision($layout_id_key);
     if (!empty($existing_revision)) {
         return $layout_id_key;
     }
     $post_id = wp_insert_post(array("post_content" => base64_encode(serialize($store)), "post_title" => self::to_string($cascade), "post_name" => $layout_id_key, "post_type" => self::REVISION_TYPE, "post_status" => self::REVISION_STATUS, "post_author" => get_current_user_id()));
     return !empty($post_id) && !is_wp_error($post_id) ? $layout_id_key : false;
 }
 /**
  * This fires in style parsing AJAX request and overrides the used layout.
  *
  * @param Upfront_Layout $layout Style layout for parsing
  * @return Upfront_Layout
  */
 public function intercept_style_loading($layout)
 {
     $key = !empty($_GET['layout']['layout_revision']) ? $_GET['layout']['layout_revision'] : false;
     if (empty($key)) {
         return $layout;
     }
     $cascade = $layout->get_cascade();
     $src_key = !empty($cascade['layout_revision']) ? $cascade['layout_revision'] : false;
     if ($key != $src_key) {
         return $layout;
     }
     $raw = $this->_data->get_revision($key);
     if (!empty($raw)) {
         $layout = Upfront_Layout::from_php($raw);
     }
     return $layout;
 }