Comments (6)
Hey @hadi-aj
I don't fully understand what you mean that CoCart does not define REST_REQUEST
. Are you saying that simply registering the API controllers for CoCart is not enough? Please explain if you can.
I've had a mix of feedback with this plugin where it works and does not. Mostly due to not setting up authentication headers to be approved.
I think I might be dropping support for this plugin as I have my own JWT plugin specifically for CoCart. Last CoCart update v3.8.1 was to support it.
But if you can find where REST_REQUEST
is needed to make this JWT plugin work, please push a fix.
Thank you for reporting the issue.
from cocart-third-party.
Hi
WordPress defines this constant in the rest_api_loaded
function in the wp-includes/rest-aapi.php
file, which is implemented when calling pars_request
, and this is also defined in Woocommerce when Rest request. In the this JWT plugin in the determine_current_user
function to identify a Rest request, the existence of this constant is checked and this plugin does not work because it is not defined in Cocart.
I defined this constant in the setup_constants
method in the Cocart
class and the problem was solved, and it also worked for the exam at the .../jwt-auth-by-useful-team/class-cocart-plugin-jwt-auth.php
.
Thank you for your awesome plugin.
from cocart-third-party.
@hadi-aj Yes WordPress defines REST_REQUEST
as true when rest_api_loaded
is called which is why any REST API including custom controllers registered like WooCommerce and CoCart work.
If you define REST_REQUEST when CoCart is setting up constants then WordPress is going to assume your doing a REST API request all the time which will not help you.
I think the issue is not defining again REST_REQUEST
but the priority order JWT needs to change when it is checking the current user via determine_current_user
which is at the default 10
.
WooCommerce hooks at priority 15
and CoCart hooks at priority 16
.
from cocart-third-party.
Yes you are right. We should not define REST_REQUEST
manualy.
After about 10 hours debugging, I think I found the problem, in the CoCart_REST_API
class wc_load_cart()
is called in the maybe_load_cart
method, but the user is not identified due to the lack of REST_REQUEST
(what is checked in the JWT plugin).
I moved this method to the pars_request
hook and the problem was resolved.
add_action( 'parse_request', array( $this, 'maybe_load_cart' ), 0 );
from cocart-third-party.
I already said it's a load order of determine_current_user
. So really it needs unhooking and rehooking later.
from cocart-third-party.
Completely forgot this issue was still open. Just tested the JWT plugin and it works with no changes made where you suggested. Closing for now.
from cocart-third-party.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cocart-third-party.