Skip to content

Instantly share code, notes, and snippets.

@VR51
Last active December 9, 2025 01:29
Show Gist options
  • Select an option

  • Save VR51/7122f84e32d33dfd04081f322d256c8c to your computer and use it in GitHub Desktop.

Select an option

Save VR51/7122f84e32d33dfd04081f322d256c8c to your computer and use it in GitHub Desktop.
See all wp_usermeta registered for any user on the user's backend profile page

Handy code snippet to display all wp_usermeta associated with a user's profile.

  1. This snippet is locked to only display meta for site admins
  2. The meta is shown at the bottom of the user's profile page in the backend.
  3. The data is non editable.
  4. This is a WordPress code snippet.
<?php
/**
 * Display all user meta fields on the user profile page for admins only, showing meta for the viewed user.
 */
function display_target_user_meta_for_admins( $profile_user ) {
    // Check if the current user is an admin.
    if ( current_user_can( 'administrator' ) ) {
        // $profile_user is an object containing the user data for the profile being viewed.
        $user_id = $profile_user->ID;

        // Retrieve all user meta for the viewed user.
        $user_meta = get_user_meta( $user_id );

        // Output the meta data.
        echo '<div class="user-meta-display">';
        echo '<h3>User Meta Data for ' . esc_html( $profile_user->display_name ) . '</h3>';
        echo '<table class="wp-list-table widefat fixed striped">';
        echo '<thead>';
        echo '<tr>';
        echo '<th>Key</th>';
        echo '<th>Value</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';

        if ( ! empty( $user_meta ) ) {
            foreach ( $user_meta as $key => $values ) {
                echo '<tr>';
                echo '<td>' . esc_html( $key ) . '</td>';
                echo '<td>';
                if ( is_array( $values ) && count( $values ) > 1 ) {
                    echo '<ol>';
                    foreach ( $values as $value ) {
                        echo '<li>' . esc_html( maybe_serialize( $value ) ) . '</li>';
                    }
                    echo '</ol>';
                } elseif ( is_array( $values ) && count( $values ) == 1 ) {
                    echo esc_html( maybe_serialize( $values[0] ) );
                } else {
                    echo esc_html( maybe_serialize( $values ) );
                }
                echo '</td>';
                echo '</tr>';
            }
        } else {
            echo '<tr><td colspan="2">No user meta found for this user.</td></tr>';
        }

        echo '</tbody>';
        echo '</table>';
        echo '</div>';
    }
}

// Hook the function to the user profile page.
// The 'show_user_profile' and 'edit_user_profile' actions pass the user object to the callback function.
add_action( 'show_user_profile', 'display_target_user_meta_for_admins' );
add_action( 'edit_user_profile', 'display_target_user_meta_for_admins' );

How to Use

  1. Access your WordPress site's functions.php file (usually located in wp-content/themes/your-theme-name/).
  2. Paste the updated code snippet at the end of the file.
  3. Save the functions.php file.
  4. Navigate to the 'Users' section in your WordPress admin area, and click on 'All Users'. Then, click 'Edit' for any user. As an administrator, you will now see a table at the bottom displaying all wp_usermeta fields associated with that specific user.

Important Considerations

  1. Security: Be mindful of the data you're displaying. User meta can contain sensitive information.
  2. Performance: Displaying a large amount of user meta data can potentially impact performance. Consider optimizing the code if you have a very large number of meta fields.
  3. Customization: You can customize the output further by modifying the HTML structure or adding CSS styles to match your theme's design.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment