Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What should [bw_link ID] do when ?p=ID would produce a 404? #36

Closed
bobbingwide opened this issue May 25, 2016 · 1 comment
Closed

What should [bw_link ID] do when ?p=ID would produce a 404? #36

bobbingwide opened this issue May 25, 2016 · 1 comment

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented May 25, 2016

Imagine this scenario.

  • Some content contains a [bw_link ID] shortcode, where ID is the post ID of a registered post type.
  • Clicking on the link displays the post.
  • The post type is then de-registered

How should the link now appear?

Actual Result

It displays an invalid permalink conforming to the custom structure defined in Permalink Settings.

e.g. for post ID 32932, published on 2016/05/25, with slug 'reactjs', using the Day and name permalink structure we get http://example.com/2016/05/25/reactjs/

Clicking on the link displays the 404 page.

Expected result

Good question. Help wanted here.
See also humanmade/WordPress-Importer#38 (comment)

Notes about current implementation

  • Currently, when the post ID is NOT found e.g. [bw_link 1010101010101] then no link is shown.
  • When the post ID is 0, then it produces a link to the current post.
  • When the post ID is negative then no link is shown.
@bobbingwide
Copy link
Owner Author

The current logic uses get_permalink( $id ) to determine the permalink.

  • When passed a post ID, get_permalink calls get_post() to access the post.
  • It then checks the post_type to determine how to create the permalink - returning the correct format for "page", "attachment" and any registered post type that's not _builtin

Everything else is treated as a "post" using the permalink_structure option.

get_permalink() invokes the 'pre_post_link' filter first ( incorrectly documented as 'Only applies to posts with post_type of 'post' ). This filter hook is not normally implemented, so the permalink structure to be used is unchanged.

And just at the end of the function it invokes the "post_link" filter, also not normally implemented.

Conclusion

We could consider implementing the "post_link" filter to null out the result when the post type is not registered. But I don't think it's necessary.

I might raise a WordPress TRAC on the docblock for 'pre_post_link' though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant