Change the user role after x days

Here is an idea that you can implement. I think it will work just fine. Save the expiration time in user meta. Say the meta name is change_role. What you save in the meta is unix time. If you want to change them back in 14 days. Set the meta value to time() + 60 … Read more

How to display user role

Change: $user_roles = $current_user->roles; with $user = new WP_User( $user_id ); $user_roles = $user->roles; and the $user_id should e the actual user id who’s role you are trying to get. Update, Sorry i just read the author template part so try this: //first get the current author whos page you are viewing if(isset($_GET[‘author_name’])) $curauth = … Read more

How to get all users with Author role capabilities?

Here’s a way to collect roles with the publish_posts capability: $roles__in = []; foreach( wp_roles()->roles as $role_slug => $role ) { if( ! empty( $role[‘capabilities’][‘publish_posts’] ) ) $roles__in[] = $role_slug; } and then we can query users with these roles: if( $roles__in ) $users = get_users( [ ‘roles__in’ => $roles__in, ‘fields’ => ‘ids’ ] ); … Read more

How to delete user roles?

$wp_roles = new WP_Roles(); // create new role object $wp_roles->remove_role(‘name_of_role’); If you need to check the name_of_role use $wp_roles->get_names(); you will get an array of name_of_role => Nicename of Role Alternatively, you could use the global object $wp_roles global $wp_roles;

What is the difference between “create_users” and “add_users” capabilities?

I explored WordPress to find difference between it and in schema.php file i found the following function only where in WordPress add_users capability is used. /** * Create and modify WordPress roles for WordPress 3.0. * * @since 3.0.0 */ function populate_roles_300() { $role =& get_role( ‘administrator’ ); if ( !empty( $role ) ) { … Read more

How are roles stored in the database?

The core functions: is_super_admin(), grant_super_admin(), revoke_super_admin() fetch the super admins data from the wp_sitemeta table with: $super_admins = get_site_option( ‘site_admins’, array( ‘admin’ ) ); It’s stored as a serialized array of user logins, for each site, like: a:1:{i:0;s:6:”louiev”;} It’s possible to override it with the global $site_admins array. On the other hand, the general user … Read more

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