Remove Custom Post Type menu for non-administrator users.

Codex – Register Post Type See the capability_type and capabilities arguments for register_post_type. You can pass the capabilities argument an array of capabilities to map to the necessary caps, here’s an example of the args array with custom capabilities. $args = array( ‘labels’ => $labels, ‘public’ => true, ‘publicly_queryable’ => true, ‘show_ui’ => true, ‘query_var’ … Read more

if role is logged in then do something

Something like this would be more efficient. This is basic PHP by the way, not WP specific. function add_extra_item_to_nav_menu( $items, $args ) { $roles = [ ‘administrator’ => [ //Role – slug name ‘SCHOOL_NAME-A’, //url path – appended to the end ‘ADMIN’, // can be any name – appended to SHOP NOW button ], ‘ROLEABC’ … Read more

Only show category to certain user levels without plugin

If I understand you have some categories, eg: ‘reserved’, ‘people’, ‘landscapes’, ‘personal’ and so on. Now you want that subscribers can see posts in, e.g. ‘people’, ‘landscapes’ categories but not posts in ‘reserved’ and ‘personal’ categories. This is relatively easy, just hook into pre_get_posts and if the request is for a post having that terms … Read more

Restrict access and display for categories

Yes :). The following will effect all queries for posts on the front-end including ‘secondary loops’ (e.g. post lists on the side) but it won’t effect custom post types. So this may not be exactly what you’re after, but the principle is the same: add_action(‘pre_get_posts’,’wpse72569_maybe_filter_out_category’); function wpse72569_maybe_filter_out_category( $query ){ //Don’t touch the admin if( is_admin() … Read more

How to remove “Super Admin” from All Users for those that are not a “Super Admin”?

This list of filters at the top of admin screens are called Views. You can manage views using the views_{$this->screen->id} filter. Where you’d replace {$this->screen->id} with the name of the screen you’d like to manage. In order to filter the Users screen, you can try the following: // filter the ‘users’ views add_filter( “views_users”, “wse57231_filter_user_views”); … Read more

Restrict acceess of a page in backend

This can be done in two steps. First, add a hook to the page /wp-admin/edit.php?post_type=page to remove the desired page from appearing to other users. And another hook to redirect non-authorized users from trying to access the page directly /wp-admin/post.php?post=ID&action=edit. Here, the post type is page, but it can be changed to any other. Make … 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

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