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

Mark Jaquith mark.wordpress at txfx.net
Sat Jun 24 08:50:41 GMT 2006


On Jun 22, 2006, at 12:32 AM, Robert Deaton wrote:

> Would it not make sense for us to make these actions, and all other
> similar inconsistancies and duplications, in some way standardized so
> that we're not doing so many things and searching through so many
> pieces of code?

Most of our action hooks for deleting things or creating things  
happen AFTER the event.  e.g. delete_post

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.

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.

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.

--
Mark Jaquith
http://txfx.net/




More information about the wp-hackers mailing list