Title: botoxparty's Replies | WordPress.org

---

# botoxparty

  [  ](https://wordpress.org/support/users/adamhammad/)

 *   [Profile](https://wordpress.org/support/users/adamhammad/)
 *   [Topics Started](https://wordpress.org/support/users/adamhammad/topics/)
 *   [Replies Created](https://wordpress.org/support/users/adamhammad/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/adamhammad/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/adamhammad/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/adamhammad/engagements/)
 *   [Favorites](https://wordpress.org/support/users/adamhammad/favorites/)

 Search replies:

## Forum Replies Created

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/users/adamhammad/replies/page/2/?output_format=md)
[→](https://wordpress.org/support/users/adamhammad/replies/page/2/?output_format=md)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[JWT Authentication for WP REST API] Feature Request: get_current_user_id](https://wordpress.org/support/topic/feature-request-get_current_user_id/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/feature-request-get_current_user_id/#post-11441937)
 * [@mullibahr](https://wordpress.org/support/users/mullibahr/) Nice one! Thanks!
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[JWT Authentication for WP REST API] Conflict with JWT and Cookies](https://wordpress.org/support/topic/conflict-with-jwt-and-cookies/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/conflict-with-jwt-and-cookies/#post-11437155)
 * I 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](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Manually flush cache](https://wordpress.org/support/topic/manually-flush-cache/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11419592)
 * Sorry thought I replied to this.
 * [@acato](https://wordpress.org/support/users/acato/)
 * 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](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Manually flush cache](https://wordpress.org/support/topic/manually-flush-cache/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11401851)
 * Thanks 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](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Manually flush cache](https://wordpress.org/support/topic/manually-flush-cache/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11381522)
 * No 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](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Caching endpoints with query params](https://wordpress.org/support/topic/caching-endpoints-with-query-params/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/caching-endpoints-with-query-params/#post-11364883)
 * Also what is the ‘Item API Caches’?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Manually flush cache](https://wordpress.org/support/topic/manually-flush-cache/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11364746)
 * Okay 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/endpoint
 * Would be a good place to start.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Caching endpoints with query params](https://wordpress.org/support/topic/caching-endpoints-with-query-params/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/caching-endpoints-with-query-params/#post-11364742)
 * Ah 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](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[TI WooCommerce Wishlist] API for WooCommerce Wishlist Plugin](https://wordpress.org/support/topic/api-for-woocommerce-wishlist-plugin/)
 *  [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/api-for-woocommerce-wishlist-plugin/#post-11359945)
 * If anyone is looking to do you can contact me at [adam@adamhammad.com](https://wordpress.org/support/users/adamhammad/replies/adam@adamhammad.com?output_format=md)
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Caching endpoints with query params](https://wordpress.org/support/topic/caching-endpoints-with-query-params/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/caching-endpoints-with-query-params/#post-11359759)
 * Okay 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 7 years, 4 months ago by [botoxparty](https://wordpress.org/support/users/adamhammad/).
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Caching endpoints with query params](https://wordpress.org/support/topic/caching-endpoints-with-query-params/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/caching-endpoints-with-query-params/#post-11359720)
 * Hmm 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](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Manually flush cache](https://wordpress.org/support/topic/manually-flush-cache/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11359706)
 * Hey [@acato](https://wordpress.org/support/users/acato/)
 * Is there any way to do this programatically?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[XML Sitemap Generator for Google] force rebuild of sitemap](https://wordpress.org/support/topic/force-rebuild-of-sitemap/)
 *  [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/force-rebuild-of-sitemap/#post-11301153)
 * Also looking to do this…
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[JWT Authentication for WP REST API] Conflict with JWT and Cookies](https://wordpress.org/support/topic/conflict-with-jwt-and-cookies/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/conflict-with-jwt-and-cookies/#post-11270597)
 * Okay 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](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[JWT Authentication for WP REST API] Conflict with JWT and Cookies](https://wordpress.org/support/topic/conflict-with-jwt-and-cookies/)
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/conflict-with-jwt-and-cookies/#post-11252871)
 * What 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?

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/users/adamhammad/replies/page/2/?output_format=md)
[→](https://wordpress.org/support/users/adamhammad/replies/page/2/?output_format=md)