Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b28054f
Refactoring Admin Tabs to make to reduce code duplication.
colinmurphy Sep 24, 2025
3781589
Refactor settings page and add new tests
colinmurphy Sep 24, 2025
bbb6750
Removed LoggerSettingService as not needed. Updated tests for Admin S…
colinmurphy Sep 26, 2025
308217a
Fixed bug when query is empty. Added tests for DownloadLogService.
colinmurphy Sep 26, 2025
75c5438
Added tests for ViewLogsPage class
colinmurphy Sep 26, 2025
c3302a6
Added tests for ListTable. Admin test coverage now above 85%.
colinmurphy Sep 26, 2025
716d534
Fixed namespaces for test classes. Added missing tests for the databa…
colinmurphy Sep 26, 2025
6a45575
Added tests for LogsRepository.
colinmurphy Sep 26, 2025
070ce14
Added tests for individual rules. Updated placeholder text for exclud…
colinmurphy Sep 26, 2025
59dbb0f
Added test for SampleRateRule.
colinmurphy Sep 26, 2025
785a70f
Added tests for Data Sanisation.
colinmurphy Sep 29, 2025
a1580ad
Merge branch 'main' into chore-wpgraphql-snags-sept-2025-iteration-2
colinmurphy Sep 29, 2025
d8b7366
Added tests for Data Deletion Scheduler.
colinmurphy Sep 29, 2025
9559fbe
Added tests for Events Action Logger. Added fixes to the action logge…
colinmurphy Sep 30, 2025
2a77388
Added fixes to EventFilterLogger and added tests.
colinmurphy Sep 30, 2025
0f1986c
Add event selection check for response headers logging
colinmurphy Sep 30, 2025
6a199f8
Added missing tests to the plugin manager.
colinmurphy Sep 30, 2025
8e8e204
Fix for PHP 8.3 for sampling rate
colinmurphy Sep 30, 2025
ef373fa
Added Changeset
colinmurphy Oct 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-moons-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/wpgraphql-logging-wordpress-plugin": patch
---

chore: Fixed some snags for events and event manager. Added and updated PHPUnit tests and coverage now above 90%.
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,16 @@

namespace WPGraphQL\Logging\Admin\Settings;

use WPGraphQL\Logging\Admin\Settings\Fields\Tab\BasicConfigurationTab;
use WPGraphQL\Logging\Admin\Settings\Fields\Tab\DataManagementTab;

/**
* Configuration Helper class
*
* This class provides a centralized and cached way to access WPGraphQL Logging configuration.
* It implements a singleton pattern to ensure configuration is only loaded once per request
* and provides convenient methods for accessing different configuration sections.
*
* Usage Examples:
* ```php
* // Get the helper instance
* $config = ConfigurationHelper::get_instance();
*
* // Get a specific setting
* $log_level = $config->get_setting('basic_configuration', 'log_level', 'info');
*
* // Check if a feature is enabled
* $is_enabled = $config->is_enabled('data_management', 'data_sanitization_enabled');
*
* // Get an entire configuration section
* $basic_config = $config->get_basic_config();
* ```
*
* @package WPGraphQL\Logging
*
* @since 0.0.1
Expand Down Expand Up @@ -87,25 +75,25 @@ public function get_config(): array {
* Get configuration for a specific section (tab).
*
* @param string $section The configuration section key.
* @param array<string, mixed> $default_value Default value if section not found.
* @param array<string, mixed> $default_value_value Default value if section not found.
*
* @return array<string, mixed>
*/
public function get_section_config( string $section, array $default_value = [] ): array {
public function get_section_config( string $section, array $default_value_value = [] ): array {
$config = $this->get_config();
return $config[ $section ] ?? $default_value;
return $config[ $section ] ?? $default_value_value;
}

/**
* Get a specific setting value from a configuration section.
*
* @param string $section The configuration section key.
* @param string $setting_key The setting key within the section.
* @param mixed $default_value Default value if setting not found.
* @param mixed $default_value_value Default value if setting not found.
*/
public function get_setting( string $section, string $setting_key, $default_value = null ): mixed {
public function get_setting( string $section, string $setting_key, $default_value_value = null ): mixed {
$section_config = $this->get_section_config( $section );
return $section_config[ $setting_key ] ?? $default_value;
return $section_config[ $setting_key ] ?? $default_value_value;
}

/**
Expand All @@ -114,7 +102,7 @@ public function get_setting( string $section, string $setting_key, $default_valu
* @return array<string, mixed>
*/
public function get_basic_config(): array {
return $this->get_section_config( 'basic_configuration' );
return $this->get_section_config( BasicConfigurationTab::get_name() );
}

/**
Expand All @@ -123,7 +111,7 @@ public function get_basic_config(): array {
* @return array<string, mixed>
*/
public function get_data_management_config(): array {
return $this->get_section_config( 'data_management' );
return $this->get_section_config( DataManagementTab::get_name() );
}

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

/**
* Reload the configuration from the database.
* This bypasses any cache and forces a fresh load.
*/
public function reload_config(): void {
$this->clear_cache();
$this->load_config();
}

/**
* Get the option key for the settings.
*/
Expand All @@ -170,6 +149,18 @@ public function get_settings_group(): string {
return (string) apply_filters( 'wpgraphql_logging_settings_group_settings_group', WPGRAPHQL_LOGGING_SETTINGS_GROUP );
}

/**
* Get the raw option value from the database.
*
* @param string $option_key The option key to retrieve.
* @param mixed $default_value Default value if option not found.
*
* @return array<string, mixed> The option value as an array.
*/
public function get_option_value( string $option_key, mixed $default_value = null ): array {
return (array) get_option( $option_key, $default_value );
}

/**
* Hook into WordPress to clear cache when settings are updated.
* This should be called during plugin initialization.
Expand Down Expand Up @@ -213,7 +204,7 @@ protected function load_config(): void {
}

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

// Cache the result in both cache groups.
wp_cache_set( $option_key, $this->config, self::CACHE_GROUP, $cache_duration );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ public function render_field( array $option_value, string $setting_key, string $
* @return string The sanitized string value.
*/
public function sanitize_field( $value ): string {
if ( 'email' === $this->get_input_type() ) {
return sanitize_email( (string) $value );
}

if ( 'url' === $this->get_input_type() ) {
return esc_url_raw( (string) $value );
}

return sanitize_text_field( (string) $value );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function remove_field( string $key ): void {
* @param \WPGraphQL\Logging\Admin\Settings\Fields\Tab\SettingsTabInterface $tab The tab to add.
*/
public function add_tab( SettingsTabInterface $tab ): void {
$this->tabs[ $tab->get_name() ] = $tab;
$this->tabs[ $tab::get_name() ] = $tab;

foreach ( $tab->get_fields() as $field_key => $field ) {
$this->add_field( $field_key, $field );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,6 @@ class BasicConfigurationTab implements SettingsTabInterface {
*/
public const LOG_RESPONSE = 'log_response';

/**
* Get the name/identifier of the tab.
*/
public function get_name(): string {
return 'basic_configuration';
}

/**
* Get the label of the tab.
*
* @return string The tab label.
*/
public function get_label(): string {
return 'Basic Configuration';
}

/**
* Get the fields for this tab.
*
Expand All @@ -92,15 +76,15 @@ public function get_fields(): array {

$fields[ self::ENABLED ] = new CheckboxField(
self::ENABLED,
$this->get_name(),
self::get_name(),
__( 'Enabled', 'wpgraphql-logging' ),
'',
__( 'Enable or disable WPGraphQL logging.', 'wpgraphql-logging' ),
);

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

$fields[ self::EXCLUDE_QUERY ] = new TextInputField(
self::EXCLUDE_QUERY,
$this->get_name(),
self::get_name(),
__( 'Exclude Queries', 'wpgraphql-logging' ),
'',
__( 'Comma-separated list of GraphQL query names to exclude from logging.', 'wpgraphql-logging' ),
__( 'e.g., __schema,SeedNode,__typename', 'wpgraphql-logging' )
__( 'e.g., __schema,GetSeedNode', 'wpgraphql-logging' )
);

$fields[ self::ADMIN_USER_LOGGING ] = new CheckboxField(
self::ADMIN_USER_LOGGING,
$this->get_name(),
self::get_name(),
__( 'Admin User Logging', 'wpgraphql-logging' ),
'',
__( 'Log only for admin users.', 'wpgraphql-logging' )
);

$fields[ self::DATA_SAMPLING ] = new SelectField(
self::DATA_SAMPLING,
$this->get_name(),
self::get_name(),
__( 'Data Sampling Rate', 'wpgraphql-logging' ),
[
'10' => __( '10% (Every 10th request)', 'wpgraphql-logging' ),
Expand All @@ -142,7 +126,7 @@ public function get_fields(): array {

$fields[ self::EVENT_LOG_SELECTION ] = new SelectField(
self::EVENT_LOG_SELECTION,
$this->get_name(),
self::get_name(),
__( 'Log Points', 'wpgraphql-logging' ),
[
Events::PRE_REQUEST => __( 'Pre Request', 'wpgraphql-logging' ),
Expand All @@ -159,12 +143,28 @@ public function get_fields(): array {

$fields[ self::LOG_RESPONSE ] = new CheckboxField(
self::LOG_RESPONSE,
$this->get_name(),
self::get_name(),
__( 'Log Response', 'wpgraphql-logging' ),
'',
__( 'Whether or not to log the response from the WPGraphQL query into the context object.', 'wpgraphql-logging' ),
);

return apply_filters( 'wpgraphql_logging_basic_configuration_fields', $fields );
}

/**
* Get the name/identifier of the tab.
*/
public static function get_name(): string {
return 'basic_configuration';
}

/**
* Get the label of the tab.
*
* @return string The tab label.
*/
public static function get_label(): string {
return 'Basic Configuration';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,6 @@ class DataManagementTab implements SettingsTabInterface {
*/
public const DATA_SANITIZATION_CUSTOM_FIELD_TRUNCATE = 'data_sanitization_custom_field_truncate';

/**
* Get the name/identifier of the tab.
*/
public function get_name(): string {
return 'data_management';
}

/**
* Get the label of the tab.
*
* @return string The tab label.
*/
public function get_label(): string {
return 'Data Management';
}

/**
* Get the fields for this tab.
*
Expand All @@ -93,15 +77,15 @@ public function get_fields(): array {

$fields[ self::DATA_DELETION_ENABLED ] = new CheckboxField(
self::DATA_DELETION_ENABLED,
$this->get_name(),
self::get_name(),
__( 'Data Deletion Enabled', 'wpgraphql-logging' ),
'',
__( 'Enable or disable data deletion for WPGraphQL logging.', 'wpgraphql-logging' ),
);

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

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

$fields[ self::DATA_SANITIZATION_METHOD ] = new SelectField(
self::DATA_SANITIZATION_METHOD,
$this->get_name(),
self::get_name(),
__( 'Data Sanitization Method', 'wpgraphql-logging' ),
[
'recommended' => __( 'Recommended', 'wpgraphql-logging' ),
Expand All @@ -134,7 +118,7 @@ public function get_fields(): array {

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

$fields[ self::DATA_SANITIZATION_CUSTOM_FIELD_REMOVE ] = new TextInputField(
self::DATA_SANITIZATION_CUSTOM_FIELD_REMOVE,
$this->get_name(),
self::get_name(),
__( 'Custom Fields to Remove', 'wpgraphql-logging' ),
'wpgraphql-logging-custom',
__( 'Comma-separated list of custom fields to remove.', 'wpgraphql-logging' ),
);

$fields[ self::DATA_SANITIZATION_CUSTOM_FIELD_TRUNCATE ] = new TextInputField(
self::DATA_SANITIZATION_CUSTOM_FIELD_TRUNCATE,
$this->get_name(),
self::get_name(),
__( 'Custom Fields to Truncate', 'wpgraphql-logging' ),
'wpgraphql-logging-custom',
__( 'Comma-separated list of custom fields to truncate.', 'wpgraphql-logging' ),
);

return apply_filters( 'wpgraphql_logging_data_management_fields', $fields );
}

/**
* Get the name/identifier of the tab.
*/
public static function get_name(): string {
return 'data_management';
}

/**
* Get the label of the tab.
*
* @return string The tab label.
*/
public static function get_label(): string {
return 'Data Management';
}
}
Loading