plugin development – Displaying an Uploaded Image as a Custom Avatar in WordPress

Question

Am creating a WordPress site whereby am enabling users to upload their own custom profile images from a custom form. Once they upload am storing the image URL in a database table and the image is then stored inside the WordPress wp-content/uploads folder. This works fine

enter image description here

When a user logs in, I want to show the uploaded image as an avatar in wordpress dashboard at the top-right corner as shown below. Ideally it should be Welcome test [avatar-image]

enter image description here

My menus are created dynamically using Wp Custom Navwalker. Henceforth all the menus are added dynamically from the Admin dashboard under Appearance -> Menus.

I have tried using a filter hook called wp_nav_menu_objects to filter the menu and append the image as an avatar but seems not to work.
Below is the filter hook am using:

//Filter inside functions.php
function my_dynamic_menu_items( $menu_items ) {

    foreach ( $menu_items as $menu_item ) {
        if ( strpos($menu_item->title, 'Welcome') !== false) {
        $menu_item->title="Welcome" . ' ' . get_avatar( get_the_author_meta( 'ID' ), 'medium' );
        }
    }
    return $menu_items;
}
add_filter( 'wp_nav_menu_objects', 'my_dynamic_menu_items', 10 );

Please assist as I have tried possible options but no success

0
Pweb 1 month 2022-12-29T10:45:46-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse