Restrict Contributors to view only their own custom post types?

You need to use the action hook pre_get_posts. See the comments for details and modify the Custom Post Type(s) to your own: add_action( ‘pre_get_posts’, ‘filter_cpt_listing_by_author_wpse_89233’ ); function filter_cpt_listing_by_author_wpse_89233( $wp_query_obj ) { // Front end, do nothing if( !is_admin() ) return; global $current_user, $pagenow; wp_get_current_user(); // http://php.net/manual/en/function.is-a.php if( !is_a( $current_user, ‘WP_User’) ) return; // Not the … Read more

wp_insert_user role not working

$WP_array = array ( ‘user_login’ => $username, ‘user_email’ => $email, ‘user_pass’ => $password, ‘user_url’ => $website, ‘first_name’ => $first_name, ‘last_name’ => $last_name, ‘nickname’ => $nickname, ‘description’ => $bio, ) ; $id = wp_insert_user( $WP_array ) ; wp_update_user( array (‘ID’ => $id, ‘role’ => ‘editor’) ) ; Since you are looking for working solutions, this one … Read more

Temporary capability for current_user_can()

Yes, just filter ‘user_has_cap’. You get an array with the current capabilities that you can change without touching the database. Sample Code add_filter( ‘user_has_cap’, ‘wpse_53230_catch_cap’, 10, 3 ); /** * See WP_User::has_cap() in wp-includes/capabilities.php * * @param array $allcaps Existing capabilities for the user * @param string $caps Capabilities provided by map_meta_cap() * @param array … Read more

Check if user is admin by user ID

You worded it as you want to check if user has administrator role. It is considered more proper to check for capability, relevant to specific action. In practice this is usually expressed as current_user_can( ‘manage_options’ ) for current user. For arbitrary user it would be user_can( $user_id, ‘manage_options’ ). Of course this is capability that … Read more

What’s the difference between Role and Meta capabilities; When to use map_meta_cap() filter

difference between Role and Meta capabilities That would be better to ask the compare Role with Capabilities, not just Meta capabilities, but as a simple answer: A Role defines a set of tasks a user assigned the role is allowed to perform. Capabilities are assigned to Roles difference between Meta and Primitive capabilities? Meta capabilities … Read more

wp_update_user not updating

Im using remove_role and then add_role to upgrade a user from one role to another. Here is a function that checks all user within the user role subscriber and upgrade them to editor every hour. /** * Add a cron job that will update * Subscribers to editors. Runs hourly */ add_action(‘check_user_role’, ‘upgrade_user’); function run_check_user_role() … Read more

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