Skip to main content
Cookbook Security

Restrict Content by User Role with AI

Lock a members area, client portal, or staff page to the exact roles that should see it, and send everyone else cleanly to login or a permission notice.

Difficulty Intermediate
Time ~10 min
Tools run_wp_cli, rest_api

Prerequisites

A connected site and the free Code Snippets plugin, which the AI installs for you (installing a plugin asks for your approval once).

The prompt
On [my site], restrict [the page or pages, by title or URL] so only [the roles that should see them, for example editors and administrators, or a custom members role] can view them. Handle everyone else cleanly: send logged-out visitors to the login screen with a return link back to the page, and show logged-in users who lack the role a clear "you do not have permission" message rather than a blank page. Leave every other page on the site open exactly as it is now. Use a small snippet through the Code Snippets plugin, installing and activating it first if it is not already there and asking me to approve that once. When it is done, verify it by loading the restricted page as a logged-out visitor and confirming it redirects to login, and list exactly which pages and which roles you gated so I can spot-check.

Already connected to WPVibe?

Skip the copy-paste. Just ask your AI for the “Restrict Content by User Role with AI” recipe, or describe the task, and WPVibe runs these steps on your own site.

You have pages meant for one group and not the whole internet: a members area, staff documentation, a client portal, an early-access page. WordPress gives you Public or Private and little in between, and Private is a blunt tool that hides a page from everyone except administrators and editors, with no way to say “let this specific role in.” So most people reach for a heavy membership plugin they do not otherwise need, or they leave the page public and hope nobody finds the URL. Neither is the small, targeted control the job actually calls for.

WPVibe adds a small gate that checks who is viewing a page and lets through only the roles you name. We verified the full behavior on a test site with a page restricted to editors: a logged-out visitor was redirected to the login screen, a logged-in subscriber was stopped with a clear permission error even though they had an account, and a logged-in editor saw the page normally. A separate public page on the same site stayed open to everyone, which confirms the gate only touches the pages you choose and leaves the rest of the site alone.

Name the pages and the roles allowed to see them, and paste the prompt. The AI adds the gate through the free Code Snippets plugin (installing it asks for your approval once), then proves it by loading the restricted page as a logged-out visitor and confirming the redirect fires. Two honest limits: this controls who can view a page on the front end, it is not a full membership system with billing or drip scheduling, and it protects the page itself rather than any files or images you link from inside it. If you also want the page kept out of search results, ask the AI to add a noindex tag while it is in there.

Outcome

The pages you name are viewable only by the roles you allow; logged-out visitors go to login and logged-in users without the role get a permission notice, while every other page stays open.