4

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?

4 Answers 4

5

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.

2
  • If only you'd answered before I gave the bounty away ... :-( Awesome work, though!
    – EAMann
    Feb 29, 2012 at 14:53
  • @EAMann No need for a bounty. :) I just thought this would help the community. Feb 29, 2012 at 14:58
3
+50

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.

1
  • 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, 2012 at 21:20
2

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!

2
  • 1
    Most versions of grep will need a -n appended as well in order to get the line numbers prepended.
    – ZaMoose
    Feb 27, 2012 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, 2012 at 21:11
0

As Theme Checker is no longer supported, we can use new "Log Deprecated Notices" plugin.

After install, just go to "Tools -> Deprecated Calls"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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