该解决方案意味着您已禁用对“普通”帖子类型(帖子,页面)的编辑。
这并不像你想象的那么难。键是用户登录名。分类法甚至术语也可以做到这一点。
请参见以下内容(还有一个查询示例):
// 1st: Add a post type for that user with it\'s
// user login & according capabilities
function create_user_home() {
global $current_user;
get_currentuserinfo();
register_post_type(
\'home_of_\'.$current_user->user_login,
array(
\'public\' => true,
\'capability_type\' => $current_user->user_login,
\'capabilities\' => array(
\'publish_posts\' => \'publish_\'.$current_user->user_login,
\'edit_posts\' => \'edit_\'.$current_user->user_login,
\'edit_others_posts\' => \'edit_\'.$current_user->user_login,
\'delete_posts\' => \'delete_\'.$current_user->user_login,
\'delete_others_posts\' => \'delete_others_\'.$current_user->user_login,
\'read_private_posts\' => \'read_private_\'.$current_user->user_login,
\'edit_post\' => \'edit_\'.$current_user->user_login,
\'delete_post\' => \'delete_\'.$current_user->user_login,
\'read_post\' => \'read_\'.$current_user->user_login,
),
)
);
}
add_action( \'init\', \'create_user_home\' );
// A query could be done like this:
wp_reset_query(); // to be sure
global $wp_query, $current_user;
get_currentuserinfo();
$query_user_home = new WP_Query( array(
,\'order\' => \'ASC\'
,\'post_type\' => \'home_of_\'.$current_user->user_login
,\'post_status\' => \'publish\'
) );
if ( $query_user_home->have_posts() ) :
while ( $query_user_home->have_posts() ) : $query_user_home->the_post();
// check for password
if ( post_password_required() ) :
the_content();
elseif ( !current_user_can(\'\') ) :
// display some decent message here
return;
else :
// here goes your content
endif;
endwhile;
else : // else; no posts
printf(__( \'Nothing from Mr./Mrs. %1$s so far.\', TEXTDOMAIN ), $current_user->user_firstname.\' \'.$current_user->user_lastname);
endif; // endif; have_posts();
wp_rewind_posts(); // for a sec. query
对于分类法,这甚至更有意义,因为您只能查询带有此用户分类法中术语标记的帖子,但这需要一个带有用户分类法术语的帖子元框。条件相同:用户登录名,只需添加分类:
function create_user_tax() {
if ( current_user_can("$current_user->user_login") ) :
global $current_user;
get_currentuserinfo();
$singular = $current_user->user_login;
$plural = $singular.\'\\\'s\';
// labels
$labels = array (
\'name\' => $plural
,\'singular_name\'=> $singular
);
// args
$args = array (
\'public\' => true
,\'show_in_nav_menus\' => true
,\'show_ui\' => true
,\'query_var\' => true
,\'labels\' => $labels
,\'capabilities\' => array(
\'manage_\'.$current_user->user_login
)
);
// Register
register_taxonomy (
$current_user->user_login
,array ( \'post\', \'page\' )
,$args
);
// Add to post type
// you can even add your current user post type here
register_taxonomy_for_object_type (
$current_user->user_login
,array ( \'post\', \'page\', \'home_of_\'.$current_user->user_login )
);
endif;
}
add_action( \'init\', \'create_user_tax\' );
能力检查(current\\u user\\u can)的位置也可以在其他地方。取决于您的具体需求。为了确保这一点:以下是一些示例,可以指导您找到解决方案。希望对您有所帮助: