WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Post Type Capabilities (6 posts)

  1. dyordan1
    Member
    Posted 1 year ago #

    Hello fellow WordPress developers!

    I'm trying to wrap my head around the custom post type capabilities in wordpress... I have a custom type that I called faculty and I've set the capability_type for it to fac_profile. I also have a new role that I've created, also called faculty(I don't think that's a conflict but I can change it easily). Now, I want people of that faculty role to be able to only change faculty profiles they are assigned as an author to. If I assign them the permissions

    'read_fac_profile' => true,
    'edit_fac_profile' => true,
    'edit_fac_profiles' => true,
    'publish_fac_profiles' => true,

    all is well and good but they can add new profiles. If I remove 'edit_fac_profiles', the whole default wordpress admin UI disappears. Is there an easy way to accomplish what I want or do I have to implement my own UI with custom permission checks to imitate the WordPress default one?

  2. bcworkz
    Member
    Posted 1 year ago #

    If you remove the publish capability, they should not be able to add new profiles, but can still edit existing ones.

  3. dyordan1
    Member
    Posted 1 year ago #

    Yes, that's true. Although, technically they'll still be able to create new profiles, they just wouldn't be able to make them public. On the other hand though, that will make them unable to publish any changes on the profile they were assigned to as an author as well, which is definitely what I don't want to happen. I still want them to have publish access to the one profile they are able to edit AND at the same time be unable to create new ones (even drafts). Any ideas?

  4. bcworkz
    Member
    Posted 1 year ago #

    Uh... Didn't think that one through very well. Hopefully this idea works better. Even though it is meant for a different purpose, the "add_meta_boxes" action could work for your enforcement of no new profiles for faculty. I'm assuming it fires when the editor opens for your faculty profiles as it does for other post types.

    Your action hook function will be passed the post type and post object. Between the $type and the $post->post_status, you can easily determine if it's an existing profile edit or an attempt to add new. If it's a faculty user and a new profile, simply wp_die() with an error message.

  5. dyordan1
    Member
    Posted 1 year ago #

    Ah, but of course, I could just make WordPress go belly up when they try to create a new profile! Not the most graceful approach but a very functional one nevertheless! Thank you, I appreciate your help! If I come up with a better solution at some point and don't forget to do so, I might post it here at some point. For now, this should be sufficient. Thanks!

  6. bcworkz
    Member
    Posted 1 year ago #

    Glad to help. WordPress core dies itself often enough on error, but yes, rather crude. As it turns out with this action, no headers are yet sent, so wp_redirect would work to send the misguided faculty anywhere you want for more elegant error handling.

Topic Closed

This topic has been closed to new replies.

About this Topic