[SOLVED] Check User role
Posted: Thu Jul 01, 2021 10:45 am
Hello,
Missing a good search/filter-function in the dashboard -> manage content (i know there is a search function in de dashboard, but it's limited to the page-titles), so i used the front-end search plugin that also search in pages-content.
So for 'fast' find and editing the content from the frontend, adding an 'Edit'-link in my template after the page-title:
This works great, but the link still showing also when a user not logged in.
Now trying show the 'Edit'-link ONLY when admin or author is logged in:
But this doesn't work
My PHP-knowledge is not so good, so it's hard to find the right objects, keys,...
I'm using this print_r($users) for help myself, but can't figured out how check the user-role. See screenshot below, what i try to do...
Someone can give me a tip how check if user admin or author is logged in?
PS: I hope there would be more documentation, in the near future, about developing themes, plugins,.. about functions and so on, similar like the WP-docs.
Missing a good search/filter-function in the dashboard -> manage content (i know there is a search function in de dashboard, but it's limited to the page-titles), so i used the front-end search plugin that also search in pages-content.
So for 'fast' find and editing the content from the frontend, adding an 'Edit'-link in my template after the page-title:
Code: Select all
<a href="<?php echo '/admin/edit-content/' . $page->key(); ?>">Edit</a>
Now trying show the 'Edit'-link ONLY when admin or author is logged in:
Code: Select all
<?php
if ($user->role()=='admin'):
?>
<a href="<?php echo '/admin/edit-content/' . $page->key(); ?>">Edit</a>
<?php endif ?>
My PHP-knowledge is not so good, so it's hard to find the right objects, keys,...
I'm using this print_r($users) for help myself, but can't figured out how check the user-role. See screenshot below, what i try to do...
Someone can give me a tip how check if user admin or author is logged in?
PS: I hope there would be more documentation, in the near future, about developing themes, plugins,.. about functions and so on, similar like the WP-docs.