/** * Saves layout data when a user chooses to publish. * * @since 1.0 * @param bool $publish Whether to publish the parent post or not. * @return void */ public static function save_layout($publish = true) { $editor_content = FLBuilder::render_editor_content(); $post_id = self::get_post_id(); $data = self::get_layout_data('draft', $post_id); $settings = self::get_layout_settings('draft', $post_id); // Fire the before action. do_action('fl_builder_before_save_layout', $post_id, $publish, $data, $settings); // Delete the old published layout. self::delete_layout_data('published', $post_id); self::delete_layout_settings('published', $post_id); // Save the new published layout. self::update_layout_data($data, 'published', $post_id); self::update_layout_settings($settings, 'published', $post_id); // Clear the asset cache. self::delete_all_asset_cache($post_id); self::delete_node_template_asset_cache($post_id); // Enable the builder to take over the post content. self::enable(); // Get the post status. $post_status = get_post_status($post_id); // Publish the post? if ($publish) { $is_draft = strstr($post_status, 'draft'); $is_pending = strstr($post_status, 'pending'); if (current_user_can('publish_posts')) { $post_status = $is_draft || $is_pending ? 'publish' : $post_status; } else { if ($is_draft) { $post_status = 'pending'; } } } // Update the post with stripped down content. wp_update_post(array('ID' => self::get_post_id(), 'post_status' => $post_status, 'post_content' => $editor_content)); // Fire the after action. do_action('fl_builder_after_save_layout', $post_id, $publish, $data, $settings); }
/** * Saves layout data when a user chooses to publish. * * @since 1.0 * @param bool $publish Whether to publish the parent post or not. * @return void */ public static function save_layout($publish = true) { $editor_content = FLBuilder::render_editor_content(); $post_id = self::get_post_id(); $data = self::get_layout_data('draft', $post_id); // Delete the old published layout. self::delete_layout_data('published', $post_id); // Save the new published layout. self::update_layout_data($data, 'published', $post_id); // Clear the asset cache. self::delete_all_asset_cache($post_id); self::delete_node_template_asset_cache($post_id); // Enable the builder to take over the post content. self::enable(); // Get the post status. $post_status = get_post_status($post_id); // Publish the post? if ($publish) { $post_status = strstr($post_status, 'draft') ? 'publish' : $post_status; } // Update the post with stripped down content. wp_update_post(array('ID' => self::get_post_id(), 'post_status' => $post_status, 'post_content' => $editor_content)); }