Skip to content

Commit

Permalink
gw-submit-to-access.php: Updated snippet to not attempt to protect …
Browse files Browse the repository at this point in the history
…the post when editing via the Block Editor.
  • Loading branch information
spivurno committed Nov 9, 2023
1 parent 962ac87 commit 9e6142c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gravity-forms/gw-submit-to-access.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ?: '/';

Check failure on line 326 in gravity-forms/gw-submit-to-access.php

View workflow job for this annotation

GitHub Actions / PHPCS

Using short ternaries is not allowed
$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;
}

Expand Down

0 comments on commit 9e6142c

Please sign in to comment.