Restrict specific private page to a specific user

I assume you’re using wp_insert_post() to create the private page for the user. The function returns the ID of the created page. You can use this ID as part of a custom capability you grant to the user. // create the new $user // create private page $private_page_id = wp_insert_post( $postarr, $wp_error = false ); … Read more

How to restrict subscriber editing other posts but read specific posts in backend

To query posts with more than one author ID, you can use author__in parameter. This makes posts from chosen authors visible (read only) for the current user. add_filter(‘pre_get_posts’, ‘posts_for_current_author’); function posts_for_current_author($query) { if ( $query->is_admin && ‘edit.php’ === $GLOBALS[‘pagenow’] && ! current_user_can( ‘edit_others_posts’ ) ) { $query->set(‘author__in’, array(get_current_user_id(), 1, 2, 3) ); // add 1 … Read more

How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?

In addition to the code piece in the question, 1. To display only the author roles in the user list page of editor: add_action(‘pre_user_query’,’editors_edit_author_list’); function editors_edit_author_list($user_search) { $user = wp_get_current_user(); if($user->ID != 1) { $user_meta=get_userdata($user->ID); //$user_roles= $user_meta->roles; global $wpdb; if(in_array(‘editor’, $user_meta->roles)) { $user_search->query_where = str_replace( ‘WHERE 1=1’, “WHERE 1=1 AND {$wpdb->users}.ID IN ( SELECT {$wpdb->usermeta}.user_id … Read more

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