How can I prevent users from creating new categories?

You should to remove a capability named ‘manage_categories’ from user role or roles, for example: /** * Don’t let subscribers add/edit/remove categories. * * You should call the function once when your plugin or theme is activated. * * @uses WP_Role::remove_cap() */ function remove_subscribers_manage_categories() { // get_role returns an instance of WP_Role. $role = get_role( … Read more

Custom Post Type Capabilities — Enable Edit, Disable Create and Delete

There are a lot of capabilities, you can set for your post type. foreach ( self::$todo_roles as $role ) { $wp_roles->add_cap( $role, ‘edit_’ . self::$post_type_1 ); $wp_roles->add_cap( $role, ‘read_’ . self::$post_type_1 ); $wp_roles->add_cap( $role, ‘delete_’ . self::$post_type_1 ); $wp_roles->add_cap( $role, ‘edit_’ . self::$post_type_1 . ‘s’ ); $wp_roles->add_cap( $role, ‘edit_others_’ . self::$post_type_1 . ‘s’ ); $wp_roles->add_cap( … Read more

how to add custom user capabilities using add_user_meta or something else?

Try passing the value without serializing it manually, because WordPress will do it for you anyway: add_user_meta( $user->id, ‘orewpst_capabilities’, array( ‘author’ => 1 ), true ); or update_user_meta( $user->id, ‘orewpst_capabilities’, array( ‘author’ => 1 ) ); // it will create the meta data for you if it doesn’t exist already. The s:23 means that you … Read more

How to assign capabilities to user NOT to User Role

Finally, I’ve figured out a way to do it using WP_user Class. Snippet to add/remove capability to/from specific user – //to remove capability from user $user = new WP_User( $user_id ); $user->remove_cap( ‘can_email’); //to add capability to user $user = new WP_User( $user_id ); $user->add_cap( ‘can_email’); There is special function in capabilities.php in the wp_user … Read more