最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filters - Is it possible to apply_filter on a wp_ajax_ action?

programmeradmin0浏览0评论

I'm extending someone else's plugin with an AddOn and register it on their 'AddOn' page with an apply_filters .... (if possible)

Their plugin works with Ajax calls on plugin page admin, so when I click on 'AddOn' page it makes an ajax call called 'wp_ajax_checkAddons', which executes a function (that takes no arguments) and gerenates the page HTML.

The question is: Is it possible to hook with apply_filters or add_filters on their function, manipulate it adding HTML to that page?

Exmaple code:

The ajax call:

$.ajax({
    type: 'POST',
    url: 'admin-ajax.php',
    data: 'action=checkAddons',
    success: function (response) {
      $('.box').html(response);
    }
  });

The action:

add_action('wp_ajax_checkAddons', array(&$this, 'checkAddons'));

The callback:

function checkAddons() {
$result = theClass::theFunction();
die($result);

}

The function:

class theClass{
public static function theFunction(){
//code
return $code;
}
}

I'm extending someone else's plugin with an AddOn and register it on their 'AddOn' page with an apply_filters .... (if possible)

Their plugin works with Ajax calls on plugin page admin, so when I click on 'AddOn' page it makes an ajax call called 'wp_ajax_checkAddons', which executes a function (that takes no arguments) and gerenates the page HTML.

The question is: Is it possible to hook with apply_filters or add_filters on their function, manipulate it adding HTML to that page?

Exmaple code:

The ajax call:

$.ajax({
    type: 'POST',
    url: 'admin-ajax.php',
    data: 'action=checkAddons',
    success: function (response) {
      $('.box').html(response);
    }
  });

The action:

add_action('wp_ajax_checkAddons', array(&$this, 'checkAddons'));

The callback:

function checkAddons() {
$result = theClass::theFunction();
die($result);

}

The function:

class theClass{
public static function theFunction(){
//code
return $code;
}
}
Share Improve this question asked Sep 8, 2019 at 1:14 SantoroSantoro 607 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

The question is: Is it possible to hook with apply_filters or add_filters on their function, manipulate it adding HTML to that page?

apply_filters and add_filter() do two separate things. apply_filters allows a value to be filtered by add_filter(). This means that if the original code is 3rd-party, you can only use add_filter() if that code already has apply_filters() applied to it. If you're extending another plugin, you will be using add_filter(), not apply_filters().

So you need to check if the original checkAddons function includes any filters for you to use, by seeing if it uses apply_filters() anywhere. If it does, then you can filter the value passed to it with add_filter(). If the filter is properly supported, then ideally the original developer has documented it somewhere.

发布评论

评论列表(0)

  1. 暂无评论