Support » Plugin: Custom Post Type UI » How restrict custom post type too user role

  • Resolved calaiopee

    (@calaiopee)


    Hi,

    I need custom post types on my site that are exclusively accessible by certain roles. How can I assing a cpt to certain roles?

    I work with members plugin and the content restriction metabox that allows for the default wordpress posts and pages to select roles for access permission does not appear with the custom post types.

    I can see my cpts in members and assign the capabilities to roles. This part works just fine. But when I create a custom post the metabox for content restrictions does not show. Obviously, the cpts don’t support this metabox feature.

    Maybe there’s a possibility to code:

    check user roles
    if roles are “teacher1” or “student1”
    cpts array slugs=’xyz’, ‘abc’,’rtl’ is accessible
    else: show landingpage: http://www.sorry-you-are-not-allowed

    ??

    Thanks
    Kathryn

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Just to make sure I’m following correctly, the biggest issue is that the metabox isn’t showing up like expected, so you’re inquiring about an alternative method to hide the content?

    Thread Starter calaiopee

    (@calaiopee)

    Yes, thanks Micheal, for your quick response!!

    The members metabox is not showing and I can’t grant access to certain roles the easy way with checkboxes.

    Now I need to find a workaround … and still grant access to certain roles and deny access to all others …
    Cally

    • This reply was modified 1 year ago by calaiopee.
    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Can you send me the blob of content on the right side of the page when you visit our CPTUI Tools menu. It’ll allow me to import your CPT settings to see if I can recreate. I just registered a very basic post type and got the metabox for restrictions, so I’m curious if it’s a chosen settings detail.

    Thread Starter calaiopee

    (@calaiopee)

    Here you go!

    {"beitrag_dawidmunchen":{"name":"beitrag_dawidmunchen","label":"Beitr\u00e4ge DAWID M\u00fcnchen","singular_label":"Beitrag DAWIDM\u00fcnchen","description":"Hier findest Du aktuelle Meldungen vom Dawid-M\u00fcnchen Team zu den laufenden Seminaren. \r\n\r\nDu kannst einen Kommentar schreiben, falls Du die Kl\u00e4rung eines bestimmten Sachverhalts brauchst. \r\n\r\nDu kannst das aber auch in der Gruppe unter AKTIVIT\u00c4TEN ein Beitrag schreiben. Dann sehen es alle.","public":"false","publicly_queryable":"false","show_ui":"true","show_in_nav_menus":"true","delete_with_user":"false","show_in_rest":"true","rest_base":"","rest_controller_class":"","has_archive":"true","has_archive_string":"dawid-munchen","exclude_from_search":"true","capability_type":"Beitrag M\u00fcnchen","hierarchical":"true","rewrite":"true","rewrite_slug":"","rewrite_withfront":"true","query_var":"true","query_var_slug":"","menu_position":"5","show_in_menu":"true","show_in_menu_string":"","menu_icon":"dashicons-format-standard","supports":["title","editor","thumbnail","excerpt","comments","author","post-formats"],"taxonomies":[],"labels":{"menu_name":"Beitrag DAWID M\u00fcnchen","all_items":"Alle","add_new":"Neu","add_new_item":"Hinzuf\u00fcgen","edit_item":"Bearbeiten","new_item":"Neuen Beitrag hinzuf\u00fcgen","view_item":"Beitrag anzeigen","view_items":"Beitr\u00e4ge anzeigen","search_items":"Beitrags suchen","not_found":"Keinen Beitrag gefunden","not_found_in_trash":"Keinen Beitrag im Papierkorb gefunden","parent":"\u00dcbergeordneter Beitrag","featured_image":"Beitragsbild","set_featured_image":"Beitragsbild festlegen","remove_featured_image":"Beitragsbild entfernen","use_featured_image":"Ausgew\u00e4hltes Bild verwenden","archives":"Archiv","insert_into_item":"In Beitrag einf\u00fcgen","uploaded_to_this_item":"Zu diesem Beitrag hochladen","filter_items_list":"Beitr\u00e4ge filtern","items_list_navigation":"Beitr\u00e4ge Navigation","items_list":"List der Beitr\u00e4ge","name_admin_bar":"Beitrag DAWID M\u00fcnchen","item_published":"Beitrag ver\u00f6ffentlicht","item_published_privately":"Beitrag privat ver\u00f6ffentlicht","item_reverted_to_draft":"Beitrag als Entwurf gespeichert","item_scheduled":"Geplanter Beitrag","item_updated":"Beitrag aktualisiert","parent_item_colon":"\u00dcbergeordneter Beitrag","attributes":""},"custom_supports":"roles"},"seiten_dawid_munchen":{"name":"seiten_dawid_munchen","label":"Seiten DAWID M\u00fcnchen","singular_label":"Seite DAWID M\u00fcnchen","description":"Infoseiten, nur f\u00fcr die Gruppe DAWID M\u00fcnchen","public":"true","publicly_queryable":"true","show_ui":"true","show_in_nav_menus":"true","delete_with_user":"false","show_in_rest":"true","rest_base":"","rest_controller_class":"","has_archive":"false","has_archive_string":"","exclude_from_search":"true","capability_type":"Seite M\u00fcnchen","hierarchical":"true","rewrite":"true","rewrite_slug":"","rewrite_withfront":"true","query_var":"true","query_var_slug":"","menu_position":"6","show_in_menu":"true","show_in_menu_string":"","menu_icon":"dashicons-admin-page","supports":["title","editor","thumbnail","page-attributes"],"taxonomies":[],"labels":{"menu_name":"Seiten DAWID M\u00fcnchen","all_items":"Alle","add_new":"Neu","add_new_item":"Hinzuf\u00fcgen","edit_item":"Bearbeiten","new_item":"Neue Seite hinzuf\u00fcgen","view_item":"Seite anzeigen","view_items":"Seiten anzeigen","search_items":"Seite suchen","not_found":"Keine Seite gefunden","not_found_in_trash":"Keine Seite im Papierkorb gefunden","parent":"\u00dcbergeordnete Seite","featured_image":"Beitragsbild","set_featured_image":"Beitragsbild festlegen","remove_featured_image":"Beitragsbild entfernen","use_featured_image":"Ausgew\u00e4hltes Bild verwenden","insert_into_item":"In die Seite einf\u00fcgen","uploaded_to_this_item":"Zur Seite hochladen","filter_items_list":"Seitenliste filtern","items_list_navigation":"Seitenlisten Navigation","items_list":"Liste der Seiten","name_admin_bar":"Seite DAWID M\u00fcnchen","item_published":"Seite ver\u00f6ffentlicht","item_published_privately":"Seite privat ver\u00f6ffentlicht","item_reverted_to_draft":"Seite als Entwurf gespeichert","item_scheduled":"Seite geplant","item_updated":"Seite aktualisiert","parent_item_colon":"\u00dcbergeordnete Seite","archives":"","attributes":""},"custom_supports":""}}

    Thread Starter calaiopee

    (@calaiopee)

    it’s German. Hope you don’t mind.

    Love
    Cally

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not a problem.

    Looks like the public setting being false is preventing the metabox from showing for the “beitrag_dawidmunchen” post type. The other one, “seiten_dawid_munchen” is showing it just fine. Makes sense since it’s not meant to even be queryable on the frontend, there’s no need to hide it by role.

    If you’re needing to hide the metabox on the admin, based on current user editing, it looks like the metabox code will won’t register if the current user doesn’t have the restrict_content capability.

    Thread Starter calaiopee

    (@calaiopee)

    You are perfectly right. Works fine. Why did I not see this?

    Thank you very much for your time and effort.

    Can I get you a coffee?

    Warmly
    Cally

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome.

    We have a donate button on the lower right hand side of our plugin’s main page at https://wordpress.org/plugins/custom-post-type-ui/

    Reviews are also appreciated in place of donations, as that helps keep us at the top of post type based plugins 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How restrict custom post type too user role’ is closed to new replies.