Skip to content
Article

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:
[php]
do_action( ‘doing_it_wrong_run’, $function, $message, $version );
//
[/php]

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
EOD;
debug_whereat(3, 5, $before);
}
add_action( ‘doing_it_wrong_run’, ‘abt_doing_it_wrong_helper’, 10, 3 );
//
[/php]

And the helper function for printing debug_backtrace (use your own flavor):
[php]
/**
* 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; ?>
<table>
<thead><tr>
<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>
</tr></thead>
<tbody>
<?php

$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>
<?php
break;
}

?>
<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">
<code><?=$trace[‘function’]?></code>
<?php
if(!empty($trace[‘args’])){
echo ‘<br />’;
while(!empty($trace[‘args’])){
?> {<i><?php print_r(array_shift($trace[‘args’]) ); ?></i>} <?php
}// while !empty $trace[‘args’]
}
?>
</td>
</tr>
<?php
}
?>
</tbody></table><?php echo $after; ?></div>
<?php

}// function debug_whereat
[/php]

capabilities covered
B2C Solutions B2B Solutions Government Higher Education What We Do HIPAA Compliance in the Cloud IT Consulting Getting Started With The Cloud Support

The Atlantic BT Manifesto

The Ultimate Guide To Planning A Complex Web Project

Insights

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 about Are there differences in application architecture that are important for the cloud?
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 about Are there any drawbacks to cloud hosting?
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 about What’s the benefit of hosting in the cloud vs. traditional options?
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 about How can I improve the performance of my application?
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 about Should I move my application to the cloud?
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 about Where should my application be hosted?