woocommerce_graphql_can_query_metadata
Filters whether the current principal may run the _apiMetadata query.
The filter receives the principal-derived decision (see the tri-tier ladder in MetadataController::can_query_metadata()) and must return strictly true to grant access; any other return value denies. The filter is not invoked when principal resolution failed (i.e. when the resolver receives a null principal) — that case denies outright.
Usage
add_filter( 'woocommerce_graphql_can_query_metadata', 'wp_kama_woocommerce_graphql_can_query_metadata_filter', 10, 2 );
/**
* Function for `woocommerce_graphql_can_query_metadata` filter-hook.
*
* @param bool $allowed Whether the principal may query `_apiMetadata`.
* @param object $principal The resolved principal.
*
* @return bool
*/
function wp_kama_woocommerce_graphql_can_query_metadata_filter( $allowed, $principal ){
// filter...
return $allowed;
}
- $allowed(true|false)
- Whether the principal may query
_apiMetadata. - $principal(object)
- The resolved principal.
Changelog
| Since 10.9.0 | Introduced. |
Where the hook is called
woocommerce_graphql_can_query_metadata
woocommerce/src/Api/Infrastructure/MetadataController.php 221
$allowed = apply_filters( 'woocommerce_graphql_can_query_metadata', $allowed, $principal );