get_users() ORDER BY Not Working
Try putting the args into an array. $args = array( ‘role’ => ‘subscriber’, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ‘fields’ => ‘all_with_meta’, ‘meta_query’ => $meta_query ); $my_users = get_users( $args );
Try putting the args into an array. $args = array( ‘role’ => ‘subscriber’, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ‘fields’ => ‘all_with_meta’, ‘meta_query’ => $meta_query ); $my_users = get_users( $args );
Just use is_admin_bar_showing() to check if the currently logged in user is logged in has activated the admin bar in his user settings/preferences
This would be best as a comment, but no reputation 🙂 In the codex they say “If you are defining a custom role, and adding capabilities to the role using add_role(), be aware that modifying the capabilities array and re-executing add_role() will not necessarily update the role with the new capabilities list. The add_role() function … Read more
first_name and last_name are not the part of _users table it is user metadata. Therefore, user object does not have it. So when you access the property first_name user object has a PHP magic method __get() /** * Magic method for accessing custom fields * * @since 3.3.0 * @param string $key * @return mixed … Read more
If you use the filter wp_authenticate_user you get the user object you need to use the user ID to get the user meta function isUserActivated($user){ $userStatus = get_user_meta($user->ID, ‘account_activated’, true); // for testing $userStatus = 1; $login_page = home_url(‘/login/’); if($userStatus == 0){ wp_redirect($login_page . “?login=failed”); exit; } return $user; } add_filter(‘wp_authenticate_user’, ‘isUserActivated’); But I think … Read more
Migrate DB Pro can help with this, make sure to migrate any plugin tables and the WP_Users and WP_Usermeta tables if your users make posts and you want that content to remain assigned an available make sure to keep WP_Posts and WP_Postmeta table as well. https://deliciousbrains.com/wp-migrate-db-pro/ Also keep in mind that WP uses an EAV … Read more
thanks for that. Just one minor tweak, as the first bit of code threw up an error. Below is the working code for the first block of code. //hooks add_action( ‘show_user_profile’, ‘Add_user_fields’ ); add_action( ‘edit_user_profile’, ‘Add_user_fields’ ); function Add_user_fields( $user ) { ?> <h3>Extra fields</h3> <table class=”form-table”> <tr> <th><label for=”text”>text</label></th> <td> <?php // get test … Read more
You can use wp_update_user to update the role for your newly created user. if ( !username_exists( ‘mytestuser’ ) ) { $user_id = wp_create_user(‘mytestuser’, ‘testpass345′,’[email protected]’); $user_id = wp_update_user( array( ‘ID’ => $user_id, ‘role’ => ‘author’ ) ); } Further reading at WordPress Codex. Or, you can remove the current role and assign a new one: if … Read more
Try this. It works for me. add_filter( ‘login_redirect’, ‘redirect_non_admin_to_dashboard’), 10, 3 ); function redirect_non_admin_to_dashboard($redirect_to, $requested_redirect_to, $user ) { global $user; if( ! isset( $user->ID ) ) { return $redirect_to; } if ( ! in_array( ‘author’, (array) $user->roles ) ) { $redirect_to = site_url().’/dashboard-teacher’; }elseif( in_array( ‘subscriber’,(array) $user->roles ) ){ $redirect_to = site_url().’/dashboardwwp-student’; }else{ $redirect_to = … Read more
First: The $wpdb object has the names of tables, with prefixes, pre-defined for you. $wpdb->users == ‘wp_users’ $wpdb->posts == ‘wp_posts’ etc. Second: $wpdb-prepare() is essentially a WordPress aware printf, if you pass it more than one argument, you need to have some string/digit replacements %s %d $sql = “UPDATE {$wpdb->users} SET user_login = %s WHERE … Read more