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.

I would like to build a website that will let visitors register and get access to their own personal admin page.

So user #1 will input his login and password and get access to his admin page with his parameters. User #2 will see his own parameters, etc.

Is this possible using wordpress themes and plugins? and if yes, which theme or plugin would you advise?

share|improve this question

2 Answers 2

I have done this in the past before, so I am reusing the code here. You will need to do some tweaking for it to mesh with your site. You will also need Peter's Login Redirect plugin.

I did not explain the code because it would take too much time to work through all of it right now. If you have any trouble please add a comment and I will try my best to explain. I am also assuming you have WordPress knowledge.

Create Custom Post Type for Client Area

//CLIENT AREA
add_action('init', 'create_client_area');
function create_client_area() {
    register_taxonomy( 'client_category', array(), array(
        'hierarchical' => true,
        'labels' => array(
            'name' => 'Clients',
            'singular_name' => 'Client'
        ),
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'clientarea' )
    ));
    register_post_type( 'client', array(
        'labels' => array(
            'name' => 'Client Area',
            'singular_name' => 'Client Project'
        ),
        'supports' => array('title', 'editor', 'thumbnail', 'comments'),
        'public' => true,
        'hierarchical' => false,
        'show_ui' => true,
        'show_in_menu' => true,
        'capability_type' => 'post',
        'rewrite' => array(
            'slug' => 'clientarea/%client_category%',
            'with_front' => false
        ),
        'query_var' => true,
        //'has_archive' => 'work',
        'has_archive' => false,
        'taxonomies' => array( 'client_category' )
    ));
}
add_filter('post_type_link', 'client_area_permalink', 10, 4);
function client_area_permalink($post_link, $post, $leavename, $sample) {
    if ( false !== strpos( $post_link, '%client_category%' ) ) {
        $client_category = get_the_terms( $post->ID, 'client_category' );
        if(!$client_category) { $client_category = array(); }

        $post_link = str_replace( '%client_category%', array_pop($client_category)->slug, $post_link );
    }
    return $post_link;
}

Create a Term for each User

// CLIENT ROLE
add_role( 'client', 'Client', array('read') );

// CREATE TERM ON REGISTER
add_action('user_register', 'create_client_category', 10, 3);
function create_client_category( $user_ID ) {
    $user = new WP_User( $user_ID );
    if( in_array('client', $user->roles) ) {
        $userdata = get_userdata($user_ID);
        if( !term_exists($userdata->user_nicename, 'client_category') ) {
            wp_insert_term( $userdata->user_login, 'client_category', array(
                'slug' => $userdata->user_nicename ));
        }
    }   
}

Add Credential Check in Specialized Header

function show_404() {
    global $wp_query;
    $wp_query->set_404();
    status_header( 404 );
    get_template_part( 404 ); exit();
}

if(is_page()) {
    if( current_user_can('client') ) {
        global $user_ID;
        $user = get_userdata( $user_ID );
        if(term_exists($user->user_nicename, 'client_category')) {
            wp_redirect( home_url('/clientarea/'.$user->user_nicename.'/') ); exit;
        } else { show_404(); }
    } elseif( !current_user_can('administrator') ) { show_404(); }
} elseif(is_tax()) {
    if( !current_user_can('administrator') && get_userdata($user_ID)->user_nicename != $wp_query->queried_object->slug) { // not admin and not user page
        show_404();
    }
} elseif(is_single()) {
    global $user_ID;
    $user = get_userdata( $user_ID );
    $terms = get_the_terms($post->id, 'client_category');
    foreach( $terms as $term ) {
        if($term->slug != $user->user_nicename) $deny = true;
    }
    if( !current_user_can('administrator') && $deny) {
        show_404();
    }
} else {
    // dont know what goes here...thinking.
}
share|improve this answer
    
Thanks for your input. Though I would rather use a ready-made solution. –  tucson Feb 4 '12 at 10:46

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.