Essentially, you shouldn’t wrap your REST route declarations inside is_admin() since WordPress will not load them (see @DarkNueron comment).
What you can do is pass a ‘permission_callback’ function to the register_rest_route
function. If the function returns true, the request is allowed to continue; if false, an error is returned.
So you could do:
register_rest_route('your-namespace/v1', '/options/', [
'methods' => 'PATCH',
'callback' => [__CLASS__, 'update_option'],
'permission_callback' => function () {
return current_user_can('manage_options');
}
]);
Related Posts:
- How do I Enqueue styles/scripts on Certain /wp-admin Pages?
- Changing Admin Menu Labels
- Is there ANY way to remove comments function and section totally?
- Add “external” link to admin menu in the backend
- How to add custom submenu links in wp-admin menus?
- How to allow users login to WP from external domain and make REST requests
- Edit specific nodes in WP_Admin_Bar
- How to add notification bubble for my custom admin menu page
- How to create sub menu with a URL parameter?
- Adding a menu item in the admin bar
- How to remove items from +New admin menu?
- Reorder custom submenu item
- Make sub menu items a main link in the admin menu using fuctions.php
- Add column to pages table
- Admin account only shows Profile and Dashboard with no activity
- How to wrap admin menus and menu headers in additional divs without modifying the WordPress core?
- How to disable admin flyout menus?
- remove plugin admin menu in wordpress without installing plugin in v3.8.1
- How to prevent parent admin page from appearring as a child admin page
- Rename W3 Total Cache admin menu
- Remove query var on admin pages when ‘Save changes’ pressed
- Create a admin page in wordpress without admin menus (“wordpress sidebars”)
- Remove All in One Pack from the admin bar
- Cannot find an OLD Gravity Form on an OLD Word Press site [closed]
- Add column to pages table
- Add menu option to “New Post” menu in admin bar
- Admin menu in front-end
- Remove or move admin submenus under a new menu
- How to get specific page screen ID
- Removing Dashboard Menu Items Through The Database
- WordPress Side Menu Admin Panel Default Order numbers List?
- load-{$page hook} and returned parameter
- Hide admin menu on update_option
- meta box on new admin page
- How to hide Admin Tabs? [duplicate]
- Making Comments, a sub_menu in admin menu
- Admin top level menu, pointing to an external url
- How to break line / add to ADMIN menu
- User Capabilities are not available in WP REST permission callback?
- Creating custom admin panel pages without making a plugin?
- Change users.php WP_User_Query
- How can I control which plugins run in the dashboard?
- how to stop wordpress admin menu from scrolling with page
- Trying to create a page as a menu item in the admin while keeping the admen panel visible
- Custom admin menu order fails if slugs are complicated
- WordPress Admin Panel Left Sidebar No showing on Post create page
- Weird white space in admin area
- Redirect from wp-admin back to page
- How to move “Collapse Menu” to top of admin bar?
- Appearance -> Menus doesn’t show
- restrict admin panel sections to users
- Remove menu item dashboard for a unique user
- How to display status messages in admin panel
- adding existing menu page on new customer user role
- Can I get programmatic access to wp-admin?
- Disable flyout (popup) menus in backend
- Remove Theme menu link from Admin Panel
- Remove capability to interact with a page
- Redirection to external site on admin
- Move Custom Taxonomy Menu to Top Level Admin Menu
- get_current_screen() does not return parent_file
- Organizing Code in your WordPress Theme's functions.php File?
- How to check if a user is in a specific role?
- Create WP tutorial for users with admin pointer using next button for navigation
- Pre-fill fields with content from outside when creating a new post
- Why are admin scripts not printed
- White screen of death only in wp-admin
- wp-admin remove the subfolder URL
- Removing admin bar from wordpress dashboard
- How to control contextual help section by code?
- Can’t access wp-admin Internal Server Error 500
- Add custom text to Page Tamplate without need to know html
- Move WP Admin Bar
- Deprecated : contextual_help has been deprecated since version 3.3.0
- How get Themes list via REST api?
- Custom Background-Image not showing up
- How to hide wordpress default description box?
- cannot find the login page for local WordPress site
- In editor-style.css how can I change background color of title field?
- how to customize wp-admin page using child theme
- Possibilities for the edit.php admin panel? [closed]
- new subdomain to apply as main domain
- Blank page for wp-admin after i uploaded the website from my localhost to the live server
- Develop Admin Panel Page
- firing function at login within class
- WordPress admin page not found error
- Use of domain name
- Where is function to prevents non logged users access wp-admin?
- Registering for a domain on WordPress
- Why wp redirects me to wp-login.php when I visit a rewritten wp-admin URL?
- DISALLOW_FILE_EDIT is false but I still am not able to edit files from the admin interface and the menus do not show up
- Updated MAMP and localhost on MacOS site no longer accessible
- Function to get a ‘post selector’ UI?
- CSRF attack to create USER
- Changing headers for an export from within a PHP class extension
- When installing wordpress through WP CLI mysite.com/admin not working
- How do I change the WordPress Address URL only and still login to wp-admin
- wordpress wp-admin showing white screen with no error
- Undeletable posts, users or other content
- Couple questions about .htaccess, login page, updates