{% import "macros.twig" as macros %} {% set hook = hook ?? 'action' %} {% set functions = functions ?? [] %} {% set is_self = is_self or is_self is null ? true : false %} {% set was_found = false %} {% for function in functions %} {# iterate thru function tags, if function has wp_action/wp_filter tag reference save it #} {% for tag_name,tags in function.tags %} {% if tag_name in [ 'wp_' ~ hook ] %} {% set h = tags.0.description %} {# get all hooks in wp_action/wp_filter #} {% set hooks = '{' == h|first ? h|slice(1, h|length - 2 )|trim|split('\n') : h|split('\n') %} {% for entry in hooks %} {% if 'add_' ~ hook == entry|slice(0,10) %} {% if false == was_found %} {% set was_found = true %}

{{ hook|title }}s

{% endif %} {# get action_hook from entry #} {% set definition = entry|slice(11) %} {% set wp_action = definition|split(',')[0] %} {% set definition = definition|replace({ (wp_action ~ ',') : ""}) %} {% set wp_action = wp_action|replace({"'" : ""})|trim %} {% set wp_action_link = macros.wp_hook_corrections( wp_action )|trim %} {# get action callback function from definition #} {% set callback = "'" == definition|trim|first ? definition|trim|slice(1)|split("'")[0] : definition|split(')')[0] ~ ')' %} {% set definition = "'" == definition|trim|first ? definition|replace({ ("'" ~ callback ~ "'") : ""}) : definition|replace({ (callback) : ""}) %} {# get action priority and argument count from entry #} {% set priority = definition|split(',')[1] is not empty ? definition|split(',')[1] : '10' %} {% set arg_count = definition|split(',')[2] is not empty ? definition|split(',')[2]|replace({')' : '', ';' : ''}) : '' %}

WordPress Hook: {{ wp_action }}

{# macros.wp_hook_link(wp_action_link, wp_action) #} {% if function.description is not empty %}

Description: {{ function.description }}

{% endif %} {% if is_self %}

Callback Function: {{ callback }}

{% else %} {% set file_function_url = path('/files/') ~ function.path|replace({'/' : '-', '.php' : '.html'}) %}

Callback Function: {{ callback }}

{% endif %}

Priority: {{ priority|replace({')' : '', ';' : ''}) }}

{% if arg_count is not empty %}

Arguments: {{ arg_count }}

{% endif %}

Source: {{ function.path }} : {{ function.line }}

{% endif %} {% endfor %} {% endif %} {% endfor %} {% endfor %}