Skip to content

Commit

Permalink
Merge pull request #2 from Enterwell/bugfix/unused-function
Browse files Browse the repository at this point in the history
Removed is_nonce_valid function
  • Loading branch information
fmarencic authored Nov 23, 2022
2 parents 814b3d9 + fa1ce38 commit c1278b5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 34 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"email": "[email protected]"
}
],
"version": "1.0.0",
"version": "1.1.0",
"license": "MIT",
"description": "Helper classes for WordPress custom development.",
"autoload": {
Expand Down
33 changes: 0 additions & 33 deletions src/Controllers/AController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,6 @@ public abstract function register_routes();

#region Permission callback helpers

/**
* Check if request nonce is valid.
* Mostly used in register_routes function as
* permissions callback.
* @since 1.0.0
*
* @param \WP_REST_Request $request
*
* @return bool
*/
public function is_nonce_valid( $request ) {
// Logged in users does not have to send nonces
if ( $this->is_user_logged_in() ) {
return true;
}

// Get nonce from headera
$nonce = $request->get_header( 'X-WP-Nonce' );

// If there is no nonce in headers
// look for it in request body
if ( empty( $nonce ) ) {
// Get request params
$params = $request->get_params();

if ( ! empty( $params['_wpnonce'] ) ) {
$nonce = $params['_wpnonce'];
}
}

return wp_verify_nonce( $nonce, 'wp_rest' );
}

/**
* Checks if user is logged in.
* Mostly used in register_routes function as
Expand Down

0 comments on commit c1278b5

Please sign in to comment.