@@ -202,9 +202,62 @@ protected function configure_faust(): void {
202202 // Remove FaustWP post preview link filter to avoid conflicts with our custom preview link generation.
203203 remove_filter ( 'preview_post_link ' , 'WPE\FaustWP\Replacement\post_preview_link ' , 1000 );
204204
205+ // Prevent Faust from redirecting preview URLs to the frontend in iframe mode.
206+ $ this ->disable_faust_redirects ();
207+
205208 $ this ->display_faust_admin_notice ();
206209 }
207210
211+ /**
212+ * Disable Faust's redirect functionality for preview URLs.
213+ */
214+ protected function disable_faust_redirects (): void {
215+ add_action ( 'template_redirect ' , function (): void {
216+ // Only run for preview URLs (e.g., ?p=ID&preview=true)
217+ if ( isset ( $ _GET ['preview ' ] ) && $ _GET ['preview ' ] === 'true ' ) {
218+ // Remove Faust's redirect callback
219+ remove_action ( 'template_redirect ' , 'WPE\FaustWP\Deny_Public_Access\deny_public_access ' , 99 );
220+ }
221+ }, 10 );
222+ }
223+
224+ /**
225+ * Check if Faust rewrites are enabled.
226+ *
227+ * @return bool
228+ */
229+ public function is_faust_rewrites_enabled (): bool {
230+ return $ this ->get_faust_enabled ()
231+ && function_exists ('\WPE\FaustWP\Settings\is_rewrites_enabled ' )
232+ && \WPE \FaustWP \Settings \is_rewrites_enabled ();
233+ }
234+
235+ /**
236+ * Replace Faust preview rewrites with the home URL.
237+ *
238+ * @param string $url The URL to be rewritten.
239+ *
240+ * @return string
241+ */
242+ public function replace_faust_preview_rewrite ($ url ): string {
243+ if ( function_exists ( '\WPE\FaustWP\Settings\faustwp_get_setting ' ) ) {
244+ $ frontend_uri = \WPE \FaustWP \Settings \faustwp_get_setting ( 'frontend_uri ' );
245+
246+ // Return the URL as is if frontend uri is empty.
247+ if ( ! $ frontend_uri ) {
248+ return $ url ;
249+ }
250+
251+ $ frontend_uri = trailingslashit ( $ frontend_uri );
252+ $ home_url = trailingslashit ( get_home_url () );
253+
254+
255+ return str_replace ( $ frontend_uri , get_home_url (), $ url );
256+ }
257+
258+ return $ url ;
259+ }
260+
208261 /**
209262 * If Faust is enabled, show an admin notice about the migration on the settings page.
210263 */
0 commit comments