【发布时间】:2016-03-08 05:16:01
【问题描述】:
所以,我终于找到了一种方法来影响所需的功能。
我试图修改的函数包含在一个类中,所以我做了这样的事情:
class my_Check extends Appointments {
function __construct() {
$this->unregister_parent_hook();
add_action( 'wp_ajax_post_confirmation', array( $this, 'post_confirmation' ) );
add_action( 'wp_ajax_nopriv_post_confirmation', array( $this, 'post_confirmation' ) );
}
function unregister_parent_hook() {
global $appointments; //this was the object created with the parent class
remove_action( 'wp_ajax_post_confirmation', array( $appointments, 'post_confirmation' ) );
remove_action( 'wp_ajax_nopriv_post_confirmation', array( $appointments, 'post_confirmation' ) );
}
function post_confirmation() {
...do the stuff with my mods...
}
}
$new_Check = new my_Check();
只是,我现在有一个新问题。父类在__construct() 中做了很多事情(很多add_action()'s 等。而$this 填充了很多数据)。问题是,这些其他的东西和数据似乎并没有转移到子类中。我尝试在孩子的__construct() 函数中添加parent::__construct(),但这似乎不起作用。
除了需要从父类继承的 $this 中的更多数据之外,我的 mod 的代码可以正常工作。
如何将所有父类的变量、函数、钩子和过滤器等维护到子类中?
而且,我不能真正使用父类更改文件,因为它位于插件核心文件中,我不想直接修改。
【问题讨论】:
-
我们能看到 parent::__construct 方法吗?它是否需要将任何参数传递给它?事实上,你能发布整个父类吗?
-
由于整个父类有几千行,这里是父类文件的链接:mokyoworks.com/appointments.zip
标签: php wordpress class plugins extends