[theme-reviewers] Question about use of core WP functions in theme
Chip Bennett
chip at chipbennett.net
Thu Aug 11 15:40:31 UTC 2011
Then can you just use add_filter( 'the_content',
'mytheme_filter_the_content' ), where
function mytheme_filter_the_content( $content ) {
// Some conditional wrapper to filter only
// in the correct context. For example, you
// could query post custom meta, and determine
// if the current page is a static Page, and whether
// the current page is using your specific
// custom page template.
// Query the post metadata
$pagetemplate = get_post_meta( $post->ID, '_wp_page_template', true );
// Check to see if the current page uses the specific custom page template
if ( 'page-special-template.php' == $pagetemplate ) {
// Filter the_content here!
}
return $content;
}
On Thu, Aug 11, 2011 at 10:15 AM, Claude Needham <gxxaxx at gmail.com> wrote:
> I guess I wanted to keep the apply_filters, and the str_replace that
> is found in the_content in place.
>
> I wanted to leave everything exactly how it would be if the_content
> was called, then do a small bit of post grab pre echo processing.
>
> Was basically trying to respect the core functions since I only
> understand about 10% of what is going on in the core.
>
> Claude
>
> On Thu, Aug 11, 2011 at 8:08 AM, Chip Bennett <chip at chipbennett.net>
> wrote:
> > Skimming your question briefly: is there any particular reason you can't
> use
> > get_the_content()?
> > Chip
> >
> > On Thu, Aug 11, 2011 at 9:59 AM, Claude Needham <gxxaxx at gmail.com>
> wrote:
> >>
> >> A comment was made in a recent thread expressing the opinion that
> >> using core WP functions were *always* preferred to rolling your own.
> >> This is a slight restatement. Chip's actual statement is at the bottom
> >> of this email. Point is this reminded me that I am not comfortable
> >> with some of the design solutions I have been using recently.
> >>
> >> I'll give you an example. In a recent special page I had need for a
> >> string of the_content.
> >>
> >> Because the_content does not have an option for echo=false, I was
> >> forced to reproduce the innards of the function.
> >> $mycontent = get_the_content();
> >> $mycontent = apply_filters('the_content', $mycontent);
> >> $mycontent = str_replace(']]>', ']]>', $mycontent);
> >> .... do stuff with $mycontent
> >>
> >> This means that if a fix is applied to the_content function my theme
> >> will not automatically have the advantage of the update. There are
> >> quite a few functions with forced echo: the_content, the_excerpt,
> >> post_class, body_class, the_meta, and the_guid.
> >>
> >> I'm thinking there is a different design solution that I should be
> >> using. Or, could it be that adding echo=false is somewhere in queue
> >> for future release?
> >>
> >> Just wondering about the best practices here.
> >>
> >> Regards,
> >> Claude Needham
> >>
> >>
> >> Proper quote as promised.
> >> On Thu, Aug 11, 2011 at 5:57 AM, Chip Bennett <chip at chipbennett.net>
> >> wrote:
> >> > In general, though, IMHO, it is *always* preferable to use a core WP
> >> > function for content filtering and/or untrusted data
> >> > sanitization/validation.
> >> > Chip
> >> _______________________________________________
> >> theme-reviewers mailing list
> >> theme-reviewers at lists.wordpress.org
> >> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
> >
> >
> > _______________________________________________
> > theme-reviewers mailing list
> > theme-reviewers at lists.wordpress.org
> > http://lists.wordpress.org/mailman/listinfo/theme-reviewers
> >
> >
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110811/fff70f9b/attachment.htm>
More information about the theme-reviewers
mailing list