Skip to content

Commit

Permalink
Fix CPT URL Rewrites (#1590)
Browse files Browse the repository at this point in the history
Fix: swap traditional custom post type URLs in WordPress admin for the headless frontend custom post type URLs.

Add unit test

Update existing unit test since we now support CPT rewrites

Add changeset

---------

Co-authored-by: John Parris <[email protected]>
Co-authored-by: Blake Wilson <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2024
1 parent 11401ee commit 05cc940
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-dolls-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@faustwp/wordpress-plugin': patch
---

Fix: swap traditional custom post type URLs in WordPress admin for the headless frontend custom post type URLs.
3 changes: 2 additions & 1 deletion plugins/faustwp/includes/replacement/callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ function post_preview_link( $link, $post ) {

add_filter( 'post_link', __NAMESPACE__ . '\\post_link', 1000 );
add_filter( 'page_link', __NAMESPACE__ . '\\post_link', 1000 );
add_filter( 'post_type_link', __NAMESPACE__ . '\\post_link', 1000 );
/**
* Callback for WordPress 'post_link' & 'page_link' filter.
* Callback for WordPress 'post_link', 'page_link', and `post_type_link` filter.
*
* Swap post links in admin for headless front-end.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public function test_page_link_filter() {
public function test_term_link_filter() {
$this->assertSame( 1000, has_action( 'term_link', 'WPE\FaustWP\Replacement\term_link' ) );
}

public function test_post_type_link_filter() {
$this->assertSame( 1000, has_filter( 'post_type_link', 'WPE\FaustWP\Replacement\post_link' ) );
}

public function test_enqueue_preview_scripts_action() {
$this->assertSame( 10, has_action( 'enqueue_block_editor_assets', 'WPE\FaustWP\Replacement\enqueue_preview_scripts' ) );
Expand Down Expand Up @@ -286,12 +290,12 @@ public function test_custom_post_type_post_preview_link_returns_filtered_link_wh
/**
* Tests get_permalink() does not modify original value when content replacement is enabled for Custom Post Types
*/
public function test_custom_post_type_post_link_returns_unfiltered_link_when_content_replacement_is_enabled()
public function test_custom_post_type_post_link_returns_filtered_link_when_content_replacement_is_enabled()
{
faustwp_update_setting( 'frontend_uri', 'http://moo' );
faustwp_update_setting( 'enable_rewrites', '1' );
$post_id = $this->getCustomPostType();
$this->assertSame( 'http://example.org/?document=' . $post_id, get_permalink($post_id) );
$this->assertSame( 'http://moo/?document=' . $post_id, get_permalink($post_id) );
faustwp_update_setting( 'frontend_uri', null );
faustwp_update_setting( 'enable_redirects', false );
}
Expand Down

0 comments on commit 05cc940

Please sign in to comment.