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

Extending WP_User class and using this sub-class during the whole lifecycle

If I did understand well, we need to cache a value retrieved from another REST service, from the login to logout of the user on the wordpress installation, so we will hook into this wp_login to get the value and cache it using Transient API, Options API or a persistent caching plugin. add_action(‘wp_login’, ‘my_get_and_cache_rest_value’); function … Read more

Change user’s display name programmatically

Just pasted your code into my functions.php with a different ID and checked the user’s page in /wp-admin/user-edit.php – it works, the value in Display name publicly as field is updated. Most likely something is wrong with your output on the user page. Check your template file. Or, if you can’t find the problem, edit … Read more

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