Strange behavior of standard theme function

1 view
Skip to first unread message

Ali B.

unread,
Jan 22, 2008, 8:48:20 PM1/22/08
to habar...@googlegroups.com
Hi all,

I have noticed something I thought rather strange when working with $theme->header() and $theme->footer(). I am not sure if this is an expected and/or accepted behavior or not, so please correct me if I am wrong. I am using the header() function as an example, but this is applicable for footer() as well, the sidebar() works fine.

for the $theme->header call not to give up on you and gives you a white page, at least one filter_theme_call_header(...) definition need to be included within the theme.php or any of the activated plugins. If only the theme_header(...) is invoked in the process, you will be presented with a nice white page for anything below the function call within your theme.

At the least, you would need to use the filter_theme_call_* in the simplest way possible (normally within theme.php of your theme:

function filter_theme_call_header( $return ) {
return $return;
}

Does this make sense?

PS: sorry if my English is bad. Obviously it's not my "mother tongue" :)
--
Ali B.

"No one can make you feel inferior without your consent."
--  Eleanor Roosevelt

Michael C. Harris

unread,
Jan 23, 2008, 10:19:51 PM1/23/08
to habar...@googlegroups.com
I don't really follow what's going on. Perhaps you could post the code
that works and the code that doesn't work.

If there is a syntax error in your php you'll get a blank page. Check
that's not the case by using the -l (that's a little ell) on the
command line.

php -l theme.php (or whatever file you're checking)

cheers, Michael

--
Michael C. Harris, School of CS&IT, RMIT University
http://twofishcreative.com/michael/blog

Ali B.

unread,
Jan 24, 2008, 7:49:35 PM1/24/08
to habar...@googlegroups.com
Thanks for the response Michael.

I think this is related to the invocation process of the theme_header(..) and the filter_theme_call_header(..) function. see "How to Reorder Theme Function Results" section in http://wiki.habariproject.org/en/Theme_Functions

I found out that you would need at least a definition for the filter_theme_call_header(..) function down in the process if any theme_header(..) definition occur _with_ or _before_ it within the process. Considering that theme methods are invoked after those in plugins, I am using the K2 system theme and a plugin (preferable that does not contain a definition to any of those 2 functions) to duplicate the issue in a couple of cases below

Case1: No calls to the filter_theme_call_header() method in the whole process.
1) Deactivate all the plugins.
2) Assume that we don't need to include the jquery in K2's theme.php so we completely delete the definition for filter_theme_call_header
3) At this point, no definition to any of those 2 function occur in the process, so the home page displays fine.
4) Activate your plugin of choice and add a definition of theme_header() and make sure that it has no filter_theme_call_header() defined, like so:
    public function theme_header($theme){
        echo "Hello from the plugin";   
    }
5) You now see a white page with only the Hello message printed at the top when accessing the home page


Case2: Calls in the "wrong" order.
1) Repeat step1 and step2 in Case1 above
2) Add a definition to theme_header() within K2's theme.php, something like so:
    public function theme_header($theme){
        echo "Hello from the K2's theme.php";   
    }
3) You would also see a white page with only the Hello message printed at the top when accessing the home page.
4) Now define filter_theme_call_header within the plugin used in testing and activate it. we can use a simple definition like so:
    public function filter_call_theme_header($return, $theme){
        echo "Hello from filter_call_theme_header in the plugin";
        return $return;
    }
5) Same issue and strangely enough, it would not display the second echo text, rather it echos the one in step 2 above.

This makes me think that first all theme_header() methods are invoked, and then it searches for the filter_theme_call_header() methods down the ladder only, and when it can't find it, it crashes.

What concerns me that if a custom theme is used, one that does not redefine filter_theme_call_header() method. And you use a plugin that uses theme_header to insert some code into your header. You would end up with a blank page. Which is one of the many scenarios that may be encountered

Cheers,
Ali


--  Eleanor Roosevelt
Reply all
Reply to author
Forward
0 new messages