WordPress.org

Make WordPress Core

Opened 11 months ago

Last modified 5 weeks ago

#41179 new enhancement

Adding get_the_content-filter

Reported by: Ninos Ego Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8
Component: Themes Keywords: needs-codex dev-feedback
Focuses: docs, template Cc:

Description

Hey there, atm I cannot replace the content by a custom on, because of missing filter for get_the_content().

Attached a patch for this.

Attachments (1)

get_the_content_filter.patch (1.6 KB) - added by Ninos Ego 11 months ago.

Download all attachments as: .zip

Change History (8)

#1 @Ninos Ego
11 months ago

  • Keywords has-patch needs-codex dev-feedback added

#2 @Ninos Ego
11 months ago

BTW the function get_the_content() and the_content() seems too much inconsistent compared with e.g. get_the_excerpt() and the_excerpt(). Also it looks too much complex (job could surely be done in an easier way). May it needs a complete refactoring.

Pro:

  • Cleaner code (more consistent)
    • Easier to maintain
    • For devs: easier to understand and implement

Contra:

  • Theme and plugin authors may need to refactor their code

PS: I hope for WP 5.0 you're planning some refactoring, e.g. media lib and code cleanup / consistency.

This ticket was mentioned in Slack in #themereview by nikolam. View the logs.


5 weeks ago

#4 @joyously
5 weeks ago

  • Keywords has-patch removed

This patch does not match the ticket description. The patch adds parameters to the the_content filter, which would break all kinds of themes, plugins, and core.

Why do you think get_the_content() needs a filter? I thought the whole point of it was that it was returning the actual content, unfiltered. It is a reliable source of actual content.

#5 @Ninos Ego
5 weeks ago

Why it would break all kinds of themes, plugins or core? It does not replace params. Also atm plugins, themes and core just uses add_filter( 'the_content', 'yourfunction', PRIORITY ) , no admin is using here the param $accepted_args, because not needed. If used, they have to use 1. So it's not breaking anything. The other params are optional.

get_the_content()-filter is needed for plugins to change content in themes. The params $more_link_text & $strip_teaser can then be used by plugins e.g. to readd the $more_link_text after changing content.

#6 @joyously
5 weeks ago

Ooops, my mistake of thinking the parameters backwardly. Sorry.

I still think get_the_content() is better left unfiltered.

#7 @Ninos Ego
5 weeks ago

Why get_the_content() is better unfiltered but the_content() already has an filter? If someone wants to have raw content, he can use $post->post_content.

Note: See TracTickets for help on using tickets.