ThemeShaper Forums » Thematic

[closed]

The parameters of a function to be filtered

(3 posts)
  • Started 2 years ago by Victorius
  • Latest reply from Victorius
  • This topic is resolved
  1. Hi!

    I am new in WordPress and I am doing my first theme with Thematic.
    I have been using filters and hooks to customize my theme without problems,
    however, there are some things I haven´t understand completely

    I have a doubt undertanding when to use $content (or another parameter) inside the parenthesis of my function:

    Untill now, I have doing like this, for example:

    my_custom_function($content) {

    // here I modify $content (sometimes I overwrite doing $content= ... )
    // (Other times I add things with $content.= ... )

    return $content;
    }

    // and later I use add_filter where corresponding.

    To sum it up, my filter function accept an argument (the initial content) and I return the modified content (the output) when it´s done.

    Not long ago, I have modified the page title following this nice example:

    http://forums.themeshaper.com/topic/tip-modify-thematic-page-title

    And I was wondering why there is no need of putting any argument inside the parenthesis of the function.

    I would apreciatte if somebody could give me an answer or a link I can read about this topic: The parameter / argument of the function to be filtered ( In the examples I´ve seen, sometimes is $content, other times is another variable, and other times there is no variable)

    Thanks in advance!
    Víctor

    Posted 2 years ago #
  2. you are new to WP and this is your first theme? your understanding of filters is a damned site better than mine was at the same time... to answer your question, you don't have to pass in an argument. you do that when you want to preserve the variable in its original state. then you can modify it in your function. if you are completely overwriting everything you don't need to keep it as the variable will be generated completely from your function.

    for example say the original apply filters looks like

    echo apply_filters('bacon_filter','i like bacon');

    so we want to filter it and pass in the argument:

    function test($bacon){
      $bacon .= ' a lot.'
      return $bacon;
    }
    add_filter('bacon_filter','test');

    the end result would be : I like bacon a lot.

    or if we didn't pass the $bacon variable in

    function test(){
      $bacon  = 'mmmm, bacon'
      return $bacon;
    }
    add_filter('bacon_filter','test');

    the result would be mmmmm, bacon and the initial "i like bacon" would be totally lost.

    this would've been important in the example you linked to if you only wanted to change the page title under 1 condition (like category archives or something), but leave it in tact in all other cases

    Posted 2 years ago #
  3. Hi Helga!

    Thank you very much for a clear and fast answer!

    After raeding these two examples I understand well the difference.

    Regards,
    Victor

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.