Extra filed under “About the user” user profile

Add following code in theme’s functions.php file. add_action( ‘show_user_profile’, ‘extra_user_profile_fields’ ); add_action( ‘edit_user_profile’, ‘extra_user_profile_fields’ ); function extra_user_profile_fields( $user ) { ?> <table class=”form-table”> <tr> <th><label for=”address”><?php _e(“Designation”); ?></label></th> <td> <input type=”text” name=”designation” id=”designation” value=”<?php echo esc_attr( get_the_author_meta( ‘designation’, $user->ID ) ); ?>” class=”regular-text” /><br /> </td> </tr> <tr> <th><label for=”city”><?php _e(“Linked In”); ?></label></th> <td> <input … Read more

Is there a simple way to manage capabilities per user?

You don’t necessarily have to assign roles to manage the user’s capabilities. First, register your custom post types with their respective capabilities. See capabilities under Function Reference/register post type – Parameters Managing User Capabilities You can use add_cap or remove_cap to add or remove user capabilities for a specific user. // Add capability to a … Read more

Displaying a random user with a shortcode

By default WordPress allow only order ASC and DESC. However, you can use WP_User_Query and the action pre_user_query to adjust the query (that is passed by reference) just like you want. This is efficient because you get only one user, not all. function my_user_by_rand( $ua ) { // remove the action to run only once … Read more

how to get and display logged in user’s recently read posts

For that you first need to SAVE when someone logged in reads a post. You can do this for instance within an action like get_header. add_action(‘get_header’,’save_single_posts_to_usermeta’); function save_single_posts_to_usermeta(){ if(is_single() && is_user_logged_in()){ $user_id = get_current_user_id(); $read_posts = get_user_meta($user_id,’_read_posts’,true); $most_recent_read_post = get_user_meta($user_id,’_most_recent_post’,true); if(!is_array($read_posts)){ $read_posts = array(); } if(!isset($read_posts[get_the_ID()]){ $read_posts[get_the_ID()] = 1; } else { $read_posts[get_the_ID()] = $read_posts[get_the_ID()]+1; … Read more

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