| @@ -113,14 +113,22 @@ | ||
| 113 | 113 | |
| 114 | 114 | if ( $frontend_uri ) { |
| 115 | 115 | $home_url = trailingslashit( get_home_url() ); |
| 116 | 116 | $frontend_uri = trailingslashit( $frontend_uri ); |
| 117 | + | |
| 118 | + $link = str_replace( $home_url, $frontend_uri, $link ); | |
| 119 | + | |
| 120 | + // Replace the schemes, if different. | |
| 121 | + $frontend_uri_scheme = wp_parse_url( $frontend_uri, PHP_URL_SCHEME ); | |
| 122 | + $link_scheme = wp_parse_url( $link, PHP_URL_SCHEME ); | |
| 123 | + if ( $frontend_uri_scheme !== $link_scheme ) { | |
| 124 | + $link = str_replace( $link_scheme . '://', $frontend_uri_scheme . '://', $link ); | |
| 125 | + } | |
| 126 | + | |
| 117 | 127 | /** |
| 118 | 128 | * This should already be handled by WPE\FaustWP\Replacement\post_link, but |
| 119 | 129 | * it's here for verbosity's sake and if the other filter changes for any reason. |
| 120 | 130 | */ |
| 121 | - $link = str_replace( $home_url, $frontend_uri, $link ); | |
| 122 | - | |
| 123 | 131 | $parsed_link_query = wp_parse_url( $link, PHP_URL_QUERY ); |
| 124 | 132 | $args = wp_parse_args( $parsed_link_query ); |
| 125 | 133 | $preview_id = isset( $args['preview_id'] ) ? $args['preview_id'] : $post->ID; |
| 126 | 134 | |
| @@ -129,13 +137,22 @@ | ||
| 129 | 137 | array_keys( $args ), |
| 130 | 138 | $link |
| 131 | 139 | ); |
| 132 | 140 | |
| 141 | + if ( ! isset( $args['previewPathname'] ) ) { | |
| 142 | + $args['previewPathname'] = rawurlencode( wp_make_link_relative( get_permalink( $post ) ) ); | |
| 143 | + } | |
| 144 | + | |
| 133 | 145 | // Add p=xx if it's missing, which is the case for published posts. |
| 134 | 146 | if ( ! isset( $args['p'] ) ) { |
| 135 | 147 | $args['p'] = $preview_id; |
| 136 | 148 | } |
| 137 | 149 | |
| 150 | + // Add preview=true in case other plugins have stripped it. | |
| 151 | + if ( ! isset( $args['preview'] ) ) { | |
| 152 | + $args['preview'] = 'true'; | |
| 153 | + } | |
| 154 | + | |
| 138 | 155 | // Add page_id=xx if it's missing, which is the case for published pages. |
| 139 | 156 | if ( ! isset( $args['page_id'] ) && 'page' === $post->post_type ) { |
| 140 | 157 | $args['page_id'] = $preview_id; |
| 141 | 158 | } |
| @@ -146,9 +163,13 @@ | ||
| 146 | 163 | * need to determine the preview node post type before retrieving |
| 147 | 164 | * the data. |
| 148 | 165 | */ |
| 149 | 166 | $post_type_object = get_post_type_object( $post->post_type ); |
| 150 | - if ( ! isset( $args['typeName'] ) && isset( $post_type_object ) ) { | |
| 167 | + if ( | |
| 168 | + ! isset( $args['typeName'] ) && | |
| 169 | + isset( $post_type_object ) && | |
| 170 | + ! empty( $post_type_object->graphql_single_name ) | |
| 171 | + ) { | |
| 151 | 172 | $gql_type_name = ucfirst( $post_type_object->graphql_single_name ); |
| 152 | 173 | $args['typeName'] = $gql_type_name; |
| 153 | 174 | } |
| 154 | 175 | |
| @@ -163,12 +184,12 @@ | ||
| 163 | 184 | |
| 164 | 185 | return $link; |
| 165 | 186 | } |
| 166 | 187 | |
| 167 | - | |
| 168 | 188 | add_filter( 'post_link', __NAMESPACE__ . '\\post_link', 1000 ); |
| 189 | +add_filter( 'page_link', __NAMESPACE__ . '\\post_link', 1000 ); | |
| 169 | 190 | /** |
| 170 | - * Callback for WordPress 'post_link' filter. | |
| 191 | + * Callback for WordPress 'post_link' & 'page_link' filter. | |
| 171 | 192 | * |
| 172 | 193 | * Swap post links in admin for headless front-end. |
| 173 | 194 | * |
| 174 | 195 | * @param string $link URL used for the post. |
| @@ -209,9 +230,9 @@ | ||
| 209 | 230 | * |
| 210 | 231 | * XXX: Please remove this once this issue is resolved: https://github.com/WordPress/gutenberg/issues/13998 |
| 211 | 232 | */ |
| 212 | 233 | function enqueue_preview_scripts() { |
| 213 | - wp_enqueue_script( 'faustwp-gutenberg-filters', plugins_url( '/previewlinks.js', __FILE__ ), array(), '1.0.0', true ); | |
| 234 | + wp_enqueue_script( 'faustwp-gutenberg-filters', plugins_url( '/previewlinks.js', __FILE__ ), array( 'jquery' ), '1.0.0', true ); | |
| 214 | 235 | wp_localize_script( 'faustwp-gutenberg-filters', '_faustwp_preview_link', array( '_preview_link' => get_preview_post_link() ) ); |
| 215 | 236 | } |
| 216 | 237 | |
| 217 | 238 | add_filter( 'wp_sitemaps_posts_entry', __NAMESPACE__ . '\\sitemaps_posts_entry' ); |