How to remove administrator role in settings -> general -> New User Default Role?

Okay, this looks tricky, but I think it’s possible. The user-new.php file calls wp_dropdown_roles() to output the list of roles. The wp_dropdown_roles() function calls get_editable_roles() to get the list of roles to output. The get_editable_roles() function has a filter, editable_roles. So, you should be able to add a filter for editable_roles, such that, if the … Read more

Restrict custom post type view by user role

Every role has capabilities. Here is a simple contributor to our endeavor: (he just writes and edits) add_role(‘contributor’, ‘Contributor’, array( ‘read’ => true, ‘edit_posts’ => true, ‘delete_posts’ => false, )); Now he has a new capability (he can edit other peoples posts) function add_capability() { $role = get_role(‘contributor’); $role->add_cap(‘edit_others_posts’); } add_action(‘admin_init’, ‘add_capability’); Now to add … Read more

Grouping users under parent user

Roles First of all you need to register the 2 roles, look at add_role. When you register the role, you are free to assign any capability you want. Only be careful to add the roles when your theme / plugin is activated and possibly remove them (see remove_role) when it is disabled. Meta Data You … Read more

Prevent author from changing their posts if admin has modified

You can try the following: /** * Post Update Locker For Authors * If an administrator has updated the post, then lock it for author updates. * @see http://wordpress.stackexchange.com/a/168578/26350 */ add_action( ‘pre_post_update’, function( $post_ID, $data ) { // Target only authors: if( ! current_user_can( ‘edit_post’ ) || current_user_can( ‘edit_others_posts’ ) ) return; // Target only … Read more

Help to condense/optimize some working code

Ok I figured it out. Here’s the optimized code: // Show only posts related to current user add_action(‘pre_get_posts’, ‘query_set_only_author’ ); function query_set_only_author( $wp_query ) { global $current_user; if( is_admin() && !current_user_can(‘edit_others_posts’) ) { $wp_query->set( ‘author’, $current_user->ID ); add_filter(‘views_edit-post’, ‘fix_post_counts’); } } // Fix post counts function fix_post_counts($views) { global $current_user, $wp_query; unset($views[‘mine’]); $types = array( … Read more

Defining capabilities for custom post type

You code seems to be correct. Try the following instead. $args = array( ‘labels’ => $labels, ‘public’ => true, ‘publicly_queryable’ => true, ‘show_ui’ => true, ‘query_var’ => true, ‘rewrite’ => true, ‘hierarchical’ => false, ‘menu_position’ => null, ‘supports’ => array(‘title’), ‘capability_type’ => ‘video’ ); Update: You have to do some extra steps before making it … Read more

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