如何在Wordpress中更改操作优先级? [英] How can I change action priority in Wordpress?

查看:68
本文介绍了如何在Wordpress中更改操作优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the Thematic framework for a child theme. It has a number of hooks, but I'm looking at thematic_header() in particular. The thematic_header() hook adds the following actions (through 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);
?>

动作的内容无关紧要.

The content of the actions is irrelevant.

我的问题是:如何更改所涉及的五个动作的优先级.例如,我希望thematic_access()在thematic_brandingopen()之前加载.我能够弄清楚的唯一方法是删除并重新添加动作ala:

My question is this: How can I change the priorities of the five actions in question. For instance, I want thematic_access() to load before thematic_brandingopen(). Only way to do this that I've been able to figure out is by removing and re-adding the actions, 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');

这似乎是完成一些非常简单的事情的愚蠢方法.有什么方法可以访问和排序/重新排序WP中存储数据的任何数据结构?

That seems like a stupid way of accomplishing something very simple. Is there a way to access and sort/reorder whatever data structure stores actions in WP?

推荐答案

来自 WordPress

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

if a hook was registered using a priority other than the default of 10, then you must also specify the priority in the call to remove_action().

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

So I think you can first remove using following

remove_action('thematic_header', 'thematic_brandingopen', 1);
remove_action('thematic_header', 'thematic_access', 9);

,然后使用不同的priority

add_action('thematic_header', 'thematic_access', 1);
add_action('thematic_header', 'thematic_brandingopen', 2);

这篇关于如何在Wordpress中更改操作优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆