Hide menu items for visitors and filter based on role

You need to define something like this in your header.php file.

<?php
if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
} else {
    echo 'Welcome, visitor!';
}
?>

Create a new role with the following code and put it in your functions.php

add_role('partners', 'Partners', array(
    'read' => true, // True allows that capability, False specifically removes it.
    'edit_posts' => true,
    'delete_posts' => true,
    'edit_published_posts' => true,
    'publish_posts' => true,
    'edit_files' => true,
    'import' => true,
    'upload_files' => true //last in array needs no comma!
));

Now lets say your partners has the capability “edit_published_posts”.
You can define the menu like this.

<?php
    if ( is_user_logged_in() ) {
            if(current_user_can('edit_published_posts')) {
            echo 'Welcome, Partner!';
            }
            else {
            echo 'Welcome, registered user!';
            }
    } 
    else {
        echo 'Welcome, visitor!';
    }
    ?>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)