diff --git a/plugins/faustwp/includes/replacement/callbacks.php b/plugins/faustwp/includes/replacement/callbacks.php index 9cf215124..efbf33315 100644 --- a/plugins/faustwp/includes/replacement/callbacks.php +++ b/plugins/faustwp/includes/replacement/callbacks.php @@ -11,8 +11,8 @@ faustwp_get_setting, is_image_source_replacement_enabled, is_rewrites_enabled, + is_redirects_enabled, use_wp_domain_for_media, - use_wp_domain_for_post_and_category_urls, }; use function WPE\FaustWP\Utilities\{ plugin_version, @@ -146,6 +146,10 @@ function image_source_srcset_replacement( $sources ) { * @return string URL used for the post preview. */ function post_preview_link( $link, $post ) { + // Don't rewrite preview link if redirect is disabled. + if ( ! is_redirects_enabled() ) { + return $link; + } $frontend_uri = faustwp_get_setting( 'frontend_uri' ); if ( $frontend_uri ) { diff --git a/plugins/faustwp/tests/integration/ReplacementCallbacksTests.php b/plugins/faustwp/tests/integration/ReplacementCallbacksTests.php index 6ad1c77a5..d078cbdcd 100644 --- a/plugins/faustwp/tests/integration/ReplacementCallbacksTests.php +++ b/plugins/faustwp/tests/integration/ReplacementCallbacksTests.php @@ -210,6 +210,7 @@ public function test_post_link_returns_unfiltered_link_on_ajax_requests_to_gener */ public function test_post_preview_link_returns_filtered_link() { faustwp_update_setting( 'frontend_uri', 'http://moo' ); + faustwp_update_setting( 'enable_redirects', true ); $this->assertSame( 'http://moo/?p=' . $this->post_id . '&preview=true&previewPathname=' . rawurlencode( wp_make_link_relative( get_permalink( $this->post_id ) ) ) . '&typeName=Post', get_preview_post_link( $this->post_id ) ); } @@ -219,12 +220,26 @@ public function test_post_preview_link_returns_filtered_link() { */ public function test_post_preview_link_adds_preview_true_query_param() { faustwp_update_setting( 'frontend_uri', 'http://moo' ); + faustwp_update_setting( 'enable_redirects', true ); $link = post_preview_link( 'http://moo/', get_post( $this->post_id ) ); $this->assertSame( 'http://moo/?previewPathname=' . rawurlencode( wp_make_link_relative( get_permalink( $this->post_id ) ) ) . '&p=' . $this->post_id . '&preview=true&typeName=Post', $link ); } + /** + * Tests post_preview_link() doesn't rewrite link if enable redirects is false. + */ + public function test_post_preview_doesnt_rewrite_link_with_redirect_off() { + faustwp_update_setting( 'enable_redirects', false ); + $expected = 'http://moo/?p=' . $this->post_id; + $link = post_preview_link( $expected, get_post( $this->post_id ) ); + + $this->assertSame( $expected, $link ); + + faustwp_update_setting( 'enable_redirects', true ); + } + /** * Tests post_preview_link() uses frontend_uri scheme if different than home_url scheme. */ @@ -244,7 +259,8 @@ public function test_post_preview_link_uses_frontend_uri_scheme() { public function test_custom_post_type_post_preview_link_returns_filtered_link_when_content_replacement_is_enabled() { faustwp_update_setting( 'frontend_uri', 'http://moo' ); - faustwp_update_setting( 'enable_rewrites', '1' ); + faustwp_update_setting( 'enable_rewrites', true ); + faustwp_update_setting( 'enable_redirects', true ); $post_id = $this->getCustomPostType(); $this->assertSame( 'http://moo/?document=' . $post_id . '&preview=true&previewPathname=' . rawurlencode( wp_make_link_relative( get_permalink( $post_id ) ) ) . '&p=' . $post_id . '&typeName=Document', get_preview_post_link( $post_id ) ); faustwp_update_setting( 'frontend_uri', null ); @@ -269,6 +285,7 @@ public function test_custom_post_type_post_link_returns_unfiltered_link_when_con */ public function test_post_preview_link_filters_link_for_posts_not_registered_with_wpgraphql() { faustwp_update_setting( 'frontend_uri', 'http://moo' ); + faustwp_update_setting( 'enable_redirects', true ); register_post_type('notgraphql', ['public' => true]);