如何使客户登录到客户特定的管理页面

时间:2012-02-03 作者:Timothée HENRY

我想建立一个网站,让访问者注册,并获得访问自己的个人管理页面。

因此,用户#1将输入其登录名和密码,并使用其参数访问其管理页面。用户#2将看到自己的参数等。

这是否可以使用wordpress主题和插件?如果是,你会建议使用哪个主题或插件?

2 个回复
SO网友:Evan Yeung

我以前做过这个,所以我在这里重用代码。你需要做一些调整,使其与你的网站相匹配。您还需要Peter\'s Login Redirect 插件。

我没有解释代码,因为现在完成所有代码需要太多时间。如果您有任何问题,请添加评论,我将尽力解释。我还假设你有WordPress方面的知识

为客户区创建自定义帖子类型

//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;
}
为每个用户创建术语

// 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 ));
        }
    }   
}
添加凭据签入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.
}

结束

相关推荐

Where are plugins located

我通常通过FTP下载和安装插件,但我已经从web界面安装了一些插件。我正在尝试将WP从远程移动到本地,我得到一个空白的WP管理屏幕。我认为是我的一个插件导致了这个问题。我已将wp-content/plugins重命名为wp-content/u-plugins,以禁用该文件夹中的所有插件。但我安装的插件没有出现在插件文件夹中,我认为这是导致wp管理屏幕空白的原因。请告知。谢谢