From 3c33a74d60455cfd7d0121187a8eb9ebd8220040 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 3 Jan 2017 10:36:06 +0700 Subject: [PATCH 1/4] fix #45 keep page builder data when previewing post. still don't know how to enable preview for auto-draft. --- fx-builder.php | 4 ++-- includes/builder/builder.php | 22 ++++++++++++++------- includes/builder/front.php | 25 +++++++++++++++++++---- includes/builder/switcher.php | 37 +---------------------------------- readme.txt | 5 ++++- 5 files changed, 43 insertions(+), 50 deletions(-) diff --git a/fx-builder.php b/fx-builder.php index 361ac4e..46e6d89 100644 --- a/fx-builder.php +++ b/fx-builder.php @@ -3,7 +3,7 @@ * Plugin Name: f(x) Builder * Plugin URI: http://genbumedia.com/plugins/fx-builder/ * Description: A simple page builder plugin. The one you can actually use. (Alpha Version) - * Version: 1.0.0 + * Version: 1.0.1 * Author: David Chandra Purnama * Author URI: http://shellcreeper.com/ * License: GPLv2 or later @@ -24,7 +24,7 @@ define( 'FX_BUILDER_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) ); define( 'FX_BUILDER_FILE', __FILE__ ); define( 'FX_BUILDER_PLUGIN', plugin_basename( __FILE__ ) ); -define( 'FX_BUILDER_VERSION', '1.0.0' ); +define( 'FX_BUILDER_VERSION', '1.0.1' ); /* Init diff --git a/includes/builder/builder.php b/includes/builder/builder.php index 7399489..ae0a676 100644 --- a/includes/builder/builder.php +++ b/includes/builder/builder.php @@ -157,22 +157,28 @@ public function save( $post_id, $post ){ ------------------------------------------ */ $request = stripslashes_deep( $_POST ); if ( ! isset( $request['fxb_nonce'] ) || ! wp_verify_nonce( $request['fxb_nonce'], __FILE__ ) ){ - return false; - } - if( defined('DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){ - return false; + return $post_id; } $post_type = get_post_type_object( $post->post_type ); if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ){ - return false; + return $post_id; + } + $wp_preview = isset( $request['wp-preview'] ) ? esc_attr( $request['wp-preview'] ) : false; + if( $wp_preview ){ + return $post_id; } /* Check Swicther ------------------------------------------ */ - $active = get_post_meta( $post_id, '_fxb_active', true ); + $active = isset( $request['_fxb_active'] ) ? $request['_fxb_active'] : false; + /* Page Builder Active */ + if( $active ){ + update_post_meta( $post_id, '_fxb_active', 1 ); + } /* Page Builder Not Selected: Delete Data and Bail. */ - if( !$active ){ + else{ + delete_post_meta( $post_id, '_fxb_active' ); delete_post_meta( $post_id, '_fxb_db_version' ); delete_post_meta( $post_id, '_fxb_row_ids' ); delete_post_meta( $post_id, '_fxb_rows' ); @@ -180,6 +186,7 @@ public function save( $post_id, $post ){ return false; } + /* Page Builder Datas ------------------------------------------ */ @@ -256,6 +263,7 @@ public function save( $post_id, $post ){ add_action( 'save_post', array( $this, __FUNCTION__ ) ); } + /** * Admin Scripts * @since 1.0.0 diff --git a/includes/builder/front.php b/includes/builder/front.php index d522a16..9ebf69a 100644 --- a/includes/builder/front.php +++ b/includes/builder/front.php @@ -38,11 +38,28 @@ public function __construct() { * This will format content with page builder data. */ public function content_filter( $content ){ - $post_id = get_the_ID(); - $post_type = get_post_type( $post_id ); - $active = get_post_meta( $post_id, '_fxb_active', true ); + + /* Check Post Support */ + $post_id = get_the_ID(); + $post_type = get_post_type( $post_id ); + if( ! post_type_supports( $post_type, 'fx_builder' ) ){ + return $content; + } + + if( isset( $_GET['preview_id'] ) && !empty( $_GET['preview_id'] ) ){ + $autosave = wp_get_post_autosave( $_GET['preview_id'] ); + if( $autosave && $autosave->post_parent == $post_id ) { + $post_id = (int) $autosave->ID; + } + } + elseif( isset( $_GET['p'] ) && isset( $_GET['preview'] ) ){ + $revisions = wp_get_post_revisions( $post_id ); + $post_id = array_shift( $revisions ); + } + + $active = get_post_meta( $post_id, '_fxb_active', true ); remove_filter( 'the_content', 'wpautop' ); - if( post_type_supports( $post_type, 'fx_builder' ) && $active ){ + if( $active ){ $content = Functions::content( $post_id ); // autop added in this function. } else{ diff --git a/includes/builder/switcher.php b/includes/builder/switcher.php index d94dbdc..1821b33 100644 --- a/includes/builder/switcher.php +++ b/includes/builder/switcher.php @@ -6,6 +6,7 @@ /** * Switcher: Toggle between page builder / wp editor. + * Since v.1.0.1 Switcher save method is added in builder.php * @since 1.0.0 */ class Switcher{ @@ -30,9 +31,6 @@ public function __construct() { /* Add Editor/Page Builder Tab */ add_action( 'edit_form_after_title', array( $this, 'editor_toggle' ) ); - /* Save Switcher Preference */ - add_action( 'save_post', array( $this, 'save' ), 9, 2 ); - /* Scripts */ add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ), 99 ); } @@ -87,39 +85,6 @@ public function editor_toggle( $post ){ } - /** - * Save Switcher Pref - * @since 1.0.0 - */ - public function save( $post_id, $post ){ - $request = stripslashes_deep( $_POST ); - if ( ! isset( $request['fxb_switcher_nonce'] ) || ! wp_verify_nonce( $request['fxb_switcher_nonce'], __FILE__ ) ){ - return false; - } - if( defined('DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){ - return false; - } - $post_type = get_post_type_object( $post->post_type ); - if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ){ - return false; - } - - /* Save Builder Tab */ - if( isset( $request['_fxb_active'] ) ){ - $new_data = $request['_fxb_active'] ? 1 : 0; - if( $new_data ){ - update_post_meta( $post_id, '_fxb_active', 1 ); - } - else{ - delete_post_meta( $post_id, '_fxb_active' ); - } - } - else{ - delete_post_meta( $post_id, '_fxb_active' ); - } - } - - /** * Admin Scripts * @since 1.0.0 diff --git a/readme.txt b/readme.txt index 12afacc..7ec9ac4 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i Tags: Page Builder, Drag and Drop, Beta Requires at least: 4.5 Tested up to: 4.7 -Stable tag: 1.0.0 +Stable tag: 1.0.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -50,6 +50,9 @@ You can contribute to development at GitHub https://github.com/turtlepod/fx-buil == Changelog == += 1.0.1 - 03 Jan 2017 = +* Fix bug: wp preview remove page builder data https://github.com/turtlepod/fx-builder/issues/45 + = 1.0.0 - 09 Dec 2016 = * First Stable Release. From 5539eb2b9f1c26c60716571eb8c5e13b89add5e3 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 3 Jan 2017 21:40:05 +0700 Subject: [PATCH 2/4] Hide "Preview Changes" button in "Publish" meta box when page builder active. #45 --- includes/builder/assets/custom-css.css | 2 -- includes/builder/assets/switcher.css | 3 +++ includes/builder/builder.php | 3 +++ includes/builder/front.php | 12 +----------- includes/builder/revisions.php | 12 ++++++++++++ readme.txt | 3 +++ 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/includes/builder/assets/custom-css.css b/includes/builder/assets/custom-css.css index ecf4cc1..063d662 100644 --- a/includes/builder/assets/custom-css.css +++ b/includes/builder/assets/custom-css.css @@ -7,13 +7,11 @@ border: 1px solid #ccc; color: #555; font-weight: 400; - margin-right: -14px; display: none; } .rtl .fxb-nav-css{ float: left; margin-right: 0; - margin-left: -14px; } .fx_builder_active .fxb-nav-css{ display: block; diff --git a/includes/builder/assets/switcher.css b/includes/builder/assets/switcher.css index e725a7d..1cc238b 100644 --- a/includes/builder/assets/switcher.css +++ b/includes/builder/assets/switcher.css @@ -6,4 +6,7 @@ } .fx_builder_active #fxb-wrapper{ display: block !important; +} +.fx_builder_active #post-preview{ + display: none !important; } \ No newline at end of file diff --git a/includes/builder/builder.php b/includes/builder/builder.php index ae0a676..d9369e8 100644 --- a/includes/builder/builder.php +++ b/includes/builder/builder.php @@ -159,6 +159,9 @@ public function save( $post_id, $post ){ if ( ! isset( $request['fxb_nonce'] ) || ! wp_verify_nonce( $request['fxb_nonce'], __FILE__ ) ){ return $post_id; } + if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){ + return $post_id; + } $post_type = get_post_type_object( $post->post_type ); if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ){ return $post_id; diff --git a/includes/builder/front.php b/includes/builder/front.php index 9ebf69a..60c507e 100644 --- a/includes/builder/front.php +++ b/includes/builder/front.php @@ -46,18 +46,8 @@ public function content_filter( $content ){ return $content; } - if( isset( $_GET['preview_id'] ) && !empty( $_GET['preview_id'] ) ){ - $autosave = wp_get_post_autosave( $_GET['preview_id'] ); - if( $autosave && $autosave->post_parent == $post_id ) { - $post_id = (int) $autosave->ID; - } - } - elseif( isset( $_GET['p'] ) && isset( $_GET['preview'] ) ){ - $revisions = wp_get_post_revisions( $post_id ); - $post_id = array_shift( $revisions ); - } - $active = get_post_meta( $post_id, '_fxb_active', true ); + remove_filter( 'the_content', 'wpautop' ); if( $active ){ $content = Functions::content( $post_id ); // autop added in this function. diff --git a/includes/builder/revisions.php b/includes/builder/revisions.php index 3c0912b..c45adb6 100644 --- a/includes/builder/revisions.php +++ b/includes/builder/revisions.php @@ -43,12 +43,16 @@ public function save_revision( $post_id, $post ){ $parent = get_post( $parent_id ); + $active = get_post_meta( $parent->ID, '_fxb_active', true ); $db_version = get_post_meta( $parent->ID, '_fxb_db_version', true ); $row_ids = get_post_meta( $parent->ID, '_fxb_row_ids', true ); $rows = get_post_meta( $parent->ID, '_fxb_rows', true ); $items = get_post_meta( $parent->ID, '_fxb_items', true ); $css = get_post_meta( $parent->ID, '_fxb_custom_css', true ); + if ( $active ){ + add_metadata( 'post', $post_id, '_fxb_active', $active ); + } if ( false !== $db_version ){ add_metadata( 'post', $post_id, '_fxb_db_version', $db_version ); } @@ -76,12 +80,20 @@ public function restore_revision( $post_id, $revision_id ) { $revision = get_post( $revision_id ); + $active = get_metadata( 'post', $revision->ID, '_fxb_active', true ); $db_version = get_metadata( 'post', $revision->ID, '_fxb_db_version', true ); $row_ids = get_metadata( 'post', $revision->ID, '_fxb_row_ids', true ); $rows = get_metadata( 'post', $revision->ID, '_fxb_rows', true ); $items = get_metadata( 'post', $revision->ID, '_fxb_items', true ); $css = get_metadata( 'post', $revision->ID, '_fxb_custom_css', true ); + if ( $active ){ + update_post_meta( $post_id, '_fxb_active', $active ); + } + else{ + delete_post_meta( $post_id, '_fxb_active' ); + } + if ( false !== $db_version ){ update_post_meta( $post_id, '_fxb_db_version', $db_version ); } diff --git a/readme.txt b/readme.txt index 7ec9ac4..e122b8c 100644 --- a/readme.txt +++ b/readme.txt @@ -52,6 +52,9 @@ You can contribute to development at GitHub https://github.com/turtlepod/fx-buil = 1.0.1 - 03 Jan 2017 = * Fix bug: wp preview remove page builder data https://github.com/turtlepod/fx-builder/issues/45 +* Fix CSS Bug: Tools & CSS button position. +* Store _fxb_active in revisions. +* Hide "Preview Changes" button in "Publish" meta box when page builder active. = 1.0.0 - 09 Dec 2016 = * First Stable Release. From 44e25a3f546560ddac724100567b6096cf81d3ea Mon Sep 17 00:00:00 2001 From: David Date: Wed, 4 Jan 2017 19:05:59 +0700 Subject: [PATCH 3/4] fix fatal error in some install because $post not set. --- includes/builder/builder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/builder/builder.php b/includes/builder/builder.php index d9369e8..62a95c5 100644 --- a/includes/builder/builder.php +++ b/includes/builder/builder.php @@ -151,7 +151,7 @@ public function load_templates( $post_id ){ * Save Page Builder Data * @since 1.0.0 */ - public function save( $post_id, $post ){ + public function save( $post_id, $post = false ){ /* Prepare ------------------------------------------ */ @@ -162,6 +162,7 @@ public function save( $post_id, $post ){ if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){ return $post_id; } + if( ! $post ) return $post_id; $post_type = get_post_type_object( $post->post_type ); if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ){ return $post_id; From 303a689c0c8ec0c4c6c3dda2b52331424fa67f36 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 6 Jan 2017 09:37:27 +0700 Subject: [PATCH 4/4] fix fatal error bug in save_post hook. update readme. --- fx-builder.php | 4 ++-- includes/builder/builder.php | 5 ++--- readme.txt | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fx-builder.php b/fx-builder.php index 46e6d89..d35b922 100644 --- a/fx-builder.php +++ b/fx-builder.php @@ -3,7 +3,7 @@ * Plugin Name: f(x) Builder * Plugin URI: http://genbumedia.com/plugins/fx-builder/ * Description: A simple page builder plugin. The one you can actually use. (Alpha Version) - * Version: 1.0.1 + * Version: 1.0.2 * Author: David Chandra Purnama * Author URI: http://shellcreeper.com/ * License: GPLv2 or later @@ -24,7 +24,7 @@ define( 'FX_BUILDER_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) ); define( 'FX_BUILDER_FILE', __FILE__ ); define( 'FX_BUILDER_PLUGIN', plugin_basename( __FILE__ ) ); -define( 'FX_BUILDER_VERSION', '1.0.1' ); +define( 'FX_BUILDER_VERSION', '1.0.2' ); /* Init diff --git a/includes/builder/builder.php b/includes/builder/builder.php index 62a95c5..5ab68fa 100644 --- a/includes/builder/builder.php +++ b/includes/builder/builder.php @@ -151,7 +151,7 @@ public function load_templates( $post_id ){ * Save Page Builder Data * @since 1.0.0 */ - public function save( $post_id, $post = false ){ + public function save( $post_id, $post ){ /* Prepare ------------------------------------------ */ @@ -162,7 +162,6 @@ public function save( $post_id, $post = false ){ if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){ return $post_id; } - if( ! $post ) return $post_id; $post_type = get_post_type_object( $post->post_type ); if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ){ return $post_id; @@ -264,7 +263,7 @@ public function save( $post_id, $post = false ){ */ remove_action( 'save_post', array( $this, __FUNCTION__ ) ); wp_update_post( $this_post ); - add_action( 'save_post', array( $this, __FUNCTION__ ) ); + add_action( 'save_post', array( $this, __FUNCTION__ ), 10, 2 ); } diff --git a/readme.txt b/readme.txt index e122b8c..0bfa80f 100644 --- a/readme.txt +++ b/readme.txt @@ -55,6 +55,7 @@ You can contribute to development at GitHub https://github.com/turtlepod/fx-buil * Fix CSS Bug: Tools & CSS button position. * Store _fxb_active in revisions. * Hide "Preview Changes" button in "Publish" meta box when page builder active. +* Fix "save_post" hook to fix fatal error bug. = 1.0.0 - 09 Dec 2016 = * First Stable Release.