WordPress Plugin: Log Deprecated Calls

This is a pretty straightforward plugin for WordPress that is of particular interest to fellow plugin authors. (Theme authors too!)

As WordPress changes over time, old functions and files are sometimes replaced with new ones. There is generally a transitional period during which the old functions (and files) are “deprecated”, which is basically an official statement to the effect of:

This function may go away in a future version of WordPress. It works for now, but you should really switch to using such-and-such new function instead, or your plugin/theme will stop working after some future update.

There is a functionality built-in to WordPress that allows you to flag deprecated functions, but it’s not terribly informative, and thus not very useful for plugin authors.

The plugin on this page, when activated, puts an entry in your PHP log any time a deprecated function is called, or a deprecated file is included. The entry is far more useful than the default WordPress log notice — this one tells you the name of the function, the exact file that called it, the line the call was on, and what new function, if any, you should use instead. It looks something like this:

WordPress: The ***deprecated function*** "some_old_function" was called from wp-content/plugins/myplugin/myplugin.php on line 170. Use "some_new_function" instead.

By default, it logs deprecated calls to the PHP error log. There is an admin screen (under the Plugins menu) that lets you toggle logging to the database, which, if activated, allows you to see the log on that same admin screen.

For plugin authors, it also serves as an example of how to use the new uninstall functionality coming up in WordPress 2.7. Simply put: if you use the Plugin Management page to delete this plugin, it will first clean up everything it did in the system, including clearing options, deleting the log table, and so forth….

Download

Here’s the link. Have at it!

Log Deprecated Calls v0.4

Is this download worth something to you? If you have found this plugin useful, please consider making a donation. Even as little as a dollar is appreciated:

12 Comments

  1. #1 | Posted July 31, 2008 at 1:51 am

    so nice, thanks

  2. #2 | Posted July 31, 2008 at 6:13 pm

    Excellent. This will come in really useful for us plugin and theme designers

  3. #3 | Posted August 2, 2008 at 3:00 am

    Great, I’ll definitely give this a try. I recently found that I’d been using a deprecated function in my plugins, but I only found out by accident. This will help me track down what else I’m doing wrong.

  4. Trisha
    #4 | Posted August 3, 2008 at 12:32 pm

    Dumb question, but does this work for theme function calls as well as function calls from plugins?

  5. #5 | Posted August 4, 2008 at 9:36 am

    It should work for any call to a function that is marked as “deprecated” by the WordPress programmers.

    So yes, themes too.

    If you want to test it, just put a get_settings() in your theme. :)

    [Update: I edited the page to explicitly mention theme design.]

  6. #6 | Posted August 11, 2008 at 4:49 pm

    Updated: New version 0.4. Check it out. :)

  7. #7 | Posted August 12, 2008 at 9:25 am

    Awesome. The ability to log to the database and view the results in the admin section was the only thing keeping me from using this one. I very quickly found and fixed three plugins and a few bits of my theme using deprecated code. Lovely.

  8. #8 | Posted September 16, 2008 at 12:26 pm

    Stephen,
    I’ve discovered that the plugin causes my server to throw a 500 internal server error but only when posting comments to posts which already have a number of comments (say 10). The comments are actually posted but the user is faced with the server error screen.

    I spent a happy half hour reactivating all my plugins until I could confirm which one was causing the problem. I hope you have some insight into the problem because I’ve been finding it a useful tool.

  9. #9 | Posted September 16, 2008 at 4:27 pm

    Rob — 500 is a pretty generic server error — it basically just says that there was an error.

    Is it possible for you to look at your server’s PHP log and see what exactly failed? Without more info there’s not much I can do.

    If you can’t something else might help…

    It might be a conflict between my plugin and another plugin — that is, the two of them cause the error together. (Maybe another plugin causing a lot of deprecated calls or something?)

    So if you would, please try to following: Deactivate all plugins, then just activate mine, and see if the error persists. If things are working, reactivate the other plugins and we should know roughly where the conflict is.

  10. #10 | Posted September 16, 2008 at 11:23 pm

    This is a great idea! I’m using a heavily modified theme which was originally built for a previous version of Wordpress. Tooling around one day, I saw a couple of deprecated calls and wondered how many more lurked inside. This should help me get back on track.

    Thanks!

  11. #11 | Posted October 30, 2008 at 9:27 am

    Obviously this makes it easier to locate deprecated functions. Found this through wp-hackers mailing list. I’m going to test this out right now.

  12. #12 | Posted January 29, 2009 at 10:56 am

    çok ho? saol dostum ….

Post a Comment

Your email is never shared.

Subscribe without commenting