@templatelab

Как корректно удалить хук из плагина Wordpress?

Из приведенной ниже функции нужно удалить следующий хук:
add_action( 'comment_form_before', [ $this, 'comments_link' ] );

Как сделать это корректно именно в данном случае?
Данный фрагмент из плагина WooCommerce Multilingual.

public function __construct( woocommerce_wpml $woocommerce_wpml, SitePress $sitepress, WPML_Post_Translation $post_translations, wpdb $wpdb ) {
		$this->woocommerce_wpml  = $woocommerce_wpml;
		$this->sitepress         = $sitepress;
		$this->post_translations = $post_translations;
		$this->wpdb              = $wpdb;
	}

	public function add_hooks() {

		add_action( 'comment_post', [ $this, 'add_comment_rating' ] );
		add_action( 'woocommerce_review_before_comment_meta', [ $this, 'add_comment_flag' ], 9 );

		add_filter( 'get_post_metadata', [ $this, 'filter_average_rating' ], 10, 4 );
		add_filter( 'comments_clauses', [ $this, 'comments_clauses' ], 10, 2 );
		add_action( 'comment_form_before', [ $this, 'comments_link' ] );

		add_filter( 'wpml_is_comment_query_filtered', [ $this, 'is_comment_query_filtered' ], 10, 2 );
		add_action( 'trashed_comment', [ $this, 'recalculate_average_rating_on_comment_hook' ], 10, 2 );
		add_action( 'deleted_comment', [ $this, 'recalculate_average_rating_on_comment_hook' ], 10, 2 );
		add_action( 'untrashed_comment', [ $this, 'recalculate_average_rating_on_comment_hook' ], 10, 2 );
		//before WCML_Synchronize_Product_Data::sync_product_translations_visibility hook
		add_action( 'woocommerce_product_set_visibility', [ $this, 'recalculate_comment_rating' ], 9 );

		add_filter( 'woocommerce_top_rated_products_widget_args', [ $this, 'top_rated_products_widget_args' ] );
		add_filter( 'woocommerce_rating_filter_count', [ $this, 'woocommerce_rating_filter_count' ], 10, 3 );
	}
  • Вопрос задан
  • 242 просмотра
Пригласить эксперта
Ответы на вопрос 3
qant
@qant
programer
add_action( 'wp_loaded', function(){
	remove_action( 'comment_form_before', 'comments_link');
} );


https://wp-kama.ru/function/remove_action
Ответ написан
init0
@init0
Старый моряк
function remove_wpml_hook() {
  global $woocommerce_wpml;
  remove_action('comment_form_before', array($woocommerce_wpml, 'comments_link'));
}
add_action('wpml_loaded', 'remove_wpml_hook');
Ответ написан
@templatelab Автор вопроса
Пробовал еще такими способами, но сайт ложится при этом:
remove_filters_with_method_name( 'comment_form_before', 'comments_link' );
remove_filters_for_anonymous_class( 'comment_form_before', 'WCML_Comments', 'comments_link' );
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы