WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#32319 closed enhancement (wontfix)

the_content filter should provide reference to post

Reported by: shramee Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2.2
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

the_content filter must provide at least post_id or if possible whole post object, so that contents of different posts can be filtered in a different manner...

Change History (5)

#1 @SergeyBiryukov
6 years ago

  • Component changed from Administration to Posts, Post Types

Hi @shramee, welcome to Trac!

Unfortunately, a consistent fix does not seem feasible here. Even if we pass the post ID or object to all the instances in core, a lot of plugins and themes still use apply_filters( 'the_content', $content ) without passing the ID.

#2 @DrewAPicture
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

It's also worth mentioning that this a template tag, which is meant to be used in the loop where the $post global is accessible. In your filter callback, you can access the $post global with $post = get_post(). Closing as wontfix.

#3 @DrewAPicture
6 years ago

I should clarify that while this hook doesn't always get evaluated inside the loop (via the_content(), that was the original intent. In recent times since this hook was introduced in the very beginning of WordPress, it has been used for other purposes to simply format passed content. If you're using it in the loop, the $post global should be accessible as outlined above.

And as @SergeyBiryukov aptly pointed out, it's not really feasible to pass that value to every instance of the hook because of the variety of situations it's leveraged in today.

#4 @shramee
6 years ago

Thanks @SergeyBiryukov,
Thanks @DrewAPicture,

Though it would have been incredibly useful but I agree with issues of inconsistency. ;)

#5 @jrf
5 years ago

For reference: partial duplicate of #29014

Note: See TracTickets for help on using tickets.