投稿者ユーザー専用のカテゴリーを立て、カテゴリーインデックスを編集可能にしたい
-
お知恵をお貸し下さい。
投稿者でユーザーを立てると同時にユーザー名のカテゴリーを立てて、
プラグイン Author Category でその投稿者の専用とし、他のユーザーの投稿記事を見せない仕組みまでは作れたのですが、そのカテゴリーインデックスも編集可能にさせるにはどのようなコードをfunctions.phpに書けばよいでしょうか。(投稿者ユーザーの登録と同時にユーザー名のカテゴリーを立てる)
function create_category( $user_id ) { $user_info = get_userdata($user_id); $user_name = $user_info->user_login; $my_cat = array( 'cat_name' => $user_info->first_name, 'category_nicename' => $user_name, 'category_parent' => '' ); wp_insert_category( $my_cat ); $cat_id = get_cat_ID( $user_id ); wp_set_post_categories( $post->ID, array( $cat_id ), true ); } add_action('user_register', 'create_category' );
(投稿者の投稿(所有)のみにアクセス限定)
function show_owned_posts_only( $views ) { unset($views['all']); // すべて unset($views['draft']); // 下書き unset($views['publish']); // 公開済み unset($views['pending']); // 保留中 unset($views['trash']); // ゴミ箱 return $views; } add_filter('views_edit-post', 'show_owned_posts_only');
(投稿が0件でも他者の投稿一覧が見えないように)
function hide_other_posts($wp_query) { global $current_screen, $current_user; if($current_screen->id != "edit-post") { return; } if($current_user->roles[0] == "administrator") { return false; } $wp_query->query_vars['author'] = $current_user->ID; } add_action('pre_get_posts', 'hide_other_posts')
- トピック「投稿者ユーザー専用のカテゴリーを立て、カテゴリーインデックスを編集可能にしたい」には新たに返信することはできません。