admin管理员组文章数量:1125931
I am building a plugin with two pages, one will be part of the admin dashboard which is simple enough and will just allow admins to edit some data. The other page should also be only accessible for admins and will allow them to view the data but as a 'normal' page, i.e. no wp sidebar menu or anything like that.
I had a look into the remove_menu_page function but even after I remove all admin pages there is still an empty menu bar at the left-hand side, it also defeats the object if it means admins can't access the page I'm building. There were some suggestions to just hide the menu with css but I'm not sure whether this would be best practice.
It's possible that I'm using the wrong paradigm to look at this and I should instead create a shortcode for users to add on a standard wordpress page that can then be locked down. That feels against the idea of it being an 'admin' page though.
I am building a plugin with two pages, one will be part of the admin dashboard which is simple enough and will just allow admins to edit some data. The other page should also be only accessible for admins and will allow them to view the data but as a 'normal' page, i.e. no wp sidebar menu or anything like that.
I had a look into the remove_menu_page function but even after I remove all admin pages there is still an empty menu bar at the left-hand side, it also defeats the object if it means admins can't access the page I'm building. There were some suggestions to just hide the menu with css but I'm not sure whether this would be best practice.
It's possible that I'm using the wrong paradigm to look at this and I should instead create a shortcode for users to add on a standard wordpress page that can then be locked down. That feels against the idea of it being an 'admin' page though.
Share Improve this question asked Feb 20, 2024 at 10:48 MichaelMichael 112 bronze badges 1- just add a "normal" page as you normally would but use the code in the answer to mark that page content so only admins can see it. Use the same function or a shortcode to call the data that you need. – rudtek Commented Feb 20, 2024 at 15:39
1 Answer
Reset to default 1You'll need something like this:
function your_callback() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// add your code here to display the menu for admins only
}
Basically you need to check what capabilities the current user has and then select one which only admins have
List of Roles & Capabilities https://wordpress.org/documentation/article/roles-and-capabilities/
本文标签: How can I have an admin only nondashboard page in my Wordpress plugin
版权声明:本文标题:How can I have an admin only non-dashboard page in my Wordpress plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736644963a1946080.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论