Last set of tidbits for now...
There have been a few pieces of information that have been invaluable for me debugging some of the problems that I've been trying to address over the last few days, so I wanted to share my miscellaneous notes to myself. I realize a lot of these tips are WP specific, but since those of us that are here in the ZC support group are more than likely dug into ZC instead of WP, I figured I'd share it as a source of info all in one place!
Oh, first, one extra piece of information. I do not need Kiddo's fix because I use pretty permalinks. But that said, while I was trying to fix one particular rewrite in my .htaccess that was taking me for a ride, I had his fix code in there so that I could access the pages directly. Users of pretty permalinks (to understand what this is, you should refer to WP documentation, it is not a mod, it is a way of using the built-in permalinks feature) probably will not be affected by Kiddo's fix for the better or worse.
OK, now back to the intended post...
(1) Turn on WP debug via the wp-config.php file
Change this:
Code:
define('WP_DEBUG', false);
to this:
Code:
define('WP_DEBUG', true);
Remember to turn it back off when you are finished!! You don't want to run your published site like that
(2) Make LIBERAL use of echo statements in the area you are trying to debug. Depending on where you need to sprinkle them, they may cause subsequent 'header already sent' errors or other failures, but at least you'll get to see what the variable values are while the code is executing. I'm sure there are probably preferred debug environments, but I'm not familiar with them and the echo statements were QAD solutions for me.
Again, remember to comment them out when you are done, or you could write them to be dependent on the status of constant WP_DEBUG (set above) so that if you have debug on,, the echo's work and if WP_DEBUG is set to false, which is the default, the echo's don't execute.
(3) Know where your functions are. Of course your areas of concern may very well be in different parts of the code than mine, but there are some functions that get called over and over again that help you generically determine where you are and what is going on. It is especially helpful to have echo statements in this code!
wp-includes/query.php
Contains most/all of the is_xxx() functions defined, so if you can't figure out why something is being processed a certain way in WP, this is probably a good place to start. Also has a bunch of other useful functions that you might need to debug around such as have_posts(), have_comments(), etc.
wp-includes/plugin.php
Contains a bunch of functions that are used everywhere, but the one I found critical was the do_action() function. I found it very helpful to have echo statements in here to determine the actual arguments that were being passed, etc.
wp-includes/default_filters.php
Contains a one-stop-shop for at least the bulk of the WP filters and actions, if not all. This is important as the cross-reference between what filters and actions are being queued and which function is actually being executed by that action or filter. If you are unfamiliar with how this part of WP works, you will see lots of do_action('action_name') statements in the code. The 'action_name' argument refers to the name of an action, not an executable function. You need to find the associated add_action in order to see which executable function is going to run when this action runs. Filters are similar to actions.
wp-includes/pluggable.php
And last but not least... the infamous pluggable.php which seems to be mentioned in most of the dreaded 'headers already sent' errors. Ah yes, the reason is most likely because this is where the wp_redirect() function resides. And as this is the area of debug I have sitting in front of me as soon as I send this post, I do not yet have much useful information about the function; however, I do know that because this code re-posts the headers, it generates the dreaded error message when it gets here inappropriately. The important thing to note about this is that most likely your execution path is causing this code to be executed when it should not be which is why the headers are being resent. Use all of the tips above to sort out why it is getting here in the first place.
And off I go now to get my feet wet in the wp_redirect code for my own debug... 
HTH Karen
Bookmarks