Support » Plugin: ACF: Better Search » Add getInstance() Function to Objects

  • Resolved Kipperlenny

    (@kipperlenny)


    I would like to remove a filter your Where Class is adding – but you call do not use the getInstance pattern (many new wordpress Plugins use this!). And you are not assigning the Object to a variable.

    Because of that, it’s not possible to remove_filter().

    Please read this comment: https://wordpress.stackexchange.com/a/36110

    And add this to your classes:

        protected static $instance = NULL;
    
        public static function getInstance() {
            NULL === self::$instance and self::$instance = new self;
            return self::$instance;
        }

    or at least assign the Objects to a variable:

    
        public function initSearch()
        {
          if (!$this->isSearchAvailable()) return;
    
          new Join();
          new Query();
          new Request();
          new Where();
        }
    

    Because otherwise, remove_filter f.e. for

    add_filter('posts_search', [$this, 'sqlWhere'], 0, 2);

    from your Search\Where class is not working in themes functions.php

    I am using https://github.com/herewithme/wp-filters-extras/ now to do this, but it should not be needed anymore today.

Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add getInstance() Function to Objects’ is closed to new replies.