usefulteam / jwt-auth

WordPress JSON Web Token Authentication
https://wordpress.org/plugins/jwt-auth/
122 stars 48 forks source link

Contact form 7 not working when JWT is active #31

Open y4ahmad opened 3 years ago

y4ahmad commented 3 years ago

When submitting a contact form I get an error in the console when I deactivate the plugin it starts working again I tried uninstalling and reinstalling the actual plugin functionality is working fine I am able to login using the API has anyone else had the same problem? I have left the Plugin activated if you need more info on the error just submit the form at the bottom of the home page https://chocolatebash.com/careers/

Uncaught TypeError: Cannot read property ‘replace’ of undefined

Gandhi11 commented 3 years ago

@y4ahmad I had the same problem and needed to whitelist the /wp-json/contact-form-7/* endpoint.

contactjavas commented 2 years ago

Thanks for helping @Gandhi11 :) Have you tried it @y4ahmad?

MOTY12 commented 5 months ago

@y4ahmad I had the same problem and needed to whitelist the /wp-json/contact-form-7/* endpoint.

how will I whitelist the contact form can you explain?

seqnetworks commented 5 months ago

Yo can try below code to whitelist the contact form 7 api request.

add_filter('jwt_auth_default_whitelist', 'custom_jwt_auth_default_whitelist', 10, 1); function custom_jwt_auth_default_whitelist($whitelist) { $rest_api_slug = home_url('/wp-json', 'relative'); $whitelist[] = $rest_api_slug . '/contact-form-7/'; return $whitelist; }

MOTY12 commented 5 months ago

/wp-json/contact-form-7/*

is it on the functions.php file i will put it on the theme

pesseba commented 5 months ago

/wp-json/contact-form-7/*

is it on the functions.php file i will put it on the theme

Try to put the code in a plugin. If you use the code in theme funcitons.php, it only runs in front-end calls. The rest-api could be called without front-end.

MOTY12 commented 5 months ago

/wp-json/contact-form-7/*

is it on the functions.php file i will put it on the theme

Try to put the code in a plugin. If you use the code in theme funcitons.php, it only runs in front-end calls. The rest-api could be called without front-end.

Do you mean i should create a file on the contact form plugin and just add it there. Because i want to understand the process before i do it

pesseba commented 5 months ago

@MOTY12 you must write your own plugin to add this code, that's simple. If you use the functions.php it only works in fron-end, but if you use a plugin, it will run in admin and rest-api calls too. The example below will add all contact-form-7 calls in whitelist, because de '*':

<?php
/*
Plugin Name: My Simple Plugin
Description: This is a simple plugin for WordPress.
Version: 1.0
Author: Your Name
*/
function custom_jwt_auth_default_whitelist($endpoints) {
     array_push($endpoints,'/wp-json/contact-form-7/v1/*');
     return $endpoints;
}
add_filter('jwt_auth_default_whitelist', 'custom_jwt_auth_default_whitelist', 10, 1);