Skip to content

Commit

Permalink
Properly authenticate the AJAX request
Browse files Browse the repository at this point in the history
  • Loading branch information
jdevalk committed Apr 25, 2024
1 parent 7df41cb commit b307ec8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion js/admin-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ jQuery( document ).ready(
{
pageLength: 25,
ajax: {
url: aaaOptionOptimizer.root + 'aaa-option-optimizer/v1/all-options/',
url: aaaOptionOptimizer.root + 'aaa-option-optimizer/v1/all-options',
headers: { 'X-WP-Nonce': aaaOptionOptimizer.nonce },
type: 'GET',
dataSrc: 'data',
},
Expand Down
4 changes: 2 additions & 2 deletions src/class-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public function register_rest_routes() {

\register_rest_route(
'aaa-option-optimizer/v1',
'/all-options/',
'/all-options',
[
'methods' => 'GET',
'callback' => [ $this, 'get_all_options' ],
'permission_callback' => function () {
return true;
return current_user_can( 'manage_options' );
},
]
);
Expand Down

0 comments on commit b307ec8

Please sign in to comment.