How to redirect a specific user after log-in?

You need to use the login_redirect filter returning the redirect location: add_filter( ‘login_redirect’, ‘redirect_to_home’, 10, 3 ); function redirect_to_home( $redirect_to, $request, $user ) { if( $user->ID == 6 ) { //If user ID is 6, redirect to home return get_home_url(); } else { //If user ID is not 6, leave WordPress handle the redirection as … Read more

How can I add a user through SQL?

This will create a new admin user called username with password: password in a database called DATABASE with table prefix wp_ Change the two accordingly to your own database name and table prefix. Try this: First create a row in wp_users. Replace DATABASE with your database name, username with your choosen username, password with your … Read more

Track logged in users’ visits

As it’s a small site, you can do some “real” tracking: // Update the visit time on *every* request function wpse32258_update_usertracking(){ if ( is_user_logged_in() ) { $user_ID = get_current_user_id(); $data = get_user_meta( $user_ID, ‘user_tracking’ ); $data[] = current_time( ‘timestamp’, true ); update_user_meta( $user_ID, ‘user_tracking’, $data ); } } add_action( ‘init’, ‘wpse32258_update_usertracking’ ); // Output the … Read more

Wp_User_Query not sorting by meta key

you can try this code $args = array( ‘meta_query’ => array( array( ‘key’ => ‘score’, ‘value’ => 0, ‘compare’ => ‘>’, ‘type’ => ‘numeric’ ) ), ‘orderby’ => ‘meta_value_num’, ‘number’ => 20 ); $suggested_user_query = new WP_User_Query( $args ); $users = $suggested_user_query->get_results(); echo ‘<div id=”user_suggest”>’; echo ‘<ul>’; foreach ($users as $user) { // get all … Read more

Do not allow users to create new posts and pages

Use remove_cap for this. function remove_proofreader_create_posts(){ global $wp_roles; $wp_roles->remove_cap( ‘proof_reader’, ‘create_posts’ ); $wp_roles->remove_cap( ‘proof_reader’, ‘create_pages’ ); } NOTE: This is not a global function, but a method of the WP_Roles, WP_Role and WP_User classes. It must be called using an instance of one of these classes, as shown in the examples. ALSO: You’ll want to … Read more

Basic auth WordPress REST API dilemma

Basic auth is a very common username/password authentication method and it’s as strong as the username-password combination and the encryption of the protocol you’re using. The weakness of basic auth is that if you use it with plain http instead of https then the username and password is susceptible to a man-in-the-middle attack. You can … Read more

Allow guests to save favourite pages?

Cookies, or even HTML5 local storage, seem like a good way to implement this. Here’s some basic code that could serve as a starting point. Post IDs are stored as CSV in the cookie. // Load current favourite posts from cookie $favposts = (isset($_COOKIE[‘favposts’])) ? explode(‘,’, (string) $_COOKIE[‘favposts’]) : array(); $favposts = array_map(‘absint’, $favposts); // … Read more