6

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 ). :-)

2
  • Helped, but close voted as typos won't help.
    – kaiser
    Apr 17 '12 at 1:36
  • 1
    Actually - this isn't as localized an issue as some of us would like to admit. After wasting 20 minutes on this I found Niels question and edit VERY helpful as I had made the same mistake.
    – jdm2112
    Jul 21 '16 at 21:19
9

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

1
  • 1
    Great catch Kaiser.
    – jdm2112
    Jul 21 '16 at 21:20

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