WordPress.org

Ready to get started?Download WordPress

Forums

Try/Catch around do_action and apply_filters callback execution (2 posts)

  1. Brian Zeligson
    Member
    Posted 1 year ago #

    As it stands, all it takes is one bad action or filter callback to mess up any action, many of which are very central to core functioning of WP.

    You can add an endless number of these, and every time you add a plugin or theme there's a good chance there's many contained within.

    Why not do something like this, so that an action or filter can recover from a badly written callback?

    do {
    		foreach ( (array) current($wp_filter[$tag]) as $the_ )
    			if ( !is_null($the_['function']) )
                                    try{
                                        call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
                                    } catch(Exception $e){
                                        continue;
                                    }
    	} while ( next($wp_filter[$tag]) !== false );

    plugin/theme authors still have the option to do their own error handling, but WP doesn't assume they will, and it's not as easy to break the system.

    Has this been discussed before? Couldn't find much on google, trac, or forums, but it seems like a fairly obvious topic for discussion to me.

  2. This was discussed on WP Hackers a while back, http://lists.automattic.com/pipermail/wp-hackers/2012-July/043806.html

    Nacin has a good logical response to the question.
    http://lists.automattic.com/pipermail/wp-hackers/2012-July/043816.html

Topic Closed

This topic has been closed to new replies.

About this Topic