Pages

Thursday, January 26, 2012

5 Must-Know Tips for Better WordPress User Management


WordPress is a great tool to use for managing content. It's really simple for developers, for managers and for users to use, especially when using a great theme. But if there is one thing that I think that needs to improve yet is its user management settings. I mean, even basic functions need to be coded, like editing a user's profile fields, add roles, edit capabilities, export user data. All of those need plugins or a little coding to get working.

Here we'll see 5 amazing and simple tips that you can use right now and greatly improve your user management and you can use all this additional data to serve your loyal readers better and provide more focused content.

We'll cover custom user fields to history functionality, and while we're at it you'll learn a lot about WordPress user management functions.

So, let's rock!

What will we see?


We'll focus on user specific data, so what we'll see is:

  1. How to add extra registration fields
  2. How to add and remove profile fields
  3. Export the user data
  4. Bulk export users data
  5. Create a web history of the user

1. How to add extra registration fields


Sometimes we want to know our users better. Where they live, if they want to receive our newsletter, or just store their IP. Well, to get this working the easiest way is to use one of these:

PieRegister

It allows you to . Pretty useful and easy to change.

What I like most is its simplicity. If you want to just get started, this one is your best choice.

s2Member

On the other side, you may use a plugin like which gives you full control over user's capabilities and data. But it requires a little more setup and will change a lot of things in your wp-admin. So you can edit each posts visibility for free or premium users.

Maybe it's too much if you just want to add more user registration fields, but it gives you much better control over user data and content.

2. How to add and remove profile fields


Truth be told, the default user profile fields are more markup than anything useful. But WordPress has an easy way to edit them.

Let's say instead of Yahoo IM, you want to add a Twitter field. Or just remove it. Well, this can be done with the filter 'user_contactmethods', which can be added as plugin or in your theme's functions.php file. Do it this way:

3. Export the user data


Now we have saved user data, but it can't be seen. What we'll need is a function to export this when we want (in a custom page, for instance).

Our function will get user data directly from the wp_usermeta table, and remove unnecessary data (used just by WordPress, but keep them if you want to export all user data).

This function will do the trick:

".$field->meta_key.": ".$field->meta_value."
"; } ?>

4. Bulk export user data


Now if you want to move from WordPress to another CMS you may need to hire a programmer just to figure out how to export all user data. Ok, we'll save you from this crazy work and give you a function to see all users with all their custom data!

What we have to do is get the previous function and run it for every user_id inside the WordPress wp_users table. Then you can import this content or format it according to your new CMS standards.

User #".$user->ID." data"; 		foreach( $data as $field ) { 			if( ! empty ($field->meta_value) ) 				echo "".$field->meta_key.": ".$field->meta_value."
"; } } ?>

5. Create a web history of the user


Sometimes user behavior is completely nonlinear. I know, you publish your posts with a carefully thought out order, but people just click everywhere and sometimes they stop thinking "which one was the cool post I was reading 5 minutes ago?".

Same thing may happen if you run an e-commerce store over WordPress. Users navigate through products and sometimes the very first one was the best for them.

So for these times, I would recommend you build a user history.

First you should define how many items you want to store, and this will depend on your site's size. We'll do this with the last 30 visited pages (easily changed).

Then, you'll need to add this snippet to your functions.php or plugin file, then you just call show_history and you'll be fine :)

ID) ) { 		$i = get_user_meta($current_user->ID, "wd_i", true); 		$i++;  		//update fields 		update_user_meta($current_user->ID, "wd_i", $i); 		update_user_meta($current_user->ID, "wd_page_".$i, "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); 		//delete older 		delete_user_meta( $current_user->ID, "wd_page_".($i-30) ); 	} }  function show_history() { 	$current_user = wp_get_current_user();  	// logged in? 	if ( ! empty ($current_user->ID) ) { 		$i = get_user_meta($current_user->ID, "wd_i", true);  		echo "
    "; $end = $i - 30; while( $i > $end ) { $url = get_user_meta($current_user->ID, "wd_page_".$i, true); $pid = url_to_postid( $url ); if ( ! empty ($pid) ) { $page = get_post($pid); $title = $page->post_title; } else { $title = "Home"; } echo "
  • $title
  • "; $i--; } echo "
"; } } show_history(); ?>

Other experiments


Did you know that it's possible to create shopping cart functionality with user meta data? Well, we haven't covered this because the article would get too big, but we will cover this soon :)

Now it's your turn!


What do you think? Is there another user management function that you want to share with us? Just comment! :)




Sent from my iPhone

No comments:

Post a Comment