Skip to content

Commit 65b531b

Browse files
authored
Merge pull request #423 from wpengine/chore-wpgraphql-snags-sept-2025-iteration-2
chore: WPGraphQL Logging Snags & Automated Tests
2 parents 8e2ef53 + ef373fa commit 65b531b

File tree

57 files changed

+4098
-470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4098
-470
lines changed

.changeset/eight-moons-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wpengine/wpgraphql-logging-wordpress-plugin": patch
3+
---
4+
5+
chore: Fixed some snags for events and event manager. Added and updated PHPUnit tests and coverage now above 90%.

plugins/wpgraphql-logging/src/Admin/Settings/ConfigurationHelper.php

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,16 @@
44

55
namespace WPGraphQL\Logging\Admin\Settings;
66

7+
use WPGraphQL\Logging\Admin\Settings\Fields\Tab\BasicConfigurationTab;
8+
use WPGraphQL\Logging\Admin\Settings\Fields\Tab\DataManagementTab;
9+
710
/**
811
* Configuration Helper class
912
*
1013
* This class provides a centralized and cached way to access WPGraphQL Logging configuration.
1114
* It implements a singleton pattern to ensure configuration is only loaded once per request
1215
* and provides convenient methods for accessing different configuration sections.
1316
*
14-
* Usage Examples:
15-
* ```php
16-
* // Get the helper instance
17-
* $config = ConfigurationHelper::get_instance();
18-
*
19-
* // Get a specific setting
20-
* $log_level = $config->get_setting('basic_configuration', 'log_level', 'info');
21-
*
22-
* // Check if a feature is enabled
23-
* $is_enabled = $config->is_enabled('data_management', 'data_sanitization_enabled');
24-
*
25-
* // Get an entire configuration section
26-
* $basic_config = $config->get_basic_config();
27-
* ```
28-
*
2917
* @package WPGraphQL\Logging
3018
*
3119
* @since 0.0.1
@@ -87,25 +75,25 @@ public function get_config(): array {
8775
* Get configuration for a specific section (tab).
8876
*
8977
* @param string $section The configuration section key.
90-
* @param array<string, mixed> $default_value Default value if section not found.
78+
* @param array<string, mixed> $default_value_value Default value if section not found.
9179
*
9280
* @return array<string, mixed>
9381
*/
94-
public function get_section_config( string $section, array $default_value = [] ): array {
82+
public function get_section_config( string $section, array $default_value_value = [] ): array {
9583
$config = $this->get_config();
96-
return $config[ $section ] ?? $default_value;
84+
return $config[ $section ] ?? $default_value_value;
9785
}
9886

9987
/**
10088
* Get a specific setting value from a configuration section.
10189
*
10290
* @param string $section The configuration section key.
10391
* @param string $setting_key The setting key within the section.
104-
* @param mixed $default_value Default value if setting not found.
92+
* @param mixed $default_value_value Default value if setting not found.
10593
*/
106-
public function get_setting( string $section, string $setting_key, $default_value = null ): mixed {
94+
public function get_setting( string $section, string $setting_key, $default_value_value = null ): mixed {
10795
$section_config = $this->get_section_config( $section );
108-
return $section_config[ $setting_key ] ?? $default_value;
96+
return $section_config[ $setting_key ] ?? $default_value_value;
10997
}
11098

11199
/**
@@ -114,7 +102,7 @@ public function get_setting( string $section, string $setting_key, $default_valu
114102
* @return array<string, mixed>
115103
*/
116104
public function get_basic_config(): array {
117-
return $this->get_section_config( 'basic_configuration' );
105+
return $this->get_section_config( BasicConfigurationTab::get_name() );
118106
}
119107

120108
/**
@@ -123,7 +111,7 @@ public function get_basic_config(): array {
123111
* @return array<string, mixed>
124112
*/
125113
public function get_data_management_config(): array {
126-
return $this->get_section_config( 'data_management' );
114+
return $this->get_section_config( DataManagementTab::get_name() );
127115
}
128116

129117
/**
@@ -147,15 +135,6 @@ public function clear_cache(): void {
147135
wp_cache_delete( $option_key, $this->get_settings_group() );
148136
}
149137

150-
/**
151-
* Reload the configuration from the database.
152-
* This bypasses any cache and forces a fresh load.
153-
*/
154-
public function reload_config(): void {
155-
$this->clear_cache();
156-
$this->load_config();
157-
}
158-
159138
/**
160139
* Get the option key for the settings.
161140
*/
@@ -170,6 +149,18 @@ public function get_settings_group(): string {
170149
return (string) apply_filters( 'wpgraphql_logging_settings_group_settings_group', WPGRAPHQL_LOGGING_SETTINGS_GROUP );
171150
}
172151

152+
/**
153+
* Get the raw option value from the database.
154+
*
155+
* @param string $option_key The option key to retrieve.
156+
* @param mixed $default_value Default value if option not found.
157+
*
158+
* @return array<string, mixed> The option value as an array.
159+
*/
160+
public function get_option_value( string $option_key, mixed $default_value = null ): array {
161+
return (array) get_option( $option_key, $default_value );
162+
}
163+
173164
/**
174165
* Hook into WordPress to clear cache when settings are updated.
175166
* This should be called during plugin initialization.
@@ -213,7 +204,7 @@ protected function load_config(): void {
213204
}
214205

215206
// Load from database.
216-
$this->config = (array) get_option( $option_key, [] );
207+
$this->config = $this->get_option_value( $option_key, [] );
217208

218209
// Cache the result in both cache groups.
219210
wp_cache_set( $option_key, $this->config, self::CACHE_GROUP, $cache_duration );

plugins/wpgraphql-logging/src/Admin/Settings/Fields/Field/TextInputField.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ public function render_field( array $option_value, string $setting_key, string $
7070
* @return string The sanitized string value.
7171
*/
7272
public function sanitize_field( $value ): string {
73-
if ( 'email' === $this->get_input_type() ) {
74-
return sanitize_email( (string) $value );
75-
}
76-
77-
if ( 'url' === $this->get_input_type() ) {
78-
return esc_url_raw( (string) $value );
79-
}
80-
8173
return sanitize_text_field( (string) $value );
8274
}
8375

plugins/wpgraphql-logging/src/Admin/Settings/Fields/SettingsFieldCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function remove_field( string $key ): void {
8282
* @param \WPGraphQL\Logging\Admin\Settings\Fields\Tab\SettingsTabInterface $tab The tab to add.
8383
*/
8484
public function add_tab( SettingsTabInterface $tab ): void {
85-
$this->tabs[ $tab->get_name() ] = $tab;
85+
$this->tabs[ $tab::get_name() ] = $tab;
8686

8787
foreach ( $tab->get_fields() as $field_key => $field ) {
8888
$this->add_field( $field_key, $field );

plugins/wpgraphql-logging/src/Admin/Settings/Fields/Tab/BasicConfigurationTab.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,6 @@ class BasicConfigurationTab implements SettingsTabInterface {
6666
*/
6767
public const LOG_RESPONSE = 'log_response';
6868

69-
/**
70-
* Get the name/identifier of the tab.
71-
*/
72-
public function get_name(): string {
73-
return 'basic_configuration';
74-
}
75-
76-
/**
77-
* Get the label of the tab.
78-
*
79-
* @return string The tab label.
80-
*/
81-
public function get_label(): string {
82-
return 'Basic Configuration';
83-
}
84-
8569
/**
8670
* Get the fields for this tab.
8771
*
@@ -92,15 +76,15 @@ public function get_fields(): array {
9276

9377
$fields[ self::ENABLED ] = new CheckboxField(
9478
self::ENABLED,
95-
$this->get_name(),
79+
self::get_name(),
9680
__( 'Enabled', 'wpgraphql-logging' ),
9781
'',
9882
__( 'Enable or disable WPGraphQL logging.', 'wpgraphql-logging' ),
9983
);
10084

10185
$fields[ self::IP_RESTRICTIONS ] = new TextInputField(
10286
self::IP_RESTRICTIONS,
103-
$this->get_name(),
87+
self::get_name(),
10488
__( 'IP Restrictions', 'wpgraphql-logging' ),
10589
'',
10690
__( 'Comma-separated list of IPv4/IPv6 addresses to restrict logging to. Leave empty to log from all IPs.', 'wpgraphql-logging' ),
@@ -109,24 +93,24 @@ public function get_fields(): array {
10993

11094
$fields[ self::EXCLUDE_QUERY ] = new TextInputField(
11195
self::EXCLUDE_QUERY,
112-
$this->get_name(),
96+
self::get_name(),
11397
__( 'Exclude Queries', 'wpgraphql-logging' ),
11498
'',
11599
__( 'Comma-separated list of GraphQL query names to exclude from logging.', 'wpgraphql-logging' ),
116-
__( 'e.g., __schema,SeedNode,__typename', 'wpgraphql-logging' )
100+
__( 'e.g., __schema,GetSeedNode', 'wpgraphql-logging' )
117101
);
118102

119103
$fields[ self::ADMIN_USER_LOGGING ] = new CheckboxField(
120104
self::ADMIN_USER_LOGGING,
121-
$this->get_name(),
105+
self::get_name(),
122106
__( 'Admin User Logging', 'wpgraphql-logging' ),
123107
'',
124108
__( 'Log only for admin users.', 'wpgraphql-logging' )
125109
);
126110

127111
$fields[ self::DATA_SAMPLING ] = new SelectField(
128112
self::DATA_SAMPLING,
129-
$this->get_name(),
113+
self::get_name(),
130114
__( 'Data Sampling Rate', 'wpgraphql-logging' ),
131115
[
132116
'10' => __( '10% (Every 10th request)', 'wpgraphql-logging' ),
@@ -142,7 +126,7 @@ public function get_fields(): array {
142126

143127
$fields[ self::EVENT_LOG_SELECTION ] = new SelectField(
144128
self::EVENT_LOG_SELECTION,
145-
$this->get_name(),
129+
self::get_name(),
146130
__( 'Log Points', 'wpgraphql-logging' ),
147131
[
148132
Events::PRE_REQUEST => __( 'Pre Request', 'wpgraphql-logging' ),
@@ -159,12 +143,28 @@ public function get_fields(): array {
159143

160144
$fields[ self::LOG_RESPONSE ] = new CheckboxField(
161145
self::LOG_RESPONSE,
162-
$this->get_name(),
146+
self::get_name(),
163147
__( 'Log Response', 'wpgraphql-logging' ),
164148
'',
165149
__( 'Whether or not to log the response from the WPGraphQL query into the context object.', 'wpgraphql-logging' ),
166150
);
167151

168152
return apply_filters( 'wpgraphql_logging_basic_configuration_fields', $fields );
169153
}
154+
155+
/**
156+
* Get the name/identifier of the tab.
157+
*/
158+
public static function get_name(): string {
159+
return 'basic_configuration';
160+
}
161+
162+
/**
163+
* Get the label of the tab.
164+
*
165+
* @return string The tab label.
166+
*/
167+
public static function get_label(): string {
168+
return 'Basic Configuration';
169+
}
170170
}

plugins/wpgraphql-logging/src/Admin/Settings/Fields/Tab/DataManagementTab.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,6 @@ class DataManagementTab implements SettingsTabInterface {
6767
*/
6868
public const DATA_SANITIZATION_CUSTOM_FIELD_TRUNCATE = 'data_sanitization_custom_field_truncate';
6969

70-
/**
71-
* Get the name/identifier of the tab.
72-
*/
73-
public function get_name(): string {
74-
return 'data_management';
75-
}
76-
77-
/**
78-
* Get the label of the tab.
79-
*
80-
* @return string The tab label.
81-
*/
82-
public function get_label(): string {
83-
return 'Data Management';
84-
}
85-
8670
/**
8771
* Get the fields for this tab.
8872
*
@@ -93,15 +77,15 @@ public function get_fields(): array {
9377

9478
$fields[ self::DATA_DELETION_ENABLED ] = new CheckboxField(
9579
self::DATA_DELETION_ENABLED,
96-
$this->get_name(),
80+
self::get_name(),
9781
__( 'Data Deletion Enabled', 'wpgraphql-logging' ),
9882
'',
9983
__( 'Enable or disable data deletion for WPGraphQL logging.', 'wpgraphql-logging' ),
10084
);
10185

10286
$fields[ self::DATA_RETENTION_DAYS ] = new TextIntegerField(
10387
self::DATA_RETENTION_DAYS,
104-
$this->get_name(),
88+
self::get_name(),
10589
__( 'Number of Days to Retain Logs', 'wpgraphql-logging' ),
10690
'',
10791
__( 'Number of days to retain log data before deletion.', 'wpgraphql-logging' ),
@@ -111,7 +95,7 @@ public function get_fields(): array {
11195

11296
$fields[ self::DATA_SANITIZATION_ENABLED ] = new CheckboxField(
11397
self::DATA_SANITIZATION_ENABLED,
114-
$this->get_name(),
98+
self::get_name(),
11599
__( 'Data Sanitization Enabled', 'wpgraphql-logging' ),
116100
'',
117101
__( 'Enable or disable data sanitization for WPGraphQL logging.', 'wpgraphql-logging' ),
@@ -120,7 +104,7 @@ public function get_fields(): array {
120104

121105
$fields[ self::DATA_SANITIZATION_METHOD ] = new SelectField(
122106
self::DATA_SANITIZATION_METHOD,
123-
$this->get_name(),
107+
self::get_name(),
124108
__( 'Data Sanitization Method', 'wpgraphql-logging' ),
125109
[
126110
'recommended' => __( 'Recommended', 'wpgraphql-logging' ),
@@ -134,7 +118,7 @@ public function get_fields(): array {
134118

135119
$fields[ self::DATA_SANITIZATION_CUSTOM_FIELD_ANONYMIZE ] = new TextInputField(
136120
self::DATA_SANITIZATION_CUSTOM_FIELD_ANONYMIZE,
137-
$this->get_name(),
121+
self::get_name(),
138122
__( 'Custom Fields to Anonymize', 'wpgraphql-logging' ),
139123
'wpgraphql-logging-custom',
140124
__( 'Comma-separated list of custom fields to anonymize.', 'wpgraphql-logging' ),
@@ -143,20 +127,36 @@ public function get_fields(): array {
143127

144128
$fields[ self::DATA_SANITIZATION_CUSTOM_FIELD_REMOVE ] = new TextInputField(
145129
self::DATA_SANITIZATION_CUSTOM_FIELD_REMOVE,
146-
$this->get_name(),
130+
self::get_name(),
147131
__( 'Custom Fields to Remove', 'wpgraphql-logging' ),
148132
'wpgraphql-logging-custom',
149133
__( 'Comma-separated list of custom fields to remove.', 'wpgraphql-logging' ),
150134
);
151135

152136
$fields[ self::DATA_SANITIZATION_CUSTOM_FIELD_TRUNCATE ] = new TextInputField(
153137
self::DATA_SANITIZATION_CUSTOM_FIELD_TRUNCATE,
154-
$this->get_name(),
138+
self::get_name(),
155139
__( 'Custom Fields to Truncate', 'wpgraphql-logging' ),
156140
'wpgraphql-logging-custom',
157141
__( 'Comma-separated list of custom fields to truncate.', 'wpgraphql-logging' ),
158142
);
159143

160144
return apply_filters( 'wpgraphql_logging_data_management_fields', $fields );
161145
}
146+
147+
/**
148+
* Get the name/identifier of the tab.
149+
*/
150+
public static function get_name(): string {
151+
return 'data_management';
152+
}
153+
154+
/**
155+
* Get the label of the tab.
156+
*
157+
* @return string The tab label.
158+
*/
159+
public static function get_label(): string {
160+
return 'Data Management';
161+
}
162162
}

0 commit comments

Comments
 (0)