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;
}
}
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.

  • Thank you @Jacob for the answer. I'll mark it as correct. There is no apply_filters anywhere on the code, so I can not change it. Thank you again. – Santoro Sep 10 at 0:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.