I’m developing a website in wordpress using Woocommerce and WC Vendor Marketplace plugin. I want to show content on certain page user role wise in wordpress website.
For example.
If i’m login as a vendor then it shows content “A” and if i’m login as a customer then it hides content “A”.
Here i’m customize my own code for this but not work.
<?php
$userss =get_user_meta( $vendor_id, 'wp_capabilities', true );
if ($userss='vendor') {
echo'<li id="menuuu"><a href="https://stackoverflow.com" class="button7" style="background- color:#CCCCCC; color:#000000">Back To Dashboard</a>';
echo'</li>';
}
?>
<?php endif; ?>
In above code ‘wp_capabilities’ is for user role in wordpress. In my code, user roles are ‘vendor’ and ‘customer’. I’m really weak in php. So please help me.
2
Answers
In wp_capabilities data store as serilized array of user role instead of this you can use current_user_can for more information you can refer to this.
You can change your code as below:
I know this has been marked answered, however using current_user_can() with roles is unreliable and even says as much in the codex.
It’s better to use our built in methods to determine if the current user is a vendor.