[wp-hackers] Inconsistant actions, duplicated code, complicated plugins

Robert Deaton false.hopes at gmail.com
Sat Jun 24 15:39:41 GMT 2006


On 6/24/06, Mark Jaquith <mark.wordpress at txfx.net> wrote:
> Why not just create pre_delete_post, and feed the post ID through
> that before deletion?  We could standardize that naming convention
> and create similar hooks for other events.

Agreed. On second thought, having a set of actions AND a way to cancel
the action would be great. (Owen is pretty darn good at explaining
what I wanted better than I explained it originally.

> As for Owen's concern:
>
> > One of the primary things I would like to be able to to with pre
> > hooks is to cancel the impending action without bailing completely
> > from the script (aka using die()).
>
> We have the new WP_Error class, as well as the is_wp_error()
> function.  How about this:
>
> Have apply_filters()/do_action() check the primary value being passed
> between plugins, after getting it back from each filter/action with
> the is_wp_error() function.  If it returns false, pass the value on
> to the next filter/action.  If it returns true, we echo out a nicely
> formatted list of errors.  We could also have a special wp_error
> action so that the plugin that created the error could echo out
> additional information.  The plugin would add this action to the
> wp_error hook on the fly, at the same time that it determines there
> is an error.

This sounds hackish, as my first example for this usage was a trashbin
plugin, where this is not an error, and I just want it to silently
fail and redirect back as it normally would, and return success to the
ajax scripts. This would require adding logic around every
action/filter that we wanted this behavior on, as I don't think
non-fatal or non-serious errors should just die out with a message, I
would like to be able to set an error just for myself internally as
well.

>
> e.g.
>
> > if ('some_condition' == $foo ) {
> >       // error
> >       $return = new WP_Error('foo_happened', 'Sorry, "foo" happened!');
> >       add_action('wp_error', 'thisplugin_error');
> > }
> > return $return;
>
> then, the thisplugin_error() function could echo out a link to
> documentation, or a link back to the previous page, or (and this is
> where it really gets useful) it could echo out an HTML form with
> buttons corresponding to different paths forward to resolve the error.

Sure, this is nice, but for fatal errors only, and maybe even overkill.

-- 
--Robert Deaton


More information about the wp-hackers mailing list