diff --git a/CHANGELOG.md b/CHANGELOG.md index 476193b..93601eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 1.1.3 + +- The uri field was being overwritten during GraphQL requests, resulting in post uri's that included the content sync URL. +- Some logic attempting to choose the correct manifest ID instead of regenerating it was causing manifest id's to be outdated during previews. + ## 1.1.2 - Fixed redirection to Gatsby Cloud Content Sync preview loader in Gutenberg diff --git a/readme.txt b/readme.txt index 2dff557..c7ead14 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: Gatsby, GatsbyJS, JavaScript, JAMStack, Static Site generator, GraphQL, He Requires at least: 5.4.2 Tested up to: 5.6 Requires PHP: 7.3 -Stable tag: 1.1.2 +Stable tag: 1.1.3 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html diff --git a/src/ActionMonitor/Monitors/PostMonitor.php b/src/ActionMonitor/Monitors/PostMonitor.php index 76eaa45..0066f15 100644 --- a/src/ActionMonitor/Monitors/PostMonitor.php +++ b/src/ActionMonitor/Monitors/PostMonitor.php @@ -58,6 +58,10 @@ public function callback_transition_post_status( $new_status, $old_status, WP_Po return; } + if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { + return; + } + // If the object is not a valid post, ignore it if ( ! is_a( $post, 'WP_Post' ) ) { return; diff --git a/src/Admin/Preview.php b/src/Admin/Preview.php index 9bc598f..fec5ade 100644 --- a/src/Admin/Preview.php +++ b/src/Admin/Preview.php @@ -23,8 +23,14 @@ function() { ); $use_cloud_loader = self::get_setting( 'use_gatsby_content_sync' ); - - if ( $use_cloud_loader === 'on' ) { + + if ( + $use_cloud_loader === 'on' && + // don't do this during graphql requests + // because that could override the post URI + // in Gatsby! meaning the content sync url could be added to the page path in Gatsby if pages are created from the uri. + ! ( defined( 'GRAPHQL_REQUEST' ) && true === GRAPHQL_REQUEST ) + ) { add_filter( 'preview_post_link', function( $link, $post ) { return self::get_gatsby_content_sync_url_for_post( $post ); }, 10, 2 ); @@ -33,73 +39,6 @@ function() { } public static function get_preview_manifest_id_for_post( $post ) { - $graphql_single_name = - get_post_type_object( $post->post_type ) - ->graphql_single_name; - - if ( !$graphql_single_name || $graphql_single_name === "" ) { - // if we don't have a graphql single name - // Gatsby can't use this post anyway. - // No need to return a manifest - return null; - } - - $action_monitor_posts = new \WP_Query( [ - 'post_type' => 'action_monitor', - 'post_status' => 'any', - 'posts_per_page' => 1, - 'no_found_rows' => true, - 'fields' => 'ids', - 'tax_query' => [ - 'relation' => 'AND', - [ - 'taxonomy' => 'gatsby_action_ref_node_dbid', - 'field' => 'name', - 'terms' => sanitize_text_field( $post->ID ), - ], - [ - 'taxonomy' => 'gatsby_action_ref_node_type', - 'field' => 'name', - 'terms' => sanitize_text_field( $graphql_single_name ), - ], - [ - 'taxonomy' => 'gatsby_action_stream_type', - 'field' => 'name', - 'terms' => 'PREVIEW', - ] - ], - ] ); - - if ( - isset( $action_monitor_posts->posts ) - && ! empty( $action_monitor_posts->posts ) - ) { - $action_monitor_post_id = $action_monitor_posts->posts[0]; - $referenced_node_preview_data = get_post_meta( - $action_monitor_post_id, - '_gatsby_preview_data', - true - ); - - $preview_data = false; - - if ( - $referenced_node_preview_data - && $referenced_node_preview_data !== "" - ) { - $preview_data = json_decode( $referenced_node_preview_data ); - } - - if ( - $preview_data - && property_exists( $preview_data, 'manifestIds' ) - && count( $preview_data->manifestIds ) > 0 - ) { - return $preview_data->manifestIds[0]; - } - } - - // if the above doesn't return a value we generate a new manifest ID from the post_modified date and post db id $revision = self::getPreviewablePostObjectByPostId( $post->ID ); $revision_modified = $revision->post_modified ?? null; diff --git a/wp-gatsby.php b/wp-gatsby.php index eb17b46..4f0130f 100644 --- a/wp-gatsby.php +++ b/wp-gatsby.php @@ -2,7 +2,7 @@ /** * Plugin Name: WP Gatsby * Description: Optimize your WordPress site to be a source for Gatsby sites. - * Version: 1.1.2 + * Version: 1.1.3 * Author: GatsbyJS, Jason Bahl, Tyler Barnes * Author URI: https://gatsbyjs.org * Text Domain: wp-gatsby @@ -103,7 +103,7 @@ private function setup_constants() { // Plugin version. if (! defined('WPGATSBY_VERSION') ) { - define('WPGATSBY_VERSION', '1.1.2'); + define('WPGATSBY_VERSION', '1.1.3'); } // Plugin Folder Path.