I haven’t ever seen a tag such as do_action('something_10')
. Is it invalid if I use numbers?
If the method is valid, how can I write different numbers in the tag string conditionally? For example, is the following code correct($grade is the number)?
do_action("new_grade_$grade")
add_action/*_filter('whatever');
a callback function todo_action('whatever');
, then you basically add the function (or object-method) name to theglobal $wp_filters
-array.Doing so, you add the function/method name to an array that is built like the following
$idx
is built using the_wp_filter_build_unique_id()
function, that takes the first args fromadd_action/*_filter()
.So yes, numbers are completely valid when naming action hooks. Summed up, it’s save to use
a-zA-Z0-9_
as function/method/variable names.-
is not supported. And while some characters might work well on your system, it mostly depends on the encoding if your chosen function name (example:_wUT?a_nice_DÃY!()
) works or not. WordPress itself does not check if a function/var/hook/filter/whatever name is valid or not.Addition to @BrianFegter answer about “contextual hooks”.
You can see some “contextual hooks”, when you take a look at the »help«-panel in (any) screen in your (MU or single) installation, using this plugin1).
1) Plugin inspired by @StephenHarris article.
Yes, you can dynamically create your own action hooks. WordPress has several dynamic hooks like
admin_head-hookname
andadmin_footer-hookname
.new_grade_$n
is a valid hook name.