add_action ‘manage_posts_custom_column’ in a class [closed]

I think this may be more of a general php question but I am posting it here as it relates to a WP function. I am having some issues with an add_action on manage_posts_custom_column inside a class. Here is the code (stripped a little):

class The_class{

    function __construct() {
        $this->add_actions();
    }

    function add_actions() {
        add_action('admin_notices', array($this, 'admin_notices'));
        add_action('manage_posts_custom_column', array($this, 'manage_post_columns', 10, 2));
    }

    function admin_notices() {
    // Works fine
    }

    function manage_post_columns($column_name, $post_id)
        switch ($column_name) {
            case 'xxxyyzz':
                // The code                                 
            break;      
            default:
                // Error
            break;
        }   
    }
}

The error I am getting is Warning: call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two members in xxx/wp-includes/plugin.php on line 405.

Looking deeper I found that the action manage_posts_custom_column is referenced in the WP_Posts_List_Table class that extends WP_List_Table and I wonder if this is the cause of the error?

How do I get around this?

Edit:

Well for starters I could write the action properly!!!
Instead of add_action('manage_posts_custom_column', array($this, 'manage_post_columns', 10, 2)); it should be add_action('manage_posts_custom_column', array($this, 'manage_post_columns'), 10, 2);. Note the position of the ). 🙂

1
1

Your problem is a simple typo:

array($this, 'manage_post_columns', 10, 2)

VS.

array($this, 'manage_post_columns'), 10, 2

I guess you see the difference

Leave a Comment