wp_error is an excellent tool

Rob Miller wrote an excellent article on the use of wp_error in WordPress plugins…
http://robm.me.uk/2006/06/11/wp_error/
I’d suggest suggest that every WordPress hacker/plugin author, that is not familiar with this realtively unknown bit of wordpress lore, should go and read it!

If nowhere else, it will be indispensible when writing validation routines. You can call some VerifyPostVars routine and have it return a variable. If the variable causes Is_WP_Error() to return true, then you can display the results. The neat thing is that the WP_Error structure can contain multiple results. So, you can say
X is required, but was not supplied.
Y was not formatted correctly.
Z is not valid with the sellected options.
All at once, rather than having the user try to submit a form multiple times. Sure you can build other structures to handle that, but if everyone starts using WP_Error, plugins will all be consistent.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.