From 9e6142cb376c146a0a17dc7221fbf6c2bbd013eb Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 9 Nov 2023 16:11:38 -0500 Subject: [PATCH] `gw-submit-to-access.php`: Updated snippet to not attempt to protect the post when editing via the Block Editor. --- gravity-forms/gw-submit-to-access.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gravity-forms/gw-submit-to-access.php b/gravity-forms/gw-submit-to-access.php index 3aa4605f7..c70293e87 100644 --- a/gravity-forms/gw-submit-to-access.php +++ b/gravity-forms/gw-submit-to-access.php @@ -320,6 +320,16 @@ public function has_submitted_form( $form_ids, $per_page, $post_id ) { } public function requires_access( $post_id ) { + + // Never require access for edit API requests. Interferes with the Block Editor. + if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { + $route = untrailingslashit( $GLOBALS['wp']->query_vars['rest_route'] ) ?: '/'; + $request = new WP_REST_Request( $_SERVER['REQUEST_METHOD'], $route ); + if ( $request->get_method() !== 'GET' || ( $request['context'] === 'edit' && current_user_can( 'edit_post', $post_id ) ) ) { + return false; + } + } + return get_post_meta( $post_id, 'gwsa_require_submission', true ) == true; }