PluginProbe
Faust.js / 1.0.2
Faust.js v1.0.2
1.8.12 1.8.11 1.4.1 1.8.0 1.8.8 1.8.9 trunk 0.7.0 0.7.1 0.7.10 0.7.11 0.7.3 0.7.4 0.7.5 0.7.6 0.7.7 0.7.8 0.7.9 0.8.0 0.8.1 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 All 40 releases
← All changes | includes/replacement/callbacks.php +62 -35 0.7.31.0.2 View file →
@@ -113,23 +113,26 @@
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 - $frontend_uri_path = wp_parse_url( $frontend_uri, PHP_URL_PATH );
126 - $parsed_link_path = wp_parse_url( $link, PHP_URL_PATH );
127 - $link_path = str_replace( $frontend_uri_path, '', $parsed_link_path );
128 - $path = trailingslashit( $link_path );
133 + $preview_id = isset( $args['preview_id'] ) ? $args['preview_id'] : $post->ID;
129 134
130 - $preview_id = isset( $args['preview_id'] ) ? $args['preview_id'] : $post->ID;
131 -
132 135 // Remove ?p=xx&preview=true from link temporarily.
133 136 $link = remove_query_arg(
134 137 array_keys( $args ),
135 138 $link
@@ -134,13 +137,22 @@
134 137 array_keys( $args ),
135 138 $link
136 139 );
137 140
141 + if ( ! isset( $args['previewPathname'] ) ) {
142 + $args['previewPathname'] = rawurlencode( wp_make_link_relative( get_permalink( $post ) ) );
143 + }
144 +
138 145 // Add p=xx if it's missing, which is the case for published posts.
139 146 if ( ! isset( $args['p'] ) ) {
140 147 $args['p'] = $preview_id;
141 148 }
142 149
150 + // Add preview=true in case other plugins have stripped it.
151 + if ( ! isset( $args['preview'] ) ) {
152 + $args['preview'] = 'true';
153 + }
154 +
143 155 // Add page_id=xx if it's missing, which is the case for published pages.
144 156 if ( ! isset( $args['page_id'] ) && 'page' === $post->post_type ) {
145 157 $args['page_id'] = $preview_id;
146 158 }
@@ -151,17 +163,17 @@
151 163 * need to determine the preview node post type before retrieving
152 164 * the data.
153 165 */
154 166 $post_type_object = get_post_type_object( $post->post_type );
155 - 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 + ) {
156 172 $gql_type_name = ucfirst( $post_type_object->graphql_single_name );
157 173 $args['typeName'] = $gql_type_name;
158 174 }
159 175
160 - $untrailingslash_frontend_uri = untrailingslashit( $frontend_uri );
161 - $unleadingslash_path = ltrim( $path, '/\\' );
162 - $link = $untrailingslash_frontend_uri . '/' . $unleadingslash_path;
163 -
164 176 // Add ?p=xx&preview=true to link again.
165 177 $link = add_query_arg(
166 178 array(
167 179 $args,
@@ -172,15 +184,13 @@
172 184
173 185 return $link;
174 186 }
175 187
176 -
177 188 add_filter( 'post_link', __NAMESPACE__ . '\\post_link', 1000 );
189 +add_filter( 'page_link', __NAMESPACE__ . '\\post_link', 1000 );
178 190 /**
179 - * Callback for WordPress 'preview_post_link' filter and 'post_link' filter.
191 + * Callback for WordPress 'post_link' & 'page_link' filter.
180 192 *
181 - * Callback for WordPress 'post_link' filter.
182 - *
183 193 * Swap post links in admin for headless front-end.
184 194 *
185 195 * @param string $link URL used for the post.
186 196 *
@@ -193,15 +203,9 @@
193 203 ) {
194 204 return $link;
195 205 }
196 206
197 - $frontend_uri = faustwp_get_setting( 'frontend_uri' );
198 -
199 - if ( $frontend_uri ) {
200 - return str_replace( trailingslashit( get_home_url() ), trailingslashit( $frontend_uri ), $link );
201 - }
202 -
203 - return $link;
207 + return equivalent_frontend_url( $link );
204 208 }
205 209
206 210 add_filter( 'term_link', __NAMESPACE__ . '\\term_link', 1000 );
207 211 /**
@@ -215,18 +219,9 @@
215 219 if ( ! is_rewrites_enabled() ) {
216 220 return $term_link;
217 221 }
218 222
219 - $frontend_uri = faustwp_get_setting( 'frontend_uri' );
220 -
221 - if ( empty( $frontend_uri ) ) {
222 - return $term_link;
223 - }
224 -
225 - $frontend_uri = trailingslashit( $frontend_uri );
226 - $site_url = trailingslashit( site_url() );
227 -
228 - return str_replace( $site_url, $frontend_uri, $term_link );
223 + return equivalent_frontend_url( $term_link );
229 224 }
230 225
231 226
232 227 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\enqueue_preview_scripts' );
@@ -235,7 +230,39 @@
235 230 *
236 231 * XXX: Please remove this once this issue is resolved: https://github.com/WordPress/gutenberg/issues/13998
237 232 */
238 233 function enqueue_preview_scripts() {
239 - 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 );
240 235 wp_localize_script( 'faustwp-gutenberg-filters', '_faustwp_preview_link', array( '_preview_link' => get_preview_post_link() ) );
236 +}
237 +
238 +add_filter( 'wp_sitemaps_posts_entry', __NAMESPACE__ . '\\sitemaps_posts_entry' );
239 +/**
240 + * Filters the sitemap entry for an individual post.
241 + *
242 + * @param array $sitemap_entry Sitemap entry for the post.
243 + */
244 +function sitemaps_posts_entry( $sitemap_entry ) {
245 + return normalize_sitemap_entry( $sitemap_entry );
246 +}
247 +
248 +add_filter( 'wp_sitemaps_taxonomies_entry', __NAMESPACE__ . '\\sitemaps_taxonomies_entry' );
249 +/**
250 + * Filters the sitemap entry for an individual term.
251 + *
252 + * @param array $sitemap_entry Sitemap entry for the term.
253 + */
254 +function sitemaps_taxonomies_entry( $sitemap_entry ) {
255 + return normalize_sitemap_entry( $sitemap_entry );
256 +}
257 +
258 +add_filter( 'wpseo_xml_sitemap_post_url', __NAMESPACE__ . '\\yoast_sitemap_post_url' );
259 +/**
260 + * Filter the URL Yoast SEO uses in the XML sitemap.
261 + *
262 + * Note that only absolute local URLs are allowed as the check after this removes external URLs.
263 + *
264 + * @param string $url URL to use in the XML sitemap.
265 + */
266 +function yoast_sitemap_post_url( $url ) {
267 + return equivalent_wp_url( $url );
241 268 }