WordPress Plugin: Log Deprecated Calls

This is the Original™ “Log Deprecated” plugin for WordPress — a straightforward plugin 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 keeps track of any deprecated functions, files, or arguments called from code within WordPress plugins and themes. You can see the results in one of two ways: it either puts an entry in your PHP log, or logs it to the database and displays it on the plugin’s Admin screen. 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.

WP Log Deprecated Calls screenshot

By default, it logs deprecated calls to the PHP error log. You can change the settings in Admin.

(Andrew Nacin later wrote his own version of this plugin; he talks about the changes on his blog. Although he has some interesting changes, I believe the display of my version is more clear. His certainly is — by his own admission — an experiment in pushing the boundaries of hacking WordPress Core!)


Current release v1.4

This plugin is available from GitHub: https://github.com/strider72/log-deprecated-calls/releases

27 Responses to WordPress Plugin: Log Deprecated Calls

  1. Frank says:

    so nice, thanks

  2. Dr J says:

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

  3. 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 says:

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

  5. Stephen says:

    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. Stephen says:

    Updated: New version 0.4. Check it out. 🙂

  7. Otto says:

    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. Rob says:

    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. Stephen says:

    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. Mix says:

    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.


  11. Hendry Lee says:

    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. gsava?lar? says:

    çok ho? saol dostum ….

  13. Pingback: Meine WordPress Entwickler Toolbox – bueltge.de [by:ltge.de]

  14. Pingback: Meine WordPress Entwickler Toolbox | Club45

  15. Denis says:

    May this plugin conflict with other plugins? I have some problems installing the plugin … Tnx

  16. Stephen R says:

    Denis: It should work with other plugins if they are programmed properly. What sort of problems are you having?

  17. Pingback: Our WordPress Developer Toolbox - WordPress, Add-on, Linux, Developer, Firefox, Windows - WP Engineer

  18. Pingback: Our WordPress Developer Toolbox : PIXEL SHOP

  19. Pingback: Meine WordPress Entwickler Toolbox | SohbeTCix.NeT | Chat Sohbet Muhabbet Odalar?

  20. bkh says:

    No problems with other plugins, great work, thanks.

Leave a Reply

Your email address will not be published.