Avoid having infinite loops

Yes it will give you infinite loop, because you’re calling the WP_User::set_role method within the set_user_role action that’s again fired within the the WP_User::set_role method. Not sure what the setup is but you can try to run it only once, with remove_action( current_action(), __FUNCTION__ ); as the first line in your callback, or use another … Read more

Creating user relationships

WordPress does provide you with the ability to save meta data for users, so you could just store the agent’s user id in a meta field of his subscribers, like update_user_meta( $user_id, “agent”, $agent_id ). You can then query those users with the WP_User_Query’s meta_query, e.g. $agents_subscribers = new WP_User_Query( array( ‘meta_key’ => ‘agent’, ‘meta_value’ … Read more

Update User Role

Off the top of my head, you should be able to do something like this: $role = get_role( ‘client’ ); if ( $role && $role->has_cap( ‘install_plugins’ ) ) { // Role not updated yet, so update it. $role->remove_cap( ‘install_plugins’ ); } get_role() returns a WP_Role object on success and WP_Role::remove_cap() calls WP_Roles::remove_cap(), which directly updates … Read more

exclude roles from overview

Yes, the get_users_of_blog() function is deprecated, and the reason your code breaks after using get_users() is the ->user_id part, you should use ->ID instead. $blogusers = get_users(); if ($blogusers) { foreach ($blogusers as $bloguser) { $args = array( ‘author’ => $bloguser->ID, ‘showposts’ => 1, ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) … Read more

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