Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What is the recommended way to approach the follow issue? I have to create two pages. On one page I will have a small form where users will be able to register themselves (with or without photo). On the other page, I will show all the users' info entered on the previous form. For the admin section, I just need to have all the registered users listed and to be able to delete them.

I don't want to touch the default's WP user registration stuff, because it is already being used and I cannot mix up the things.

Is it possible to use some kind of custom post types? Any plugin or idea?

share|improve this question
    
Any reason why you couldn't use the WP user tables but create a special role to separate these registered users from everyone else? –  Stephen Harris Feb 25 '12 at 12:52
    
Any example in how to do that? –  Daniel Feb 25 '12 at 14:02

2 Answers 2

up vote 2 down vote accepted

The following code creates a new role. In fact is simply clones the subscriber role, so if you are not using that role currently, you may as well just use that.

The following function need only be run once (it run's when a user is 'admin side')

//Creates a custom role called 'my_new_role'.
//Run this once then feel free to comment out the next line:
add_action('admin_init', 'my_custom_role');
function my_custom_role(){
    global $wp_roles;

    $subscriber = $wp_roles->get_role('subscriber');

    //Adding a 'new_role' with subscriber caps
    $wp_roles->add_role('my_new_role', 'My New Role', $subscriber->capabilities);
    //Optional add/remove caps, like the capability to access the dashboard
    //$wp_roles->remove_cap('my_new_role','read');  
}

See the codex for more information on capabilities.

Wherever your are processing the form you'll want to create a new user and assign them the role 'my_new_role'. To do this use the wp_insert_user. As a brief example:

wp_insert_user( array (
    'user_login' => 'JoeBloggs',
    'user_pass' => 'a_password_43463', 
    'first_name' => 'Joseph',
    'last_name' => 'Bloggs',
    'role'=>'my_new_role') ) ;

Prior to the above you should have performed all the nonce-checks, data validation and any other checks.

You may wish to redirect these new users to a different page (not the dashboard) when they log-in. To do this use the login_redirect filter.

add_filter('login_redirect', 'dashboard_redirect');
function dashboard_redirect($url) {
    global $current_user;
    get_currentuserinfo();

    if (current_user_can('my_new_role')) {
             //current user is 'my_new_role', take them somewhere else...
             $url = home_url(); 
        }
        return $url;
    }
share|improve this answer
    
Good piece of code, I will play with it around. Just one question. How do I list in the backend all users that were assigned to 'my_new_role'? –  Daniel Feb 25 '12 at 20:35
    
That's a good question - could you ask it? It would probably be helpful to others. –  Stephen Harris Feb 25 '12 at 20:54
    
It's done, thanks. –  Daniel Feb 25 '12 at 21:18

I would face it this way:

Database extension for wordpress allow you to manage very easily the content, you just need to create the form(s) and then you can retrieve and modify the information as you wish. For the other page, since the extension shows you the path to the database, you just need to make some queries and you are done.

share|improve this answer
    
I thought about that, but this approach doesn't allow me to manage the registered users. –  Daniel Feb 25 '12 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.