Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created June 30, 2019 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/8e2a228fc240ef691185f66cb54c9dec to your computer and use it in GitHub Desktop.
Save damiencarbery/8e2a228fc240ef691185f66cb54c9dec to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Disable WooCommerce REST API authentication
Plugin URI: https://www.damiencarbery.com/2019/07/disable-woocommerce-rest-api-authentication/
Description: Override WooCommerce capability check so that all REST API queries are allowed.
Author: Damien Carbery
Version: 0.1
*/
add_filter( 'woocommerce_rest_check_permissions', 'dcwd_allow_rest_api_queries', 10, 4 );
function dcwd_allow_rest_api_queries( $permission, $context, $zero, $object ) {
// Optionally limit permitted queries to different contexts.
/*if ( 'read' != $context ) {
return $permission;
}*/
// Write the parameters to the error log (or debug.log file) to see what requests are being accessed.
//error_log( sprintf( 'Permission: %s, Context: %s; Object: %s', var_export( $permission, true ), $context, var_export( $object, true ) ) );
return true; // Allow all queries.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment