Hide user fields based off capability

This filter needs to return something. Try this function modify_contact_methods($profile_fields) { if(current_user_can(‘edit_users’)) { // Field addition and removal will be done here // Add new fields $profile_fields[‘company_name’] = ‘Company Name’; $profile_fields[‘company_id’] = ‘Company ID’; } return $profile_fields; } add_filter(‘user_contactmethods’, ‘modify_contact_methods’);

Plugin capabilities

public function myplugin_role_has_cap($capabilities, $cap, $args) { if(!isset($capabilities[‘myplugin_access’])) { unset($capabilities[‘myplugin_delete_item’]); } return $capabilities; }add_filter(‘user_has_cap’, array($this, ‘myplugin_role_has_cap’), 0 , 3); Here is a better answer, that corresponds to my example. Let’s say the plugin, on activation, adds the 2 caps to a role, and that after that for some reasons, the access cap is revoked. Then, even … Read more

Add role and edit page capabilities

The edit_pages capability only allows a user to edit his own unpublished pages. It does neither allow to edit others pages (this would require the edit_others_pages capability) nor does it allow to publish or edit published pages (capabilities: publish_pages and edit_published_pages). I’d strongly recommend having a look on this wonderful table: https://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table listing up all … Read more

add_role menu pages are not visible

The problem was, that I changed the capabilities AFTER I already created the role. I noticed, that if I change the roles slug, the role became duplicated. So I searched, and found remove_role( ‘tabellenadmin’ ); Add that line somewhere before add_role(). You first have to remove the role, before you can change it.

creating different edit screens for different roles

Solved it for different edit pages for different roles. In my method resposible for rendering the field I have: if ( count( array_intersect( $allowed_editors, $user->roles ) ) < 1 ) $readonly = ‘readonly’; Which I later use to either set the input field as readonly or add/remove classes before rendering it. Still working for the … Read more

Hide menu theme location for certain capabilities?

Check user capabilities or roles when registering the navigation menu. The data will remain accessible via wp_nav_menu, but users without the capabilities won’t see the location in Appearance -> Menu -> Manage locations. Note this will only prevent assigning menus to these locations. Any menu assigned to the location already will be manageable (if the … Read more

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