admin管理员组文章数量:1130349
I am trying to remove an action that is within a class, of the parent theme. I made an example of the code I have, below. I am trying to remove the action in the child theme functions.php. I've tried multiple solutions, including defining the class into a variable like: $my_class = new My_Widget(); (that needs to be done for static functions?), but I can't find a good solution. Who can help me further understand this?
parent theme file
class My_Widget extends WP_Widget {
public function __construct( $args = array() ) {
add_action( 'wp_ajax_contact_owner', array( __CLASS__, 'contact_process' ) );
add_action( 'wp_ajax_nopriv_contact_owner', array( __CLASS__, 'contact_process' ) );
}
public static function contact_process() {
global $cc_options;
echo 'test';
}
}
functions.php child theme
function cc_remove_action(){
remove_action( 'wp_ajax_contact_owner', array('My_Widget', 'contact_process' ), 11 );
remove_action( 'wp_ajax_nopriv_contact_owner', array( 'My_Widget', 'contact_process' ), 11 );
}
add_action( 'wp_head', 'cc_remove_action' );
I am trying to remove an action that is within a class, of the parent theme. I made an example of the code I have, below. I am trying to remove the action in the child theme functions.php. I've tried multiple solutions, including defining the class into a variable like: $my_class = new My_Widget(); (that needs to be done for static functions?), but I can't find a good solution. Who can help me further understand this?
parent theme file
class My_Widget extends WP_Widget {
public function __construct( $args = array() ) {
add_action( 'wp_ajax_contact_owner', array( __CLASS__, 'contact_process' ) );
add_action( 'wp_ajax_nopriv_contact_owner', array( __CLASS__, 'contact_process' ) );
}
public static function contact_process() {
global $cc_options;
echo 'test';
}
}
functions.php child theme
function cc_remove_action(){
remove_action( 'wp_ajax_contact_owner', array('My_Widget', 'contact_process' ), 11 );
remove_action( 'wp_ajax_nopriv_contact_owner', array( 'My_Widget', 'contact_process' ), 11 );
}
add_action( 'wp_head', 'cc_remove_action' );
本文标签: functionsRemove action hook from Classunderstanding OOP
版权声明:本文标题:functions - Remove action hook from Class, understanding OOP 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749142135a2322331.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论