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

How to set individual capabilities on a taxonomy? Or how to re-register an existing taxonomy?

This should works add_action( ‘init’, ‘register_category_again’, 1 ); function register_category_again() { $user = wp_get_current_user(); if ( $user->roles[0] != ‘your_custom_role’ ) return; global $wp_taxonomies; unset( $wp_taxonomies[‘category’] ); global $wp_rewrite; $rewrite = array( ‘hierarchical’ => true, ‘slug’ => get_option(‘category_base’) ? get_option(‘category_base’) : ‘category’, ‘with_front’ => ! get_option(‘category_base’) || $wp_rewrite->using_index_permalinks(), ‘ep_mask’ => EP_CATEGORIES, ); register_taxonomy( ‘category’, ‘post’, array( … Read more

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