I want to add a menu page on Admin as well as User Dashboard, I have developed a plugin and it is working fine on admin dashboard but it is not showing on Client/User Dashboard. May be it is due to "role" property. But I want this on client side also. Can anyone help me please,thanks in advance!
Basic purpose is that the client have to offer some products to share or download on the website form his client/user dashboard. so I need to add this functionality using a plugin and this needs to add on client dashboard to work.
function wpdocs_register_my_custom_menu_page() {
add_menu_page(
__( 'Custom Menu Title', 'oceanwp' ), 'Offers','manage_options','ump-date-updater/ump-date-updater.php', '', 'dashicons-tickets',6);
}
add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page');
According to WP Codex the $capability parameter determines whether the menu item is shown to a user. See here for more info on roles and capabilities, and how to create custom capabilities.
// run this function on your plugin activation code
function setup_capabilities()
{
$role = get_role( 'author' ); // set this to the actual role of "User"
$role->add_cap('see_my_custom_menu_item');
}
and replace manage_options in your code with see_my_custom_menu_item
Related
I installed pop up maker and capabilities plugin in wordpress for my website. I want to create one user who is not able to see the link for pop up maker. I tried with adding user with some capability but I am not able to hide pop up maker link.
How can I achieve this? Do I need to use another capability plugin?
You can use the remove_menu_page() function called via the admin_menu action hook. If you just want to remove the link for a single user, check the current user's ID first with wp_get_current_user().
function remove_admin_menu_item_for_user() {
$user = wp_get_current_user();
// Check to see if the current user's ID is the one we want to remove the page for
if ( $user->ID == ??? ){
// Use the $menu_slug for the page you want to remove
remove_menu_page( $menu_slug );
}
}
add_action( 'admin_menu', 'remove_admin_menu_item_for_user' );
If you would prefer to use a plugin Admin Menu Editor should work as well, though you may need the Pro version.
I have created a edit link on my wordpress where subscribers can edit their posts. When they click this it takes them back to the admin portal to edit post. I want to make sure they can't see the categories widget on the right side how do I remove that from a user seeing this?
<?php edit_post_link(__("Edit Post"), ''); ?>
I ahve this un the function.php file but need to know how to make it just for subscribers.
function wpse60590_remove_metaboxes() { if() remove_meta_box( 'categorydiv' , 'post' , 'normal' ); remove_meta_box( 'tagsdiv-post_tag' , 'post' , 'normal' ); } add_action( 'admin_menu' , 'wpse60590_remove_metaboxes' );
You need to modify the capabilities of these users' role to prevent them from working with categories. The capability you need to disable for their role should be "manage_categories".
Just make sure all of the users you wish to limit are in the same role (e.g. "Contributor" or something).
In my experience the easiest way to manage capabilities for roles is the Members Plugin.
Once installed, go to Users -> Roles -> Select the role you wish to change. Find "manage_categories", uncheck it, and save.
If you are using a custom post type, we may have to add some settings where you register the taxonomy to specify the ability to assign a category to a post.
I am adding a menu to wordpress using the following:
add_action('admin_menu','menu');
function menu(){
add_menu_page('Test Admin Panel','Test Admin Panel','TestAdmin','test-plugin'.'- top-level','mnuTopLevel');
add_submenu_page( 'test-plugin'.'-top-level', 'Test Results', 'Test Results', 'TestAdmin', 'test-plugin'.'results', 'mnuResults' );
The menu is shown when logging in with the administrator role but not when logging in with a custom role (created with the User Role Editor).
Can you help me on this one please ?
Thanks a lot
The third argument of add_menu_page() should be a capability of the user.
I need help to show the left menu item on other role users dashboard. I am using the code at plugin to add the custom admin menu items .
add_action('admin_menu', 'wp_hotlel_admin_menu');
function wp_hotlel_admin_menu() {
add_menu_page('Page Title', 'Menu Title', 10,'unique-slug','ChainForm_page');
function ChainForm_page() {
echo "test";
}
The menu is being displayed and working at admin dashboard. But not being displayed at other users dashboard. I am being logged in through Wordpress basic users login section.
I have added the line below,
global $wp_roles;
$wp_roles->add_cap('Subscriber','wp-wall');
Subscriber is my user type. The menu item is not being displayed still at general users custom menu.
Please help me to fix this.
Thanks in advance.
The add_cap has been deprecated since version 2.8 I believe. You could use something like:
<?php
if( current_user_can( 'edit-posts' ) ){
//YOUR CODE HERE
}
?>
See the Codex Pages for Roles and Capabilities:
http://codex.wordpress.org/Roles_and_Capabilities
And a simplified version:
http://web-profile.com.ua/wordpress/dev/user-capabilities/
Your value 10 (the third argument) should be replaced with a capability (e.g. 'edit_pages'). User levels are deprecated. Here is a list of all available capabilities and their associated roles.
I'm building a Wordpress plugin and I added a menu page which serves for management of "Vendor" entities that are kinda similar to the existing User entities.
I have a list page similar to Users List, with Edit button for every record and when I click on the "Edit" button I should be taken to the "Edit Vendor" (which does not have its submenu item in the admin menu) page for that vendor. Everything is stored in the "plugins/wp_vendors" folder.
Question: What URL should I use for opening that Edit page? How should a slug be registered for the Edit Vendor page?
PS. Vendor List is added to the admin menu with
add_menu_page('Vendors', 'Vendors', 8, 'C:\wordpress\wp-content\plugins\wp-vendors\vendors-list.php');
And I can open the List page with
http://localhost/wp-admin/admin.php?page=wp-vendors/vendors-list.php
Can anyone help me on this?
Well, first I'd suggest modifying the initial add_menu_page call:
add_menu_page( 'Vendors', 'Vendors', 'manage_options', 'wp-vendors', 'my_admin_page_callback' );
The user level argument is deprecated, so it's better to use capabilities. Also, it's better to use a callback function for the admin page, since having plugin files output data by default can lead to unexpected errors.
Now, there are a few ways you can do what you're asking. You can either register a new submenu:
add_submenu_page( 'wp-vendors', 'Edit Vendor', 'Edit Vendor', 'manage_options', 'wp-vendors-edit', 'my_admin_edit_page_callback' );
And have that function check for a vendor id to edit. If it doesn't exist, redirect them back to the main vendors menu page.
With this method, the url would look like this:
http://localhost/wp-admin.php?page=wp-vendors-edit&vendor=<vendor ID>
The other way is just to use URL arguments and separate your admin page callback with if checks. For example:
if( ( isset($_GET['action']) && $_GET['action'] == 'edit' ) && ( isset($_GET['vendor']) && !empty($_GET['vendor']) ) ){
//You're editing a vendor.
} else {
//You're listing the vendors.
}
Then make the link for editing look like this:
http://localhost/wp-admin.php?page=wp-vendors&action=edit&vendor=<vendor ID>