How to add author role as a custom field to custom post type in wordpress?

You can hook into save_post_{$post->post_type} which fires after the post has been saved in database. function wpse405375_save_author_role_as_meta( $post_ID, $post, $update ) { //Get the User object from author id. $author = get_user_by( ‘ID’, $post->post_author ); //Get author roles $roles = $author->roles; //Store the role/roles in post meta /* This one will store all the roles … Read more

pre_get_posts Remove posts based on meta value with ‘post__not_in’

Try this version: // Get all posts with the access level of ‘Member’ function members_get_member_posts() { $post_ids = wp_cache_get( ‘wpse61487_members_posts’ ); if ( false === $post_ids ) { $post_ids = array(); $args=array( ‘post_type’ => ‘any’, ‘meta_key’ => ‘_members_access_role’, ‘meta_value’ => ‘member’, ‘post_status’ => array(‘publish’,’private’) ); $protected_posts = get_posts($args); if($protected_posts) { $post_ids = wp_list_pluck( $protected_posts, ‘ID’ … Read more

WordPress Super Admin

I would recommend creating a Custom User Role, using the add_role() function, such as a “Site Admin” or “Sub-Admin” (or whatever you want to call it). Then, you can assign specific user capabilities to that custom role, thereby giving users exactly the capabilities you want them to have, without giving them the capabilities you don’t … Read more

Allow contributor to view own scheduled post

You can write your query for listing scheduled posts as follow : You can see the details here $the_query = new WP_Query(array( ‘post_status’ => ‘future’, ‘posts_per_page’ => 3, ‘orderby’ => ‘date’, ‘order’ => ‘ASC’ )); To show the scheduled post on details page you should do something like this Add code to your theme’s functions.php … Read more

Is there a way to set the user Role based on email domain

With this code, you will check during the registration the users email and attach the roles you want to: <?php add_action( ‘user_register’, ‘wp234_set_role_by_email’ ); function wp234_set_role_by_email( $user_id ){ $user = get_user_by( ‘id’, $user_id ); $domain = substr( strrchr( $user->data->user_email, “@” ), 1 ); //Get Domain $contributor_domains = array( ‘gmail.com’ ); if( in_array( $domain, $contributor_domains ) … Read more

Why is wp-login redirecting to the home page when I use this function?

So, first off, if you want to block access to wp-admin, why hook into something that fires on every page load? Hook into admin_init instead. And, as @MattSmath mentioned, edit isn’t a capability. edit_posts is. Also, admin_init only fires on admin pages, so you can remove is_admin() from your check. Your revised function: <?php add_action(‘admin_init’, … Read more

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