menus – Control page access based on User Meta data?

Question

I want to control access to pages (and menus) based on whether the viewer has a value in a user meta data field.

I’ve made a plugin that securely receives viewers from another private system where they are signed in, makes an account for them if needed, copies in custom values (about a dozen values) to user meta data, and signs them into the WordPress site. Most will be subscribers, but some could be assigned roles like editor or admin. I can alter this single sign-on system to do something else as needed, but adding the user meta data would be a part of it.

The challenge now:

  1. I want to be able to restrict page access based on one of the user meta data fields. I should be able to block page access by simply checking the user meta data, but what’s the best way to remove pages from the menu based on that? Do the menus in most themes have a hook that would allow my plugin to remove a menu item?

  2. The other challenge is adding to the page editor so that admins/editors can specify that the page they are editing can or cannot be seen according to the user meta data.

This seems to be so simple and basic, but I can’t find any plugin that controls page/menu access based on user meta data.

Any tips would be appreciated.

0
Glen Little 3 weeks 2023-01-17T00:49:19-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse