pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.06k stars 265 forks source link

Fix custom capability fallback #7250

Closed JoryHogeveen closed 3 months ago

JoryHogeveen commented 5 months ago

Description

Currently if you leave the custom capability field empty it will fallback to post instead of the CPT name. This PR fixes this :)

Related GitHub issue(s)

Related #7218

Testing instructions

  1. Create CPT with custom cap
  2. Leave custom cap empty
  3. Switch to role that includes the custom edit caps (edit_cpt/edit_cpts) but doesn't have the default edit_post and edit_posts caps.
  4. Try to edit CPT post
  5. You can't! :(
  6. Apply patch
  7. You can! :)

Changelog text for these changes

PR checklist

what-the-diff[bot] commented 5 months ago

PR Summary

sc0ttkclark commented 3 months ago

I believe this was intentional because all CPTs by default use 'post' as the capability base: https://developer.wordpress.org/reference/functions/register_post_type/#:~:text=the%20posts%20icon.-,capability_type,-string%7Carray

I'm going to keep this as it was before except add a strict check on it so that if it was saved as empty then should force 'post' no matter what there.

sc0ttkclark commented 3 months ago

Oh wait I see this was capability_type_custom, carry on!