remove_cap nothing changes

Look at the remove_cap method from WP_User class- /** * Remove capability from user. * * @since 2.0.0 * @access public * * @param string $cap Capability name. */ public function remove_cap( $cap ) { if ( ! isset( $this->caps[ $cap ] ) ) { return; } unset( $this->caps[ $cap ] ); update_user_meta( $this->ID, $this->cap_key, … Read more

Make a single page in WordPress available only for Admin and Subscribers

please try this if ( have_posts() ) : while ( have_posts() ) : the_post(); if ( get_post_status (get_the_id()) == ‘private’ ) { if ( current_user_can( ‘administrator’ ) ) { the_title(); the_content(); } else if ( current_user_can( ‘subscriber’ ) ) { the_title(); the_content(); } else { echo ‘this post is private’; } } else { the_title(); … Read more

allowing subscriber role to delete their own posts

The capability required to delete posts is delete_posts. If you want them to be able to delete their own published posts, the capability is delete_published_posts. The capability required to view the administration panel is read. Subscribers have this capability natively, so unless you have removed it, subscribers can access the backend. I would write a … Read more

Problems using ‘add_role’

You can pass the user’s role directly to wp_insert_user(). First, you can try to add your custom role to the WP_Roles object, then pass the custom role to the user properties: // Add custom roles only once to avoid unnecessary database calls. // It is usually done during plugin activation. register_activation_hook( __FILE__, ‘cyb_add_roles’ ); function … Read more

Allow user edit widgets

The edit_theme_options capability controls access to the widgets page but also to the menus page. You can then remove the menus submenu from appearance for a specific role, and if someone tries to get there by url, redirect it : /** * Remove the “Menus” submenu from Appearance */ function remove_menus() { if (in_array(‘administrator’, wp_get_current_user()->roles)) … Read more

How to restrict an admin page, if the user is not superadmin?

To remove from the admin menu, you could use remove_menu_page(): add_action( ‘admin_menu’, function ( ) { if (is_super_admin()) return; remove_menu_page(); // or remove_submenu_page( … },99); If for some reason the page still exists, it’s just missing it’s menu link, you could check the get_current_screen() to see if the page is being viewed, and prevent access: … Read more

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