0

Here is the code in short that is coming from a plugin:

class Post_Views_Counter_Columns {
     public function __construct() {
        add_action( 'wp', array( $this, 'admin_bar_maybe_add_style' ) );
    }
}

I want to remove this admin_bar_maybe_add_style function. I am trying with following code in my child theme's functions.php

remove_action( 'wp', array( 'Post_Views_Counter_Columns', 'admin_bar_maybe_add_style' ) );

It's not working. Any suggestions?

5
  • Is that class coming from a plugin, or where does it inherit from?
    – WPTricksDK
    Aug 5, 2021 at 12:04
  • @WPTricksDK it's coming from a plugin. Sorry I didn't mention that. Aug 5, 2021 at 12:10
  • Please take a look at this thread: stackoverflow.com/questions/36639146/… Don't know if you've tried this already or not - but it's worth a shot.
    – WPTricksDK
    Aug 5, 2021 at 12:25
  • Where/how is Post_Views_Counter_Columns instantiated? Aug 5, 2021 at 13:06
  • 2
    I hate this type of classes, in order to remove the action you need to create a instance of that class, when creating an instance the action is called... so anoying. See Removing action added from constructor Aug 5, 2021 at 14:03

1 Answer 1

1

I don't understand any of it but it seems to work just fine. Thank you @Buttered_Toast for mentioning the useful thread.

add_action("init", function() {
    global $wp_filter;
    foreach($wp_filter["wp"][10] as $id => $filter) {
    if(is_array($filter["function"]) && count($filter["function"]) == 2 &&
        get_class($filter["function"][0]) == "Post_Views_Counter_Columns" &&
        $filter["function"][1] == "admin_bar_maybe_add_style") {
            remove_action("wp", $id);
        }
    }
}, 99);

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.