1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | //CSSで管理画面内のサイドメニューを非表示にする 権限指定 function custom_admin_styles(){ $current_user = wp_get_current_user(); //現在のユーザー情報を取得 if (check_user_role( $current_user , 'author' )){ //編集者(editor)かチェック echo '<link rel="stylesheet" type="text/css" href="' .get_bloginfo( 'template_directory' ). '/custom-admin-css2.css" />' ; } if (check_user_role( $current_user , 'reader' )){ //編集者(editor)かチェック echo '<link rel="stylesheet" type="text/css" href="' .get_bloginfo( 'template_directory' ). '/custom-admin-css2.css" />' ; } } add_action( 'admin_print_styles' , 'custom_admin_styles' , 21); /* * ユーザーの権限をチェックする * @param $user ユーザーオブジェクト * @param $role ユーザー権限の文字列 * (administrator, editor, author, contributor, subscriber) */ function check_user_role( $user , $role ){ foreach ( $user ->roles as $user_role ){ if ( $user_role === $role ){ return true; } } return false; } |