#8640 closed enhancement (wontfix)
2 new functions for Plugin API.
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 2.7 |
Component: | Plugins | Keywords: | has-patch tested commit |
Focuses: | Cc: |
Description
With my plugins, i use often the same action for differents Hooks.
The code is:
add_action('save_post', 'example'); add_action('publish_post', 'example'); add_action('post_syndicated_item', 'example');
Why not to create add_actions() and add_filters() ?
The result will be:
add_actions( array('save_post', 'publish_post', 'post_syndicated_item'), 'example' );
Props functions:
function add_filters($tags, $function_to_add, $priority = 10, $accepted_args = 1) { if ( is_array($tags) ) { foreach ( (array) $tags as $tag ) { add_filter($tag, $function_to_add, $priority, $accepted_args); } return true; } else { return add_filter($tags, $function_to_add, $priority, $accepted_args); } } function add_actions($tags, $function_to_add, $priority = 10, $accepted_args = 1) { return add_filters($tags, $function_to_add, $priority, $accepted_args); }
Attachments (3)
Change History (23)
#1
@
14 years ago
- Component changed from General to Plugins
- Milestone changed from 2.8 to 2.7.1
- Owner anonymous deleted
- Severity changed from normal to minor
- Version set to 2.7
#3
@
14 years ago
There's been something before about multiple actions being passed, IIRC it was thought that modifying the existing functions to accept an array would add a overhead which wasnt really needed when you could mearly have a new function for it.
#5
@
14 years ago
- Milestone changed from 2.7.1 to 2.8
Well, I suppose it really depends, if the overhead doesn't make sense to that function.
I forget what other function it was that wanted to be added to the add_filter and add_action, but it didn't make sense at the time.
Add overhead the majority of people are not going to use will lower the limit of actions and filters that can be run before the total equals more than a second in itself.
Adding an if statement might not seem like much, but the CPU still has to make an decision on whether or not it should choose the branch that goes into the if statement or the one that ignores it. If it chooses wrong, then it has to start over.
However, making multiple function calls might be more than the overhead of the single if statement.
New functions / features usually aren't added to a minor release.
#7
@
14 years ago
- Owner set to ShaneF
- Status changed from new to assigned
Testing and upgrading code to use new format.
#8
@
14 years ago
- Keywords commit added; dev-feedback removed
Updated orginal patch file to include the same thing for filters 'the_comment' to process many function call backs. Can not add the priority unless someone wants to take a stab at it.
Optimized current default-filters.php file to start this off.
#9
@
14 years ago
- Keywords needs-testing added
Just need someone to confirm that this is all good! :)
#10
@
14 years ago
If we're going to go down this road, why not allow the function parameter to be an array of function names as well?
I.E. Change
foreach ( $filters as $filter ) { add_filter($filter, 'strip_tags'); add_filter($filter, 'trim'); add_filter($filter, 'wp_filter_kses'); add_filter($filter, 'wp_specialchars', 30); }
to
add_filters($filers, array('strip_tags', 'trim', 'wp_filter_kses', 'wp_specialchars'), array(null,null,null,30));
or at least
add_filters($filters, array('strip_tags', 'trim', 'wp_filter_kses')); add_filters($filters, 'wp_specialchars', 30);
or ideally
add_filters($filters, array('strip_tags', 'trim', 'wp_filter_kses', array('wp_specialchars', 30)));
#11
@
14 years ago
- Milestone changed from 2.8 to 2.9
A little late for this. Will consider it early in 2.9 cycle. Shane, your 8650.2.diff patch won't work... you're not calling the new function properly. You're still passing $filter
when you've removed the foreach loop.
#15
@
14 years ago
- Keywords has-patch tested added; needs-patch removed
- Milestone changed from 2.9 to 2.8
I don't think it's correct to try to something like:
add_filters($filters, array('strip_tags', 'trim', 'wp_filter_kses'));
each function can have its own priority and number of arguments, and this renders the whole idea more or less pointless. and that is not to mention the clunky looking syntax with classes (especially when they're mixed up):
add_filters($filters, array(array('foo', 'bar'), array(&$bar, 'foo'), 'foobar'));
the correct approach, I think, is the first patch, 9640.diff, which is still good against 11300.
add_filters($filters_array, $single_callback, $priority, $num_args);
@
14 years ago
same as 8640.diff, except that the filters actually get used in the default-filters.php file.
#17
@
14 years ago
itching to close as wontfix myself, as I don't find this very useful.
so please patch in 2.8, or close this. this is one of those "well, why not?" tickets that can wait for years if not committed straight away.
Looks handy.
Or
add_filter()
andadd_action()
could be modified to accept an array as the first argument to achieve the same thing.