[wp-hackers] Weird 1.5 template behaviour

Stephen Cropp steve at de-generationx.net
Mon Jan 17 12:04:12 GMT 2005


Okay... This is a little bizarre and I cannot find any reason as to why 
this might happen.

In my header.php file I have a single line that require()'s what is the 
effective equiv of a my-hacks.php file. This file (dgenx.conf.php) is 
inside the template directory and its called using

require(TEMPLATEPATH.'/dgenx.conf.php');

at the top of my header.php script second only to the

require(ABSPATH . 'wp-blog-header.php');

line.

dgenx.conf.php contains things like the path to external includes and my 
XML-RPC code that I use outside of WP for certain core parts of my theme 
and other little bits and pieces of my WP site. The file is pretty 
essential for me because I use the same theme/layout outside of WP for 
other parts of my site that aren't quite so obvious to the general 
consumers visiting. So my theme is essentially putting all these pieces 
together in a way that WP can use.

The problem occurs if I use the get_header(); function. Now this 
function is just going to go and get the header.php file and require() 
it, and it works as far as the layout itself goes, however it doesn't 
seem to also include the dgenx.conf.php that is require()'d in the 
header.php file itself. I suddenly start to get path errors.

On the flip side, if I just include('header.php'); instead of 
get_header();, the problem doesn't happen. It parses dgenx.conf.php 
properly and all the external includes/libraries are loaded properly. 
XML-RPC works instead of giving me errors all over the place and all is 
fine.

In my header I have require(TEMPLATEPATH.'/dgenx.conf.php'); and then 
inside dgenx.conf.php I create a specific variable and then use that 
variable throughout the theme. In the dgenx.conf.php there is the 
following as an example.

-----8<-----
$dgenxhome = "/home/scropp/public_html/";
require_once( $dgenxhome.'/includes/lib-xmlrpc-class.inc.php' );
-----8<-----

Thing is, it appears that $dgenxhome is not being set properly. I have 
even had a look by putting "<!-- <?php echo $dgenxhome ?> -->" in the 
index.php to see if it appears there and all that appears are the html 
comment braces there. The weirdest part is that because it is a require 
for dgenx.conf.php and its not failing at that point, it must be loading 
it at least partly. Its definitely loading my pathfinder() function from 
dgenx.conf.php as that gets called above the content/sidebar.

Here are some of the errors that are appearing when you load the page...

-----8<-----
Warning:  Variable passed to each() is not an array or object in 
/home/scropp/public_html/includes/lib-xmlrpc-class.inc.php on line 70

Warning: main(): Failed opening '/includes/buttons.php' for inclusion 
(include_path='.:/usr/lib/php:/usr/local/lib/php') in 
/home/scropp/public_html/dev/wp-content/themes/dgenx/sidebar.php on line 21

Fatal error: Call to a member function on a non-object in 
/home/scropp/public_html/dev/wp-content/themes/dgenx/sidebar.php on line 22
-----8<-----

The weird part is that the first error is caused by my XML-RPC stuff and 
its being loaded from the correct path. The second error should be 
loading buttons.php from the same directory as lib-xmlrpc-class.inc.php 
but its at that point that $dgenxhome appears to be emptied. The final 
call is caused by an XML-RPC call (which fails because of the original 
XML-RPC lib error)

I had a look in template-functions-general.php at the get_*(); functions 
and also had a look at the load_template(); function to see if anything 
else is different. Aside from the extract($wp_query->query_vars); line, 
there is nothing there thats different from me just require'ing the 
header myself directly.

I'd like to avoid making $dgenxhome global if I can. But just making it 
global isn't going to resolve the problem.

So my simple question is, why is get_header(); not working while a 
simple include(); does? That is ultimately the only difference between 
the two. I've tried tracing it, but I really cannot find a reason for it 
to do so.

For now this isn't really urgent. I'm working on this on a dev blog, not 
my live blog so its not a problem. Also, just using require or 
include('header.php'); resolves the problem but its not really the best 
of hacks and could present problems down the line.

Anyone have any ideas? This one is kind of bugging me ;-)

Stephen Cropp (aka Korgan)
http://www.de-generationx.net/


More information about the hackers mailing list