如何在Wordpress中更改操作优先级?

eld*_*dov 15 php wordpress

我正在使用Thematic框架作为儿童主题.它有许多钩子,但我特别关注thematic_header().thematic_header()钩子添加了以下操作(通过add_action):

<?php
  add_action('thematic_header', 'thematic_brandingopen', 1);
  add_action('thematic_header', 'thematic_blogtitle', 3);
  add_action('thematic_header', 'thematic_blogdescription', 5);
  add_action('thematic_header', 'thematic_brandingclose', 7);
  add_action('thematic_header', 'thematic_access', 9);
?>
Run Code Online (Sandbox Code Playgroud)

行动的内容无关紧要.

我的问题是:如何改变有关五项行动的优先顺序.例如,我想在thematic_brandingopen()之前加载thematic_access().我能够弄清楚的唯一方法就是删除并重新添加动作,ala:

<?php
  function remove_thematic_actions() {
    remove_action('thematic_header', 'thematic_access');
    add_action('thematic_header', 'thematic_access', 0); //puts it above thematic_brandingopen
  } 
  add_action ('init', 'remove_thematic_actions');
Run Code Online (Sandbox Code Playgroud)

这似乎是一种完成非常简单的事情的愚蠢方式.有没有办法访问和排序/重新排序任何存储WP中的操作的数据结构?

The*_*pha 10

来自WordPress

如果使用默认值10以外的优先级注册了挂钩,则还必须在remove_action()调用中指定优先级.

所以我认为你可以先删除使用以下内容

remove_action('thematic_header', 'thematic_brandingopen', 1);
remove_action('thematic_header', 'thematic_access', 9);
Run Code Online (Sandbox Code Playgroud)

然后再使用不同的添加 priority

add_action('thematic_header', 'thematic_access', 1);
add_action('thematic_header', 'thematic_brandingopen', 2);
Run Code Online (Sandbox Code Playgroud)


Jon*_*ead 5

不要自我推销,但我已经做了一些工作,通过名为Prioritize Hooks的WordPress插件提供非编码解决方案.我的插件允许您通过UI设置各种已注册挂钩的优先级,并在运行时覆盖,以便不修改代码.