{"id":3235,"date":"2025-11-14T12:22:55","date_gmt":"2025-11-14T12:22:55","guid":{"rendered":"https:\/\/codingfix.com\/?p=3235"},"modified":"2025-11-14T12:22:57","modified_gmt":"2025-11-14T12:22:57","slug":"add-a-custom-user-role","status":"publish","type":"post","link":"https:\/\/codingfix.com\/add-a-custom-user-role\/","title":{"rendered":"Add a custom user role"},"content":{"rendered":"\n<div class=\"wp-block-greenshift-blocks-row gspb_row gspb_row-id-gsbp-38d0038\" id=\"gspb_row-id-gsbp-38d0038\"><div class=\"gspb_row__content\"> \n<div class=\"wp-block-greenshift-blocks-row-column gspb_row__col--12 gspb_col-id-gsbp-eac17c2\" id=\"gspb_col-id-gsbp-eac17c2\">\n<h2 id=\"gspb_heading-id-gsbp-febea90\" class=\"gspb_heading gspb_heading-id-gsbp-febea90 \">Add a custom user role<\/h2>\n\n\n\n<div id=\"gspb_text-id-gsbp-a2e0f0a\" class=\"gspb_text gspb_text-id-gsbp-a2e0f0a \">Sometimes, you might need to assign a custom role to your registered users. To do it, just add this to your functions.php file:<br><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>add_role(\n\t'my_role',\n\t'My Role',\n\tarray(\n\t\t'read'              => false,\n\t\t'create_posts'      => false,\n\t\t'edit_posts'        => false,\n\t\t'edit_others_posts' => false,\n\t\t'publish_posts'     => false,\n\t\t'manage_categories' => false,\n\t)\n);\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #795E26\">add_role<\/span><span style=\"color: #000000\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">\t<\/span><span style=\"color: #A31515\">&#39;my_role&#39;<\/span><span style=\"color: #000000\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">\t<\/span><span style=\"color: #A31515\">&#39;My Role&#39;<\/span><span style=\"color: #000000\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">\t<\/span><span style=\"color: #795E26\">array<\/span><span style=\"color: #000000\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">\t\t<\/span><span style=\"color: #A31515\">&#39;read&#39;<\/span><span style=\"color: #000000\">              =&gt; <\/span><span style=\"color: #0000FF\">false<\/span><span style=\"color: #000000\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">\t\t<\/span><span style=\"color: #A31515\">&#39;create_posts&#39;<\/span><span style=\"color: #000000\">      =&gt; <\/span><span style=\"color: #0000FF\">false<\/span><span style=\"color: #000000\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">\t\t<\/span><span style=\"color: #A31515\">&#39;edit_posts&#39;<\/span><span style=\"color: #000000\">        =&gt; <\/span><span style=\"color: #0000FF\">false<\/span><span style=\"color: #000000\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">\t\t<\/span><span style=\"color: #A31515\">&#39;edit_others_posts&#39;<\/span><span style=\"color: #000000\"> =&gt; <\/span><span style=\"color: #0000FF\">false<\/span><span style=\"color: #000000\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">\t\t<\/span><span style=\"color: #A31515\">&#39;publish_posts&#39;<\/span><span style=\"color: #000000\">     =&gt; <\/span><span style=\"color: #0000FF\">false<\/span><span style=\"color: #000000\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">\t\t<\/span><span style=\"color: #A31515\">&#39;manage_categories&#39;<\/span><span style=\"color: #000000\"> =&gt; <\/span><span style=\"color: #0000FF\">false<\/span><span style=\"color: #000000\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">\t)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<div id=\"gspb_text-id-gsbp-b20d49b\" class=\"gspb_text gspb_text-id-gsbp-b20d49b \"><em><br>Add a custom user role with no capabilities&#8230; or the ones you want to give it.<\/em>\ud83d\udc68\u200d\ud83e\uddb1\ud83d\udc69<\/div>\n<\/div>\n <\/div><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":3,"featured_media":3051,"comment_status":"open","ping_status":"open","sticky":false,"template":"wp-custom-template-single-ninja-post","format":"standard","meta":{"_gspb_post_css":"#gspb_row-id-gsbp-38d0038{justify-content:space-between;margin-top:0;display:flex;flex-wrap:wrap;margin-bottom:0}#gspb_row-id-gsbp-38d0038>.gspb_row__content{display:flex;justify-content:space-between;margin:0 auto;width:100%;flex-wrap:wrap}.gspb_row{position:relative}div[id^=gspb_col-id]{box-sizing:border-box;position:relative;padding:var(--gs-row-column-padding, 15px min(3vw, 20px))}body.gspb-bodyfront #gspb_row-id-gsbp-38d0038>.gspb_row__content{max-width:var(--wp--style--global--wide-size, 1200px)}#gspb_col-id-gsbp-eac17c2.gspb_row__col--12{width:100%}@media (max-width:575.98px){#gspb_col-id-gsbp-eac17c2.gspb_row__col--12{width:100%}}.gspb_text-id-gsbp-b20d49b{margin-bottom:0!important}","footnotes":""},"categories":[134],"tags":[],"post_folder":[144],"class_list":["post-3235","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wp-sniptips"],"_links":{"self":[{"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/posts\/3235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/comments?post=3235"}],"version-history":[{"count":1,"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/posts\/3235\/revisions"}],"predecessor-version":[{"id":3236,"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/posts\/3235\/revisions\/3236"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/media\/3051"}],"wp:attachment":[{"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/media?parent=3235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/categories?post=3235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/tags?post=3235"},{"taxonomy":"post_folder","embeddable":true,"href":"https:\/\/codingfix.com\/wp-json\/wp\/v2\/post_folder?post=3235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}