Icons instead of values to indicate a confirmed account as a user admin column

Support MB Admin Columns Icons instead of values to indicate a confirmed account as a user admin columnResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36958
    Stephen C.Stephen C.
    Participant

    I need to add a column on the user admin table that shows an icon indicating whether or not the user has confirmed their email address. The user meta field "confirm_code" only exists if they have not confirmed their email address yet. I don't want to display the actual confirmation code on the users table. I just want to display one icon if "confirm_code" exists or a different icon if "confirm_code" does not exist.

    Any ideas on how to accomplish this? Thanks

    #36979
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The admin column uses the helper function rwmb_the_value to show the field value. You can use this filter hook to change the field value when showing on the backend. For example:

    add_filter( 'rwmb_the_value', function( $output, $field, $args, $object_id ) {
        $value = rwmb_meta( 'confirm_code', $args, $object_id );
        if( is_admin() && $field['id'] == 'confirm_code') {
            if( $value ) {
                $output = '<img src="https://picsum.photos/200/300?random=1" alt="Image" width="32" height="32">';
            } else {
                $output = 'icon here';    
            }
        }
    
        return $output;
    }, 11, 4 );

    Read more on the documentation https://docs.metabox.io/filters/#rwmb_the_value

    #36990
    Stephen C.Stephen C.
    Participant

    Fantastic! Works great. Thanks, you really helped me out a lot!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.