WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] manage_users_custom_column Strange Behavior (6 posts)

  1. Driftless
    Member
    Posted 3 years ago #

    I am trying to add custom column(s) to the users admin page using the manage_users_custom_column() hook.

    Consider this:

    add_filter('manage_users_columns', 'add_status_column');
    add_action('manage_users_custom_column', 'manage_status_column', 10, 3);
    
    function add_status_column($columns) {
           	$columns['live_status'] = 'Status';
     	return $columns;
    
    }
    
    function manage_status_column($empty='', $column_name, $id) {
    	if( $column_name == 'live_status' ) {
    		echo $column_name;
    		echo $id;
    
        	}
    }

    Several strange things here:
    1) Had to add the $empty='' to get any results at all
    2) The output is dumped outside the row - after the closing </tr> in each user row... even though the function is clearly called in /wp-admin/includes/template.php file in the right place -- meaning that the echos get dumped at the top of the table...

    Any thoughts? I've been banging my head against this for hours.

  2. Driftless
    Member
    Posted 3 years ago #

    Note: Same behavior in both a plugin as well as the template functions.php file...

    This is weird.

  3. Driftless
    Member
    Posted 3 years ago #

    I see I'm on my own with this one...

  4. erez213
    Member
    Posted 3 years ago #

    add_filter('manage_users_columns', 'add_status_column');
    add_filter('manage_users_custom_column', 'manage_status_column', 10, 3);
    
    function add_status_column($columns) {
           	$columns['live_status'] = 'Status';
     	return $columns;
    
    }
    
    function manage_status_column($empty='', $column_name, $id) {
    	if( $column_name == 'live_status' ) {
    		return $column_name.$id;
    
        	}
    }

    Enjoy :)

  5. Driftless
    Member
    Posted 3 years ago #

    Really? Are you serious? Well, I'll be...

    BRILLIANT!

    Thanks erez213 -- you don't know how happy that makes me.

  6. tomasdev
    Member
    Posted 3 years ago #

    Thanks you so much! I hadn't realized it should be returned instead of printed!

Topic Closed

This topic has been closed to new replies.

About this Topic