post-page

Error Management for WordPress Plugins

10
responses
by
 
on
May 4th, 2008
in
HOW-TO, WordPress, WordPress FAQs
heading
heading
heading
10
Responses

 

Comments

  1. Jacob Santos says:

    OR:

    You could just extend the WP_Error class and like, I don’t know, return a different message for get_error method. It would be half the code.


    class my_class_example_error extends WP_Error {
    function get_error($code='') {
    return __('This is an example error.');
    }
    }

  2. Jacob Santos says:

    I mean to add __('This is an example error.', MY_PLUGIN_LOCALIZATION);

  3. Jacob Santos says:

    You know Ronald, I’ll have to say that you are pretty awesome. With this information, there might be a day when working with exceptions for noobs won’t be such a huge deal.

    Except the day when the noobs create everything as an exception to pass data, then I could just die.

  4. Dhruva Sagar (15 comments.) says:

    I use a lot of plugins and I’ve even developed a few very basic plugins for myself, as a part of the learning process. I agree that error handling is very important, several times my plugins we behaving rather irratically and I had no clue as to why they were doing so.

    I had created simple widgets that would simply display a predefined html code, which I could also edit in the widget edit mode. It was probably one of the most basic and simplest of widget code that could be!

    But somehow for quite some time I struggled with the code since in the widgets.php page my widgets in particular were somehow creating problems. While the widgets.php page lists the widgets in a loop and it reaches my widget, it was getting truncated over there! The widgets.php would simply stop further loading and the page truncates early with a broken widgets page.

    It took me quite sometime and patience of trail and error methods to find out how to correct the problem, although I still do not understand really what was causing the truncation.

    This post is really helpful, I think it will help people like me who are relatively new in this area, and also it will help advanced developers to build better code! Error handling is one of the most critical parts which are often ignored by developers because they tend to feel that the errors are happening as a result of things outside of the control of their program. But it’s importance is even more in such situations. :).
    Thanks for the post.

  5. Ronald Huereca (66 comments.) says:

    @Jacob,

    Yes, extending the class would open up a nice realm of possibilities, but I wanted to keep the example simple.

    I’m glad you liked the example, and I too would like to see error handling become the norm rather than the exception (no pun intended).

    @Dhruva,

    Thanks a lot. I hope this helps you out with error handling.

  6. Alex (1 comments.) says:

    I would like to add that there is a syslogging plugin for WordPress available, which allows plugin authors to log errors and other events persistently.

  7. Jacob Santos says:

    @Alex

    I built something like that for the core, which would allow for your plugin to hook into it and extend it further by sending errors through syslog or anything else for that matter.

    However the patch is imperfect and I will have time to show it some love in a couple of weeks. It would be nice if you could find that ticket and give some input on its implementation. The more feedback, the better the next patch will be.

  8. Keith Dsouza (82 comments.) says:

    Great find Ronald, this will definitely help me handle errors better in the future. I would want a more better error handling though for storing run time errors which are incurred while a plugin runs, the possibilities are immense and can be easily extended with this find.



Trackbacks/Pingbacks

  1. […] Plugin Error Management: Weblog Tools Collection offers “Error Management for WordPress Plugins”, tips for improving how a WordPress Plugin handles and responds to errors using the […]

  2. […] wird auf weblogtoolscollection.com schön beschrieben. Dieser Beitrag beschreibt die Fehlerbehandlung mittels der WordPress-eigenen Klasse WP_Error und stellt […]

Obviously Powered by WordPress. © 2003-2013

page counter
css.php