How to do it...

Take the following steps to build a recently registered user list and display it on the site using a shortcode:

  1. Open the wpcookbookchapter5.php file of the WPCookbook Chapter 5 plugin in the code editor.
  2. Add the following code block to define a shortcode and callback function for the recently registered user list:
add_shortcode('wpccp_recent_user_list', 'wpccp_chapter5_recent_user_list');
function wpccp_chapter5_recent_user_list($atts,$content){
// Step 3 code should be placed in next line
}
  1. Add the following code block after the comment "// Step 3 code should be placed in next line", to query the database and generate the user list:
$user_query = new WP_User_Query( array(
'orderby' => 'registered',
'order' => 'ASC',
'number' => 5
) );

$user_list = $user_query->get_results();
$user_list_html = '<ul>';
if(count($user_list) > 0){
foreach ($user_list as $key => $user) {
$user_list_html .= '<li>'. $user->user_login .'</li>';
}
}else{
$user_list_html .= '<li>'.__('No Users Found','wpccp') .'</li>';
}
$user_list_html .= '</ul>';
return $user_list_html;

Now, the shortcode is ready to display the recently registered users. Take the following steps to add the shortcode to a page and display the list on the frontend:

  1. Log in to the Dashboard as an administrator.
  2. Click the Pages menu from the left-hand section.
  3. Click the Add New button to create a page.
  4. Add a title to the page and the following shortcode as content:
[wpccp_recent_user_list]
  1. Click the Publish button to create and publish the page.
  2. Now, click the View Page link to view the page on the frontend with a recently registered user list, as shown in the following screenshot:

We have just displayed the username in this case. You can use other user details, such as the registered date and full name, in such a list.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.84.169