如何删除通过类添加的操作 [英] How to remove an action added through a class

查看:24
本文介绍了如何删除通过类添加的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除插件在单独的functions.php 文件中注册的操作,但语法让我感到困惑.插件(我无法复制/粘贴 - 商业插件)像这样推断 add_action:

I'm trying to remove an action that a plugin registers in a separate functions.php file, but the syntax is stumping me. The plugin (I can't copy/paste - commercial plugin) infers to the add_action like so:

class Plugin_Class{

  function add_actions(){
    add_action('tag', array(&$this, 'function_to_remove'), 10); 
  }

  function_to_remove(){
    global $wp;
    // Code here
  }
}

我对 &$this 最困惑.我知道这是指类的实例,但根据我的研究,它应该像这样删除:

I'm mostly confused with &$this. I know that this refers to the instance of the class, but based off my research it should be removed like so:

需要 remove_action() 方面的帮助

我只是不知道如何为我的情况想出语法.为什么要定义全局变量?在我的情况下,我需要这样做吗?我假设小部件数组来自 WP 核心代码,但我对如何在我的情况下实现这一点感到困惑,这似乎要简单得多.对不起,如果这些东西是补救措施.

I just don't know how to come up with the syntax for my situation. Why define the global variable? Would I need to do that in my case? I'm assuming the widget array comes from WP core code, but I'm confused on how I need to implement this in my case, which seems to be much simpler. Sorry if this stuff is remedial.

提前感谢您的帮助.

推荐答案

&$this 创建一个引用而不是一个副本.这样,当您稍后访问该变量时,您真正访问的是该对象,而不是副本.

The &$this creates a reference instead of a copy. That way when you access that variable later, you really access this object and not a copy.

http://www.php.net/manual/en/language.references.whatdo.php

参见关于数组的段落不是完全通过引用赋值,而是等价的."

See the paragraph about array "not exactly assigning by reference, but equivalent."

这篇关于如何删除通过类添加的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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