WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: TPG Get Posts] Apply title/content filters

[Resolved] [Plugin: TPG Get Posts] Apply title/content filters

Viewing 8 replies - 1 through 8 (of 8 total)
  • My temporary fix is to change this (in tpg-get-posts/inc/tpg-gp-process.class.php):

    switch ($field) {
    					case "post_title":
    						$wkcontent = ($short_title)? $this->shorten_text($st_style,$st_len,$wkcontent,$this->ellip): $wkcontent;

    to this:

    switch ($field) {
    					case "post_title":
    						$wkcontent = ($short_title)? $this->shorten_text($st_style,$st_len,get_the_title(),$this->ellip): get_the_title();

    Plugin Author cswaim

    @cswaim

    Thanks for the code sample. I will look at adding this – but will need to test to see how it changes the existing output. I don’t want to roll out a change that breaks existing designs. Is there a particular reason to use this function instead of the title text?

    I can’t imagine it breaking anything, because the normal blog output would have these filters applied. But to avoid the chance of breaking anything, you could offer it as an option: apply_filters=”true” with the default as “false”.

    The only reason I can think of is the same reason title filters exist in the first place. Sometimes themes or plugins want to modify or add to the title or content before it is output. I believe there are even default WP filters (to do things like replace ™ with ™) according to the last example of the apply_filters docs.

    The code I posted might not be the best solution. It might be better to use apply_filters directly… maybe you wouldn’t have to hardcode every filter since you already have the $field variable with the name of the field. Here’s a list of filters: http://codex.wordpress.org/Plugin_API/Filter_Reference

    You could probably get pretty far by doing a str_replace(‘post’, ‘the’, $field) and passing that as the $tag for apply_filters.

    Plugin Author cswaim

    @cswaim

    Collin:

    Thanks for the response. I remember adding the filter to the content a couple of revision back and I did not think about the title. I like your solution as it uses the standard wp processes and will incorporate it the next release. Agreed, it should not alter the display.

    Are you applying any content filters and are they working? Testing is the largest portion of the applying some of these fixes. I desk checked the code for the content and it is applying the filters, but not sure I have really done any specific tests to verify it works as planned.

    If the content looks good, then I will push out the change this weekend.

    Thanks again….Criss

    That would be awesome, thank you!

    I haven’t tried it with the content filter on my site, because I only needed the title filter for now. You could try a simple filter for testing:

    add_action('wp', 'my_attach_test_filters');
    function my_attach_test_filters() {
        add_filter('the_title', 'my_test_filter');
        add_filter('the_content', 'my_test_filter');
    }
    function my_test_filter($content) {
        return "Filtered: " . $content;
    }
    Plugin Author cswaim

    @cswaim

    I did think of a reason to not use the get_the_title. The routine to shorten the title counts characters and that needs to be done before applying the filters as I did with the content. So, a bit more testing.

    I will set up a test and see how it goes — should get this out late today or tomorrow.

    Thanks again for the code & ideas.

    Looking forward to it. Thanks so much for being so responsive!

    Plugin Author cswaim

    @cswaim

    1.3.6 is available.

    You caught me between jobs, so I had the time to look at this.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] [Plugin: TPG Get Posts] Apply title/content filters’ is closed to new replies.