Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've recently started revamping and re-releasing some abandoned (yet important) WordPress plugins. As I walk through the code patching other bugs, my IDE highlights deprecated function calls for me, which is fantastic!

I fix them immediately when I find them and move on.

Anything I don't catch is called out by a Log Deprecated Calls plugin or by setting WP_DEBUG to true.

But both of these approaches are highly ineffective. With one, I need to actually open the PHP file and manually scan through each line of code looking for a deprecated call. With the other, I need to wait for the deprecated call to be invoked by WP before it's flagged by the system.

Is there an easier way or some tool I can use that scans through WP plugins and themes and identifies any use of deprecated functionality?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

I was inspired by your question to create a plugin that I've been kicking the can on for several months. I'm calling it Deprecation Checker. By default, it scans the plugin and theme directories (recursively) to find deprecated functions. The functions list is sourced directly from the WP deprecated files.

It then outputs a nice list including line number, file path, old function, and recommended function to use in its place.

There are a couple of filters to add custom paths and custom deprecated functions for your own uses. You can also turn off plugin/theme directory scanning easily.

You can download it here: http://coderrr.com/deprecation-checker/ (will be on WP.org soon)

Once activated, browse to the Tools administration menu.

share|improve this answer
    
If only you'd answered before I gave the bounty away ... :-( Awesome work, though! –  EAMann Feb 29 '12 at 14:53
    
@EAMann No need for a bounty. :) I just thought this would help the community. –  Brian Fegter Feb 29 '12 at 14:58
add comment

Ehm, Theme Check plugin? :) It is set up for themes, but easy enough to make use of parts:

require WP_PLUGIN_DIR . '/theme-check/checkbase.php';
$check = new Deprecated();
$path  = 'c:\server\www\dev\wp-content\plugins\deprecated.php';
$files = array( $path => php_strip_whitespace( $path ) );
$check->check( $files, array(), array() );
var_dump( $check->getError() );

Note that it has lists of deprecated functions hardcoded, which might or might not be enough for your needs.

share|improve this answer
    
I haven't used Theme Check before, so I wasn't aware it had that functionality. I'll definitely take a look at that! –  EAMann Feb 27 '12 at 21:20
add comment

Well, the longest bit is going to be getting together a list of all the deprecated functions. Wordpress.org has a page for it here, but since that may or may not be current I would suggest going through the 5 listed files and searching for "function" to get a better list. Once you have the list together in a text file (one function name per line), put that text file into /wp-content and run this command from that directory (assuming *nix and ssh) - grep -rnf deprecatedfunctionlist.txt ./ > files.txt That will recursively search the /wp-content directly and output a text file in that directory listing the files and lines (with line numbers) those functions appear on. This way you can see exactly which functions reside in which files. I'm sure there's a more elegant solution, but this should get you started!

share|improve this answer
1  
Most versions of grep will need a -n appended as well in order to get the line numbers prepended. –  ZaMoose Feb 27 '12 at 20:51
    
Oh right - good call, I totally forgot about the line numbers, since I would just use Find for the function name in Notepad++. If there's multiple functions in a file, having the line numbers would be a must! Edited to reflect! –  SickHippie Feb 27 '12 at 21:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.