Get user log history in wordpress

There are many types of users we need to manage in our website. Admin wants to keep log history data in site for future use purpose. Saving log history is important when you have multiple users in wordpress site. In this article I will show you how to Get user log history in wordpress. when you have multiple users in wordpress site. In this article I will show you how to keep the log history of users.

Get user log history in wordpress

Why User Login History is important

Some times there are too many users with different roles in site. It is very hard to check which user is doing what. But you as admin of website want to know about user’s activity. It is important to record all the history of user so you can check which user is performing which actions and when user’s are active in site.

Some times you create multiple moderators in website to review your site content and media. For reviewing the user content user logs are very important so you can easily know about user’s logs. I found very nice wordpress plugin which will help you to keep user log history in wp site.

Simple History (http://wordpress.org/plugins/simple-history/)

Get user log history in wordpress,Get user log history in wordpress
Get user log history in wordpress

Simple History shows recent changes made within WordPress, directly on your dashboard or on a separate page.

The plugin works as a log/history/audit log/version history of the most important events that occur in WordPress.

There are multiple features are given by above wordpress plugin. Simple history plugin has great setting options which will help admin to keep limited user logs on site. It has features to filter user logs as per role.

I personally love this plugin. It has able to record multiple actions of users in wordpress like login, logout, media, upload, wrong password, creating posts or pages in site. There options are really great features of this plugin.

 

WP Login Security and History (https://wordpress.org/plugins/wp-login-security-and-history/)

By this smart plugin you can protect your login page from Brute-force attacks also you can track login history. Features:

  • Captcha on the admin login page to protect against auto-hacking.
  • You can set the number of failed logins to show Captcha or showing it always.
  • Login Blocker option to block the login processe for a period of time after specific number of failed logins.
  • Login history to show all login processes in details.

 

 

change author url without wordpress plugin

wp user want to use other url for admin user. You can easily change using wordpress hook. you can change author url in wordpress without wordpress plugin. using code you can do this. wordpress developer can use this code.

change author url without wordpress plugin

There is default username in wordpress. admin is default username in wordpress but many times user want to use other wordpress user url for admin user. You can easily do this by using following wordpress hook.

You just need to place following code in functions.php file which is your theme folder.

add_action('init', 'change_wordpress_author_url');
function change_wordpress_author_url() {
global $wp_rewrite;
$author_slug = 'new_author_url';
$wp_rewrite->author_base = $author_slug;
}

You need to choose your author url. Just replace the “new_author_url” word and put in functions.php file.

change author url without wordpress plugin
how to change the author url in wordpress without wordpress plugin

Display the authors in dropdown menu using wp_dropdown_users – Hook/Filter

One of my client faced issue with Autor drop down which is in Admin section.

Display the authors in dropdown menu using hooks.

While creating the New post there was problem with the Author field. There are hundreds of irrelevant selections (users) and it’s difficult to select the right one.

WordPress is by default showing all the users in author drop down. I don’t want to show the other users in author drop down.

Display the authors in a dropdown menu
Hook/Filter – In wordpress Admin -Add new Post section -Display the authors in a dropdown menu using wp_dropdown_users One of my client faced issue with Autor drop down which is in Admin section. Display the authors in a dropdown menu using hooks

I searched for wp_dropdown_users hook or filter. But I did not found any proper solution.

Following articles are found helpful to me.
http://wordpress.org/support/topic/filter-for-post-quick-edit-author-drop-down
http://codex.wordpress.org/Function_Reference/wp_dropdown_users

Using that code I modified the code and I am able to fix the issue. You can put following code in to functions.php file.

 /*
 * Hook for showing Admin and Author in Add new Post - Admin section dropdown menu
 */
function wpapi_override_wp_dropdown_users($output) {
    global $post, $user_ID;
    //get the Admin-role users IDs
    $admins = getUsersWithRole('admin');
    //get the author-role users IDs
    $authors = getUsersWithRole('author');
    //merge the array
    $result = array_merge($admins, $authors);

    //array converted into comma seprated string
    $authorsall = implode(",", $result);

    // return if this isn't the theme author override dropdown
    if (!preg_match('/post_author_override/', $output))
        return $output;

    // return if we've already replaced the list (end recursion)
    if (preg_match('/post_author_override_replaced/', $output))
        return $output;

    // replacement call to wp_dropdown_users
    $output = wp_dropdown_users(array(
        'echo' => 0,
        'name' => 'post_author_override_replaced',
        'selected' => empty($post->ID) ? $user_ID : $post->post_author,
        'include_selected' => true,
        'include' => $authorsall
    ));

    // put the original name back
    $output = preg_replace('/post_author_override_replaced/', 'post_author_override', $output);

    return $output;
}

add_filter('wp_dropdown_users', 'wpapi_override_wp_dropdown_users');

/*
 * Find User IDs by Role
 */

function getUsersWithRole($role) {
    $wp_user_search = new WP_User_Search($usersearch, $userspage, $role);
    return $wp_user_search->get_results();
}

Using above code, you can load multiple role users in author drop down.

wordpress user search firstname lastname and display name code

In wordpress admin users listing page, wordpress admin has user search with username and email but we cannot search via display name or first name and last name.

We can add firstname, lastname and display name in users search. You just need to add following code.

/*
 * functions will be applicable for only wordpress admin
 */
if (is_admin()) {
 /*
 * Modify the User Search in Admin to include firstname, lastname and display_name
 */
 add_action('pre_user_query', 'wpapi_pre_user_query');

function wpapi_pre_user_query($user_search) {
 //die();
 global $wpdb;
 // print_r($user_search);
 $vars = $user_search->query_vars;
 if (!is_null($vars['search'])) {
 /* For some reason, the search term is enclosed in asterisks.
 Remove them */
 $search = preg_replace('/^\*/', '', $vars['search']);
 $search = preg_replace('/\*$/', '', $search);
 //print_r($search);
 //search in display name
 if(!empty($search)){
 $user_search->query_where = substr(trim($user_search->query_where), 0, -1) . " OR display_name LIKE '%". $search . "%')";
 }

 $user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m1 ON " .
 "{$wpdb->users}.ID=m1.user_id AND (m1.meta_key='first_name')";
 $user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m2 ON " .
 "{$wpdb->users}.ID=m2.user_id AND (m2.meta_key='last_name')";
 $names_where = $wpdb->prepare("m1.meta_value LIKE '%s' OR m2.meta_value LIKE '%s'", "%{$search}%", "%$search%");
 $user_search->query_where = str_replace('WHERE 1=1 AND (', "WHERE 1=1 AND ({$names_where} OR ", $user_search->query_where);
 }
 return $user_search;
 }

}

wordpress user search firstname lastname and display name code
wordpress user search firstname lastname and display name code