Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #21 from wp-graphql/feature/#20-expose-for-graphql…
Browse files Browse the repository at this point in the history
…-debug-or-manage-options

#20 - Limit insights to GRAPHQL_DEBUG or current_user_can( 'manage_options' )
  • Loading branch information
jasonbahl authored May 29, 2019
2 parents 45763a5 + 2831eeb commit f2428eb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions wp-graphql-insights.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,42 @@ public function return_tracing_headers( $headers ) {
*/
function graphql_insights_init() {

/**
* Default $graphql_insights_active to false.
*/
$graphql_insights_active = false;

/**
* Default capability to activate insights for.
*
* @param string $capability Capability to show
*/
$graphql_insights_default_capability = apply_filters( 'graphql_insights_default_capability', 'manage_options' );

/**
* If GRAPQHL_DEBUG is enabled or the request is authenticated by a user with , enable Insights
*/
if ( defined( 'GRAPQHL_DEBUG' ) && true === GRAPHQL_DEBUG || current_user_can( $graphql_insights_default_capability ) ) {
$graphql_insights_active = true;
}

/**
* Filter whether insights is active, allowing finer control over when to activate insights.
*
* Default is to activate when GRAPHQL_DEBUG is true or authenticated requests
*
* @param boolean $graphql_insights_active Whether insights should be enabled for a request
*
*/
$graphql_insights_active = apply_filters( 'graphql_insights_active', $graphql_insights_active );

/**
* If $graphql_insights_active is not true, return now before instantiating insights
*/
if ( true !== $graphql_insights_active ) {
return false;
}

/**
* If SAVEQUERIES hasn't already been defined, define it now
*/
Expand Down

0 comments on commit f2428eb

Please sign in to comment.