botoxparty
Forum Replies Created
-
Forum: Plugins
In reply to: [JWT Authentication for WP REST API] Feature Request: get_current_user_id@mullibahr Nice one! Thanks!
Forum: Plugins
In reply to: [JWT Authentication for WP REST API] Conflict with JWT and CookiesI would even recommend adding this to the plugin.
e.g.
function get_current_user_id() { if (class_exists('Jwt_Auth_Public')) { $jwt = new \Jwt_Auth_Public('jwt-auth', '1.1.0'); $token = $jwt->validate_token(false); if (\is_wp_error($token)) { return false; } return $token->data->user->id; } else { return false; } }
Forum: Plugins
In reply to: [WP REST Cache] Manually flush cacheSorry thought I replied to this.
Number 2 sounds like a more flexible option, I can see this being used for more than just authentication purposes. e.g. Do not cache based on an environment variable.
Forum: Plugins
In reply to: [WP REST Cache] Manually flush cacheThanks for the update! It works great, definitely fixed the issue I was having before with detecting object type and throwing an error.
I think I want to cache the endpoint, this is my use case:
I have a product catalogue that is cached. Admin users can see ‘draft’ and ‘private’ status products, whereas Customers can only see ‘publish’ products. So the cached responses won’t actually return what an admin should see, and if an admin sets the cached response then it will show ‘draft’ and ‘private’ products to customers.
I guess I could create an endpoint specifically for admin users to access the catalogue.
Let me know your thoughts.
Forum: Plugins
In reply to: [WP REST Cache] Manually flush cacheNo problem, the information you’ve provided is plenty for my solution.
I have some endpoints that check authentication inside them, I would like a way to make sure any authenticated requests by admins are not cached. Any ideas on how to approach this?
Forum: Plugins
In reply to: [WP REST Cache] Caching endpoints with query paramsAlso what is the ‘Item API Caches’?
Forum: Plugins
In reply to: [WP REST Cache] Manually flush cacheOkay cool I can use those functions that’s great. Converting the endpoint path to md5 isn’t a problem seems to be matching here from a quick test.
Those use cases you describe is basically what i’m looking to achieve.
– Flushing all caches for an endpoint regardless of query params
– Flushing cache by specific path/endpointWould be a good place to start.
Forum: Plugins
In reply to: [WP REST Cache] Caching endpoints with query paramsAh okay! I see!
So yep I got this working with one of my custom endpoints which returns a single page.
Looking at this function:
private function determine_object_type( $data ) { if ( array_key_exists( 'id', $data['data'] ) ) { $this->is_single = true; if ( array_key_exists( 'type', $data['data'] ) ) { return $data['data']['type']; } else if ( array_key_exists( 'taxonomy', $data['data'] ) ) { return $data['data']['taxonomy']; } } else { $this->is_single = false; if ( count( $data['data'] ) && isset( $data['data'][0] ) ) { if ( array_key_exists( 'type', $data['data'][0] ) ) { return $data['data'][0]['type']; } else if ( array_key_exists( 'taxonomy', $data['data'][0] ) ) { return $data['data'][0]['taxonomy']; } } } return 'unknown'; }
I made sure I put the page ID in ‘id’, and the ‘type’ in type. This worked successfully when updating the page and clearing the cache.
Forum: Plugins
In reply to: [TI WooCommerce Wishlist] API for WooCommerce Wishlist PluginIf anyone is looking to do you can contact me at [email protected]
Forum: Plugins
In reply to: [WP REST Cache] Caching endpoints with query paramsOkay so i went to the line of the error and realised it was related to checking the Object Type.
Considering this doesn’t really affect the way it works i’ve just added this piece of code in for now above that line.
if(gettype($data['data']) === 'object') { return "Object"; }
- This reply was modified 5 years, 8 months ago by botoxparty.
Forum: Plugins
In reply to: [WP REST Cache] Caching endpoints with query paramsHmm that is how I have it setup. However on some endpoints i get the following on the first request:
<br /> <b>Fatal error</b>: Uncaught Error: Cannot use object of type stdClass as array in /Users/xxxxxxxx/Projects/xxxxxxxx/wp-content/plugins/wp-rest-cache/includes/caching/class-caching.php:714 Stack trace: #0 /Users/xxxxxxxx/Projects/xxxxxxxx/wp-content/plugins/wp-rest-cache/includes/caching/class-caching.php(591): WP_Rest_Cache_Plugin\Includes\Caching\Caching->determine_object_type(Array) #1 /Users/xxxxxxxx/Projects/xxxxxxxx/wp-content/plugins/wp-rest-cache/includes/caching/class-caching.php(130): WP_Rest_Cache_Plugin\Includes\Caching\Caching->register_endpoint_cache('c91289d1c66027e...', Array, '/wp-json/abode/...') #2 /Users/xxxxxxxx/Projects/xxxxxxxx/wp-content/plugins/wp-rest-cache/includes/api/class-endpoint-api.php(153): WP_Rest_Cache_Plugin\Includes\Caching\Caching->set_cache('c91289d1c66027e...', Array, 'endpoint', '/wp-json/abode/...') #3 /Users/xxxxxxxx/Projects/xxxxxxxx/wp-includes/class-wp-hook.php(286): WP_Rest_Cache_Plugin\Includes\API\Endpoint_Api->save_cache(Object(stdClass), Objec in <b>/Users/xxxxxxx/Projects/xxxxxxx/wp-content/plugins/wp-rest-cache/includes/caching/class-caching.php</b> on line <b>714</b><br />
Then i get a cached response after that. However the cache doesn’t appear in Settings > WP REST Cache.
Other endpoints that don’t produce this error do get cached and appear in the settings.
Any ideas on how to debug this?
Forum: Plugins
In reply to: [WP REST Cache] Manually flush cacheHey @acato
Is there any way to do this programatically?
Forum: Plugins
In reply to: [XML Sitemap Generator for Google] force rebuild of sitemapAlso looking to do this…
Forum: Plugins
In reply to: [JWT Authentication for WP REST API] Conflict with JWT and CookiesOkay I worked it out, thanks Martin.
Incase anyone else is looking for this solution, I was previously using wp_get_current_user to check if I was logged in, I replaced this with the function above.
Cheers
Forum: Plugins
In reply to: [JWT Authentication for WP REST API] Conflict with JWT and CookiesWhat do you mean by your
controller's permissions check
?Is this part of WP Core, or part of this plugin?
Sorry don’t have a deep knowledge of how WP authenticates requests, which file did you edit?