Skip to content AtlanticBT Monogram

WordPress Debugging – “Doing It Wrong” warnings

WordPress recently added some “helpful” error messages warning you when you’re not doing certain things correctly. Specifically, adding scripts and/or styles incorrectly using the wp_enqueue_* function.

However, even though it appears they tell you where things went wrong (via trigger_error), it actually just points you to the _doing_it_wrong function.

Fortunately, those hook-crazy developers threw us a bone in that function:
do_action( ‘doing_it_wrong_run’, $function, $message, $version );

Now we can figure out the offender ourselves with a hook:
[php highlight=”13″]
* Because new WP 3.3 "doing it wrong" warnings don’t really tell you where you screwed up…
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
function abt_doing_it_wrong_helper($function, $message, $version){
$before = <<<EOD
<strong>$function:</strong> v$version
debug_whereat(3, 5, $before);
add_action( ‘doing_it_wrong_run’, ‘abt_doing_it_wrong_helper’, 10, 3 );

And the helper function for printing debug_backtrace (use your own flavor):
* Pretty-print debug_backtrace()
* @param int $limit {optional} when to stop printing – how many recursions up/down
* @param int $skip {optional} when to start printing – how many calls to skip over
* @param string $before {optional} extra html to print before the table, inside debug container
* @param string $after {optional} extra html to print before the table, inside debug container
* */
function debug_whereat($limit = false, $skip = false, $before = ”, $after = ”){
static $debug_whereat_counter; if( !$debug_whereat_counter) $debug_whereat_counter = 0;
$uid = $debug_whereat_counter++;
<div class="debug trace">
<?php echo $before; ?>
<th id="th-index-<?=$uid?>"><i>nth</i></th>
<th id="th-line-<?=$uid?>">Line</th>
<th id="th-file-<?=$uid?>">File</th>
<th id="th-method-<?=$uid?>">Method</th>

$backtrace = debug_backtrace();
if( $skip ) $backtrace = array_slice($backtrace, $skip);

foreach($backtrace as $index => $trace){
//force quit
if($limit !== false && $index == $limit){
<tr><td colspan="4"><em>—– FORCE STOP RECURSION —–</em></td></tr>

<tr class="trace-item">
<th headers="th-index-<?=$uid?>"><?=$index?></th>
<td headers="th-line-<?=$uid?>" class="line"><?=$trace[‘line’]?></td>
<td headers="th-file-<?=$uid?>" class="file"><?=$trace[‘file’]?></td>
<td headers="th-method-<?=$uid?>" class="method">
echo ‘<br />’;
?> {<i><?php print_r(array_shift($trace[‘args’]) ); ?></i>} <?php
}// while !empty $trace[‘args’]
</tbody></table><?php echo $after; ?></div>

}// function debug_whereat

capabilities covered
Amazon Web Services

The Atlantic BT Manifesto

The Ultimate Guide To Planning A Complex Web Project


Atlantic BT's Insights

We’re sharing the latest concepts in tech, design, and software development. Learn more about our findings.

Questions & Answers

Are there differences in application architecture that are important for the cloud?
It is important to build applications and workloads specifically for the cloud. You will want to carefully consider what services the cloud provider of your choice has to offer and how your application leverages those services.
Learn More
Are there any drawbacks to cloud hosting?
Yes, there will always be some risks associated with any hosting option. You are relying on the resiliency and engineering of infrastructure that has scaled at an astounding rate.
Learn More
What’s the benefit of hosting in the cloud vs. traditional options?
Reasons not to host in the cloud are few and far between. If you don't host in the cloud, you will spend more in both CapEx and OpEx to manage your applications or websites in a traditional environment.
Learn More
How can I improve the performance of my application?
There are several primary reasons that applications perform poorly, and in some cases it’s a combination of several. 1) Data latency: If your application is making calls to a data source (whether it’s an API or a direct call) and there is latency at the data provider, your application performance will suffer.
Learn More
Should I move my application to the cloud?
The answer is ‘probably yes’. There aren’t many reasons for an application to be hosted elsewhere, aside from occasional compliance standards, or requirements to integrate with local services that would require large amounts of data to move from on-premise to cloud.
Learn More
Where should my application be hosted?
There are many different options for hosting, but most applications would do well with one of the cloud providers -- Amazon Web Services, Google Cloud Platform, Microsoft Azure.
Learn More