✨ Solution
I’m not sure this is the most efficient way to use rest_post_dispatch (documentation) for this purpose (maybe overkill but I didn’t found other way).
It works as expected.
add_filter("rest_post_dispatch", "rest_customize_result", 10, 3);
function rest_customize_result(
WP_REST_Response $result,
WP_REST_Server $server,
WP_REST_Request $request
) {
if ( $request->get_route() === "/jwt-auth/v1/token"
&& $result->get_status() === 403 ) {
$data = $result->get_data();
$data["code"] = "jwt_auth_failed";
$data["message"] = __("Invalid Credentials.", "theme");
$result->set_data($data);
}
return $result;
}
Related Posts:
- wp_head filter not executed inside custom class
- Passing a parameter to filter and action functions
- Get a list of all registered actions
- How can I edit post data before it is saved?
- How can I see all the actions attached to an “add_action” hook?
- Where is the best place to use add_filter
- How to only hook on Single.php after content?
- How can I log a user out of WordPress before the page loads?
- Which hook callback has priority if both plugin and theme use the same hook?
- How to list the Hooks and order of execution in current loading page? [duplicate]
- Use external link in the add sub menu
- Very stubborn wp_register_script / add_action vs remove
- How to prepend to the_title for admin-side plugin’s use
- do_action and hook methods
- How to filter content post only on save
- Filter or action hook to insert content on admin pages before tag
- Creating search filter through plugin
- What is the purpose of $merged_filters?
- Reposition Woocommerce Message
- How to remove xmlns on language_attributes()?
- add_query_arg not working
- How to Use Parameters with a Do_Action Function Within PHP Tags
- How do action and filter hooks understand where to look for the core function that we hooked our function to them
- How to stop or remove an action being called inside a function of an extended class
- Automatically add attributes to woocommerce product?
- wordpress plugin is not activating from widget
- How to get the element ID from new menu list that added with add_filter()?
- How to check current user before all actions and filters?
- Get Time Taken By Each Action Hook in WordPress
- Removing an action from wp_footer called in a class that’s inside a bigger class
- Plugin developer automated documentation
- Is there a hook to Intercept al urls from a webpage and redirect to a page
- WordPress user account activation
- External Script Using WP – Hooks / Actions Not Working?
- Redirect to another page using contact form 7? [closed]
- What is @Action in WordPress?
- Is there a way to figure out which action/filter invoked a function?
- How passing values to construct function with Actions?
- add_action into another add_action not working
- Using add_action before add_filter on a plugin?
- Check if variable is set in filter
- remove_action not removing add_action from constructor
- Basic function call on init failing
- Editing wp-config.php
- Are there action hooks for comments?
- Change text string in a plugin
- WordPress: Add custom add_filter for custom functions
- Override a Plugin Function
- How to use add_action for multiple instances of the same class
- How to hook into action/filter call
- Cannot access empty property error in Advanced Access Manager
- How to append new form elements in “Add New” form of Users in WordPress admin panel?
- Edit post image attributes on fly?
- Use a hook or filter, or overwrite this Gamipress function?
- How to convert Currency from USD to other IP Based currency in Php function
- Redirect to a page while maintaining search query parameters without causing an infinite loop
- Hooking into the HTML header container
- 500 Internal server error wp_handle_upload_prefilter
- How to Unhook actions/filters in within Class in plugin
- Nested Actions and Filters
- Use action, filter, or hook to append HTML to WordPress plugin function
- Get post content inside plugin class method
- Ajax call to php function doesn’t work PHP code
- Remove action added in plugin class from theme
- Show custom taxonomy in theme
- Creating Admin Submenu Page via Class Method
- Help needed with woocommerce (wc stripe) filter
- What action or filter can I use to change all the html returned from server for a page?
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Passing a parameter to filter and action functions
- plugins_loaded action is not working properly
- Plugin Hook: Get posts
- change output location of plugin function using a custom hook
- Filter for modifying image on upload
- Which filters or actions involve with index page for plugin?
- add query string to all pages after user logged in
- Which action/filter can i use for a Member Plugin [closed]
- add_action() not working for admin
- is_singular() in mu-plugins not working
- Add 2 links in between the navigation using the Breadcrumb Navxt plugin hook
- Change Page’s Tag Using functions.php File
- Pass A Value From Outside To A Plugin Variable
- How to Replace Words with Hypertext Link But Ignore Previously Existed Links?
- What are the benefit in adding hook in the init() hook?
- Apple push notification doesn’t work
- Conditional attributes and logic per product category
- Include a php file from another plugin
- How can I fetch data from another website to my wordpress website with mysql database
- Switch from wp-cron to a server cron job
- get_post_meta shortcode returns empty field
- How to get a specific string from a url
- Removing Plugin Action via Theme for Non-admins
- Override filter variable not working
- Creating wordpress admin page panel [Theme Option]
- Why doesn’t a form need an ‘action’ with a plugin that uses the post data?
- Some of my php is rendered only when logged as admin
- Pulling sub-site content into specific pages
- How to create post comparison in wordpress
- How to fix Fatal error: Cannot redeclare get_cli_args() in class-wp-importer.php
- Call to undefined function create_function() – PHP 8.2