• Is it possible to add a filter with a method of a class not a function?

    E.g:

    <?php
    class MyClass{
      public function __construct(){
        add_filter('the_content', '$this->myFilter');
      }
    
      private function myFilter($content){
        return $content;
      }
    }
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter levi.putna

    (@leviputna-1)

    Fount then solution for anyone interested.

    <?php
    class MyClass{
      public function __construct(){
        add_filter('the_content', array($this, 'myFilter'));
      }
    
      public function myFilter($content){
        return $content;
      }
    }
    ?>

    Does that method work in all versions of WP?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filter in a class’ is closed to new replies.