From 9da26c12b923670961fb911e50e5d441abf8b2ed Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Tue, 13 Feb 2024 15:42:46 -0700 Subject: [PATCH 1/2] - update settings page to provide more clarity on the settings and improve hierarchy --- src/Admin/Settings.php | 64 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/src/Admin/Settings.php b/src/Admin/Settings.php index 1a406d1..e85de17 100644 --- a/src/Admin/Settings.php +++ b/src/Admin/Settings.php @@ -193,18 +193,22 @@ function () { 'graphql_cache_section', [ 'title' => __( 'Cache', 'wp-graphql-smart-cache' ), - 'desc' => __( 'Caching and other settings related to improved performance of GraphQL queries.', 'wp-graphql-smart-cache' ), ] ); register_graphql_settings_field( 'graphql_cache_section', [ - 'name' => 'log_purge_events', - 'label' => __( 'Log Purge Events', 'wp-graphql-smart-cache' ), - 'desc' => __( 'Enabling this option will log purge events to the error log. This can be helpful when debugging what events are leading to specific purge events.', 'wp-graphql-smart-cache' ), - 'type' => 'checkbox', - 'default' => 'off', + 'name' => 'network_cache_notice', + 'type' => 'custom', + 'callback' => static function( array $args ) { + echo ' +

' . esc_html( __( 'Network Cache Settings', 'wp-graphql-smart-cache' ) ) . '

+

' . esc_html( __( 'Below are settings that will modify behavior of the headers used by network cache clients such as varnish.', 'wp-graphql-smart-cache' ) ). '

+

' . esc_html( __( 'Our recommendation is to use HTTP GET requests for queries and take advantage of the network cache (varnish, etc) and only enable and use Object Cache if GET requests are, for some reason, not an option.', 'wp-graphql-smart-cache' ) ). '

+ + '; + }, ] ); @@ -213,7 +217,7 @@ function () { [ 'name' => 'global_max_age', 'label' => __( 'Cache-Control max-age', 'wp-graphql-smart-cache' ), - 'desc' => __( 'If set, a Cache-Control header with max-age directive will be set for all GraphQL responses. Value should be an integer, greater or equal to zero, or blank to disable. A value of 0 indicates that requests should not be cached (use with caution).', 'wp-graphql-smart-cache' ), + 'desc' => __( 'Value, in seconds. (i.e. 600 = 10 minutes) If set, a Cache-Control header with max-age directive will be added to the responses GraphQL queries made by via non-authenticated HTTP GET request. Value should be an integer, greater or equal to zero. A value of 0 indicates that requests should not be cached (use with caution).', 'wp-graphql-smart-cache' ), 'type' => 'number', 'sanitize_callback' => function ( $value ) { if ( ! is_numeric( $value ) ) { @@ -229,6 +233,23 @@ function () { ] ); + register_graphql_settings_field( + 'graphql_cache_section', + [ + 'name' => 'object_cache_notice', + 'type' => 'custom', + 'callback' => static function( array $args ) { + echo ' +
+

' . esc_html( __( 'Object Cache Settings', 'wp-graphql-smart-cache' ) ) . '

+

' . esc_html( __( 'Below are settings that will impact object cache behavior.', 'wp-graphql-smart-cache' ) ). '

+

' . esc_html( __( 'NOTE', 'wp-graphql-smart-cache' ) ) . ': ' . esc_html( __( 'GraphQL Object Cache is only recommended if network cache cannot be used. When possible, we recommend using HTTP GET requests and network caching layers such as varnish.', 'wp-graphql-smart-cache' ) ). '

+ + '; + }, + ] + ); + register_graphql_settings_field( 'graphql_cache_section', [ @@ -257,12 +278,39 @@ function () { ] ); + register_graphql_settings_field( + 'graphql_cache_section', + [ + 'name' => 'debugging_notice', + 'type' => 'custom', + 'callback' => static function( array $args ) { + echo ' +
+

' . esc_html( __( 'Debugging', 'wp-graphql-smart-cache' ) ) . '

+

' . esc_html( __( 'Below are settings you can use to help debug', 'wp-graphql-smart-cache' ) ). '

+ + '; + }, + ] + ); + + register_graphql_settings_field( + 'graphql_cache_section', + [ + 'name' => 'log_purge_events', + 'label' => __( 'Log Purge Events', 'wp-graphql-smart-cache' ), + 'desc' => __( 'Enabling this option will log purge events to the error log. This can be helpful when debugging what events are leading to specific purge events.', 'wp-graphql-smart-cache' ), + 'type' => 'checkbox', + 'default' => 'off', + ] + ); + register_graphql_settings_field( 'graphql_cache_section', [ 'name' => 'purge_all', 'label' => __( 'Purge Now!', 'wp-graphql-smart-cache' ), - 'desc' => __( 'Purge GraphQL Cache. Select this box and click the save button to purge all responses stored in the GraphQL Cache.', 'wp-graphql-smart-cache' ), + 'desc' => __( 'Purge GraphQL Cache. Select this box and click the save button to purge all responses stored in the GraphQL Cache. This should purge network caches and object caches (if enabled) for GraphQL Queries.', 'wp-graphql-smart-cache' ), 'type' => 'checkbox', 'default' => 'off', 'sanitize_callback' => function ( $value ) { From 0799813d3f40912c2e6a8a394b79a49dd82d3aaf Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 14 Feb 2024 09:29:42 -0700 Subject: [PATCH 2/2] - composer fix-cs --- src/Admin/Settings.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Admin/Settings.php b/src/Admin/Settings.php index e85de17..1302b2e 100644 --- a/src/Admin/Settings.php +++ b/src/Admin/Settings.php @@ -199,13 +199,13 @@ function () { register_graphql_settings_field( 'graphql_cache_section', [ - 'name' => 'network_cache_notice', - 'type' => 'custom', - 'callback' => static function( array $args ) { + 'name' => 'network_cache_notice', + 'type' => 'custom', + 'callback' => static function ( array $args ) { echo '

' . esc_html( __( 'Network Cache Settings', 'wp-graphql-smart-cache' ) ) . '

-

' . esc_html( __( 'Below are settings that will modify behavior of the headers used by network cache clients such as varnish.', 'wp-graphql-smart-cache' ) ). '

-

' . esc_html( __( 'Our recommendation is to use HTTP GET requests for queries and take advantage of the network cache (varnish, etc) and only enable and use Object Cache if GET requests are, for some reason, not an option.', 'wp-graphql-smart-cache' ) ). '

+

' . esc_html( __( 'Below are settings that will modify behavior of the headers used by network cache clients such as varnish.', 'wp-graphql-smart-cache' ) ) . '

+

' . esc_html( __( 'Our recommendation is to use HTTP GET requests for queries and take advantage of the network cache (varnish, etc) and only enable and use Object Cache if GET requests are, for some reason, not an option.', 'wp-graphql-smart-cache' ) ) . '

'; }, @@ -236,14 +236,14 @@ function () { register_graphql_settings_field( 'graphql_cache_section', [ - 'name' => 'object_cache_notice', - 'type' => 'custom', - 'callback' => static function( array $args ) { + 'name' => 'object_cache_notice', + 'type' => 'custom', + 'callback' => static function ( array $args ) { echo '

' . esc_html( __( 'Object Cache Settings', 'wp-graphql-smart-cache' ) ) . '

-

' . esc_html( __( 'Below are settings that will impact object cache behavior.', 'wp-graphql-smart-cache' ) ). '

-

' . esc_html( __( 'NOTE', 'wp-graphql-smart-cache' ) ) . ': ' . esc_html( __( 'GraphQL Object Cache is only recommended if network cache cannot be used. When possible, we recommend using HTTP GET requests and network caching layers such as varnish.', 'wp-graphql-smart-cache' ) ). '

+

' . esc_html( __( 'Below are settings that will impact object cache behavior.', 'wp-graphql-smart-cache' ) ) . '

+

' . esc_html( __( 'NOTE', 'wp-graphql-smart-cache' ) ) . ': ' . esc_html( __( 'GraphQL Object Cache is only recommended if network cache cannot be used. When possible, we recommend using HTTP GET requests and network caching layers such as varnish.', 'wp-graphql-smart-cache' ) ) . '

'; }, @@ -281,13 +281,13 @@ function () { register_graphql_settings_field( 'graphql_cache_section', [ - 'name' => 'debugging_notice', - 'type' => 'custom', - 'callback' => static function( array $args ) { + 'name' => 'debugging_notice', + 'type' => 'custom', + 'callback' => static function ( array $args ) { echo '

' . esc_html( __( 'Debugging', 'wp-graphql-smart-cache' ) ) . '

-

' . esc_html( __( 'Below are settings you can use to help debug', 'wp-graphql-smart-cache' ) ). '

+

' . esc_html( __( 'Below are settings you can use to help debug', 'wp-graphql-smart-cache' ) ) . '

'; },