Allowing a CPT post to be edited by a single user role

Add code – your current active theme’s functions.php file or in a custom plugin: // Step 1: Create a New Role Based on Subscriber function create_custom_role() { // Check if the role doesn’t already exist if (!get_role(‘username-role’)) { // Get the capabilities of the Subscriber role $subscriber_role = get_role(‘subscriber’); $capabilities = $subscriber_role->capabilities; // Create a … Read more

Force logout when role is changed

The wp_login hook you are using only triggers when a user login, while we need to trigger function when user changed their role. The correct for this will be set_user_role hook. Please update your code with the given code so User will logout on changing the role. function logout_pending_users( $user_id, $new_role, $old_roles ) { // … Read more

How can I add the User Menu for Authors (role)?

How do I make this (and the pages) appear for authors, now that they actually have the relevant capabilities? They don’t have the needed capabilities, just because a role can add/edit/remove users does not mean they can list_users. Similarly there are other capabilities such as role promotion etc, here’s the code for administrators, e.g. this … Read more

Why is user_can_access_admin_page() an undefined function?

As mentioned by Jacob Peattie: functions not loaded yet. You will need to use hooks/actions (init, wp etc) https://codex.wordpress.org/Plugin_API/Action_Reference e.g. function callMyMethod(){ $userLoggedIn = is_user_logged_in(); echo ‘INIT Action: User Logged in: ‘.var_export($userLoggedIn, true); if ( is_admin() ) { $canAccess = user_can_access_admin_page(); } } add_action(‘init’,’callMyMethod’); This answer is assuming you’re creating a plugin and calling the … Read more

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