Follow oik-plugins on TwitterFollow oik-plugins on Facebook
oik-plugins
WordPress plugins and themes

oik-bwtrace – debug trace for WordPress

The oik-bwtrace plugin provides a trace mechanism for problem determination of WordPress plugins and themes and even core code.

  • The primary purpose of debug trace is to help in the development of PHP code: plugins or themes.
  • The primary purpose of action and filter trace is to help you follow the sequence of events in the server.
  • The primary purpose of Immediate action and filter trace is to show you all the actions and filters that are invoked.
  • This plugin provides the admin interface to trace functions and action and filter tracing built into plugins that use the oik / bw APIs.

When developers are debugging their code, if they are not able to use a debug program, where execution can be followed line by line, they often resort to adding lines of code to trace the values of variables. In many cases they write the output to the web page, or to a file.

The oik-bwtrace plugin provides an easy to use API that assists in the problem determination. It writes its output to a trace file, so it does not alter what you see on the web page.

It can be dynamically enabled and disabled at runtime. The APIs are implemented as lazy APIs. They are dormant until trace is activated and enabled. There is no real need to remove the trace (debug) statements when the code goes “live”.

During development of the oik plugins, Bobbing Wide have often resorted to using these trace functions in order to understand some of the stranger behaviour of WordPress, PHP and other plugins and themes.

bw_trace2() function

Introduced in oik version 1.6 the bw_trace2() is easier to use than bw_trace() as it requires less coding.

bw_trace2( $value=null, $text=null, $show_args=true );

This function uses bw_backtrace() to determine the function, line and file parameters to pass to bw_trace(). By default, bw_trace2() will print the values of the parameters to the function from which it is called to the trace log file. You can view the file using your web browser.

bw_trace() function

At the heart of the oik trace plugin is the bw_trace() function call. Whenever you need to find the value of a variable you simply code something like the following line


bw_trace( $store, __FUNCTION__, __LINE__, __FILE__, "store" );

Assuming the value of the $store variable was “2″ then
the output that you see in the trace log will be similar to this:
\wp-content\plugins\oik\oik-tides.php(140:0) 2011-09-12T17:02:42+00:00 bw_tides store 2

The variable passed to bw_trace() may also be an array or object. This enables the developer to quickly see all of the current content of a particular variable.

bw_backtrace() function

The bw_backtrace() function allows you to find out the call hierarchy for a function. You can see the context in which the function was invoked; call stack and parameters.
Use this function sparingly.

bw_gobang()

Or whatever you want it to be, so long as it doesn’t exist.
We use this mythical function to get a fatal error. It’s good when you want to demonstrate that your code IS being run. Use this function even more sparingly than bw_backtrace().

Download version 1.18.1219

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tel: +44 (0)2392 410090
Mobile: +44 (0)7876 236864
oik-plugins oik-plugins
Work
The Long Room
41 Redhill Road
Rowlands Castle
HANTS
PO9 6DE
UK