Skip to content

Commit

Permalink
- Add access functions for GraphQL Settings fields/sections
Browse files Browse the repository at this point in the history
- register_graphql_settings_section
- register_graphql_settings_field
- register_graphql_settings_fields
- get_graphql_setting
- Add deactivation function to cleanup WPGraphQL settings when WPGraphQL is de-activated
- Change plugin name from WP GraphQL to WPGraphQL
- remove the `graphql_insights_init` action so that users using WPGraphQL Insights don't have conflicts with the built in Query Logs and Tracing
- initialize GraphQL Tracing and Query Logging when WPGraphQL boots up
- initialize Admin pages
- add new WPGraphQL::debug() method to determine if debug mode is enabled
- Use the new WPGraphQL::debug() method on request execution to determine if requests should execute in debug mode
- Update the endpoint on the Router to use the new endpoint setting, allowing users to override the endpoint from the settings page
- Add new Admin class to facilitate bootstrapping Admin pages in the WordPress dashboard
- Add new Extensions class to facilitate adding an Extensions page to the Admin
- Bring WPGraphiQL into the core WPGraphQL plugin
- Adds new Settings class to facilitate registering admin settings
- Adds new SettingsRegistry class to facilitate registering settings sections, fields, and displaying their HTML
- Brings the functionality for Query Logging and Tracing into the core WPGraphQL plugin so that WPGraphQL Insights is no longer needed
  • Loading branch information
jasonbahl committed Sep 16, 2020
1 parent fb4e3b8 commit 92a1b16
Show file tree
Hide file tree
Showing 30 changed files with 9,648 additions and 17 deletions.
61 changes: 61 additions & 0 deletions access-functions.php
Expand Up @@ -315,6 +315,67 @@ function is_graphql_http_request() {
return \WPGraphQL\Router::is_graphql_http_request();
}

/**
* Registers a GraphQL Settings Section
*
* @param string $slug The slug of the group being registered
* @param array $config Array configuring the section. Should include: title
*
* @return void
*/
function register_graphql_settings_section( $slug, $config ) {
add_action( 'graphql_init_settings', function( \WPGraphQL\Admin\Settings\SettingsRegistry $registry ) use ( $slug, $config ) {
$registry->register_section( $slug, $config );
} );
}

/**
* Registers a GraphQL Settings Field
*
* @param string $group The name of the group to register a setting field to
* @param array $config The config for the settings field being registered
*
* @return void
*/
function register_graphql_settings_field( $group, $config ) {
add_action( 'graphql_init_settings', function( \WPGraphQL\Admin\Settings\SettingsRegistry $registry ) use ( $group, $config ) {
$registry->register_field( $group, $config );
} );
}

/**
* Registers a series of GraphQL Settings Fields
*
* @param string $group The name of the settings group to register fields to
* @param array $fields Array of field configs to register to the group
*
* @return void
*/
function register_graphql_settings_fields( $group, $fields ) {
add_action( 'graphql_init_settings', function( \WPGraphQL\Admin\Settings\SettingsRegistry $registry ) use ( $group, $fields ) {
$registry->register_fields( $group, $fields );
} );
}

/**
* Get an option value from GraphQL settings
*
* @param string $option The key of the option to return
* @param mixed $default The default value the setting should return if no value is set
* @param string $section The settings group section that the option belongs to
*
* @return mixed|string|int|boolean
*/
function get_graphql_setting( $option, $default = '', $section = 'graphql_general_settings' ) {
$options = get_option( $section );

if ( isset( $options[ $option ] ) ) {
return $options[ $option ];
}

return $default;
}

/**
* Polyfill for PHP versions below 7.3
*
Expand Down

0 comments on commit 92a1b16

Please sign in to comment.