class-grunion-contact-form-endpoint.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * Plugin Name: Feedback CPT Permissions over-ride
  4. */
  5. if ( class_exists( 'WP_REST_Posts_Controller' ) ) {
  6. /**
  7. * Class Grunion_Contact_Form_Endpoint
  8. * Used as 'rest_controller_class' parameter when 'feedback' post type is registered in modules/contact-form/grunion-contact-form.php.
  9. */
  10. class Grunion_Contact_Form_Endpoint extends WP_REST_Posts_Controller {
  11. /**
  12. * Check whether a given request has proper authorization to view feedback items.
  13. *
  14. * @param WP_REST_Request $request Full details about the request.
  15. * @return WP_Error|boolean
  16. */
  17. public function get_items_permissions_check( $request ) {
  18. if ( ! is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) {
  19. return new WP_Error(
  20. 'rest_cannot_view',
  21. esc_html__( 'Sorry, you cannot view this resource.', 'jetpack' ),
  22. array( 'status' => 401 )
  23. );
  24. }
  25. return true;
  26. }
  27. /**
  28. * Check whether a given request has proper authorization to view feedback item.
  29. *
  30. * @param WP_REST_Request $request Full details about the request.
  31. * @return WP_Error|boolean
  32. */
  33. public function get_item_permissions_check( $request ) {
  34. if ( ! is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) {
  35. return new WP_Error(
  36. 'rest_cannot_view',
  37. esc_html__( 'Sorry, you cannot view this resource.', 'jetpack' ),
  38. array( 'status' => 401 )
  39. );
  40. }
  41. return true;
  42. }
  43. }
  44. }