@@ -181,6 +181,41 @@ public function register_faust_admin_notice(): void {
181
181
}, 10 , 0 );
182
182
}
183
183
184
+ /**
185
+ * Check if Faust rewrites are enabled.
186
+ */
187
+ public function is_faust_rewrites_enabled (): bool {
188
+ if ( $ this ->get_faust_enabled () && function_exists ( '\WPE\FaustWP\Settings\is_rewrites_enabled ' ) ) {
189
+ return (bool ) \WPE \FaustWP \Settings \is_rewrites_enabled ();
190
+ }
191
+
192
+ return false ;
193
+ }
194
+
195
+ /**
196
+ * Replace Faust preview rewrites with the home URL.
197
+ *
198
+ * @param string $url The URL to be rewritten.
199
+ */
200
+ public function replace_faust_preview_rewrite ($ url ): string {
201
+ if ( ! function_exists ( '\WPE\FaustWP\Settings\faustwp_get_setting ' ) ) {
202
+ return $ url ;
203
+ }
204
+
205
+ $ frontend_uri = \WPE \FaustWP \Settings \faustwp_get_setting ( 'frontend_uri ' );
206
+
207
+ // Return the URL as is if frontend uri is empty.
208
+ if ( ! $ frontend_uri ) {
209
+ return $ url ;
210
+ }
211
+
212
+ $ frontend_uri = trailingslashit ( $ frontend_uri );
213
+ $ home_url = trailingslashit ( get_home_url () );
214
+
215
+
216
+ return str_replace ( $ frontend_uri , $ home_url , $ url );
217
+ }
218
+
184
219
/**
185
220
* Dismiss the Faust admin notice.
186
221
*/
@@ -202,9 +237,26 @@ protected function configure_faust(): void {
202
237
// Remove FaustWP post preview link filter to avoid conflicts with our custom preview link generation.
203
238
remove_filter ( 'preview_post_link ' , 'WPE\FaustWP\Replacement\post_preview_link ' , 1000 );
204
239
240
+ // Prevent Faust from redirecting preview URLs to the frontend in iframe mode.
241
+ $ this ->disable_faust_redirects ();
242
+
205
243
$ this ->display_faust_admin_notice ();
206
244
}
207
245
246
+ /**
247
+ * Disable Faust's redirect functionality for preview URLs.
248
+ */
249
+ protected function disable_faust_redirects (): void {
250
+ add_action ( 'template_redirect ' , static function (): void {
251
+ // Only run for preview URLs (e.g., ?p=ID&preview=true).
252
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification not required for disabling front-end redirects.
253
+ if ( isset ( $ _GET ['preview ' ] ) && 'true ' === $ _GET ['preview ' ] ) {
254
+ // Remove Faust's redirect callback.
255
+ remove_action ( 'template_redirect ' , 'WPE\FaustWP\Deny_Public_Access\deny_public_access ' , 99 );
256
+ }
257
+ }, 10 , 0 );
258
+ }
259
+
208
260
/**
209
261
* If Faust is enabled, show an admin notice about the migration on the settings page.
210
262
*/
0 commit comments