Skip to content

Commit e27696a

Browse files
committed
Updated admin templates for settings. Added data management settings.
1 parent 04879e8 commit e27696a

File tree

5 files changed

+165
-13
lines changed

5 files changed

+165
-13
lines changed

plugins/wpgraphql-logging/assets/css/settings/wp-graphql-logging-settings.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ settings_page_wpgraphql-logging #poststuff .postbox .inside h2 {
55
}
66

77

8+
.form-table td input[type="number"],
89
.form-table td input[type="text"] {
910
width: calc(99% - 24px);
1011
display: inline-block;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WPGraphQL\Logging\Admin\Settings\Fields\Field;
6+
7+
use WPGraphQL\Logging\Admin\Settings\Fields\Field\Text_Input_Field;
8+
9+
/**
10+
* Text Integer Field class for WPGraphQL Logging settings.
11+
*
12+
* This class handles the rendering and sanitization of text input fields in the settings form.
13+
*
14+
* @package WPGraphQL\Logging
15+
*
16+
* @since 0.0.1
17+
*/
18+
class Text_Integer_Field extends Text_Input_Field {
19+
/**
20+
* Sanitize the text input field value.
21+
*
22+
* @param mixed $value The field value to sanitize.
23+
*
24+
* @return string The sanitized string value.
25+
*/
26+
public function sanitize_field( $value ): string {
27+
$value = sanitize_text_field( (string) $value );
28+
return (string) intval( $value );
29+
}
30+
31+
/**
32+
* Get the input type.
33+
*
34+
* @return string The input type.
35+
*/
36+
protected function get_input_type(): string {
37+
return 'number';
38+
}
39+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace WPGraphQL\Logging\Admin\Settings\Fields;
66

77
use WPGraphQL\Logging\Admin\Settings\Fields\Tab\Basic_Configuration_Tab;
8+
use WPGraphQL\Logging\Admin\Settings\Fields\Tab\Data_Management_Tab;
89
use WPGraphQL\Logging\Admin\Settings\Fields\Tab\Settings_Tab_Interface;
910

1011
/**
@@ -34,6 +35,7 @@ class Settings_Field_Collection {
3435
*/
3536
public function __construct() {
3637
$this->add_tab( new Basic_Configuration_Tab() );
38+
$this->add_tab( new Data_Management_Tab() );
3739
do_action( 'wpgraphql_logging_settings_field_collection_init', $this );
3840
}
3941

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WPGraphQL\Logging\Admin\Settings\Fields\Tab;
6+
7+
use WPGraphQL\Logging\Admin\Settings\Fields\Field\Checkbox_Field;
8+
use WPGraphQL\Logging\Admin\Settings\Fields\Field\Text_Input_Field;
9+
use WPGraphQL\Logging\Admin\Settings\Fields\Field\Text_Integer_Field;
10+
11+
/**
12+
* Data Management Tab class.
13+
*
14+
* @package WPGraphQL\Logging
15+
*
16+
* @since 0.0.1
17+
*/
18+
class Data_Management_Tab implements Settings_Tab_Interface {
19+
/**
20+
* The field ID for the enabled checkbox.
21+
*
22+
* @var string
23+
*/
24+
public const DATA_DELETION_ENABLED = 'data_deletion_enabled';
25+
26+
/**
27+
* The field ID for the number of days to retain data.
28+
*
29+
* @var string
30+
*/
31+
public const DATA_RETENTION_DAYS = 'data_retention_days';
32+
33+
/**
34+
* The field ID for the data sanitization enabled checkbox.
35+
*
36+
* @var string
37+
*/
38+
public const DATA_SANITIZATION_ENABLED = 'data_sanitization_enabled';
39+
40+
/**
41+
* The field ID for the data sanitization fields.
42+
*
43+
* @var string
44+
*/
45+
public const DATA_SANITIZATION_FIELDS = 'data_sanitization_fields';
46+
47+
/**
48+
* Get the name/identifier of the tab.
49+
*/
50+
public function get_name(): string {
51+
return 'data_management';
52+
}
53+
54+
/**
55+
* Get the label of the tab.
56+
*
57+
* @return string The tab label.
58+
*/
59+
public function get_label(): string {
60+
return 'Data Management';
61+
}
62+
63+
/**
64+
* Get the fields for this tab.
65+
*
66+
* @return array<string, \WPGraphQL\Logging\Admin\Settings\Fields\Settings_Field_Interface> Array of fields keyed by field ID.
67+
*/
68+
public function get_fields(): array {
69+
$fields = [];
70+
71+
$fields[ self::DATA_DELETION_ENABLED ] = new Checkbox_Field(
72+
self::DATA_DELETION_ENABLED,
73+
$this->get_name(),
74+
__( 'Data Deletion Enabled', 'wpgraphql-logging' ),
75+
'',
76+
__( 'Enable or disable data deletion for WPGraphQL logging.', 'wpgraphql-logging' ),
77+
);
78+
79+
$fields[ self::DATA_RETENTION_DAYS ] = new Text_Integer_Field(
80+
self::DATA_RETENTION_DAYS,
81+
$this->get_name(),
82+
__( 'Number of Days to Retain Logs', 'wpgraphql-logging' ),
83+
'',
84+
__( 'Number of days to retain log data before deletion.', 'wpgraphql-logging' ),
85+
__( 'e.g., 30', 'wpgraphql-logging' ),
86+
'30'
87+
);
88+
89+
$fields[ self::DATA_SANITIZATION_ENABLED ] = new Checkbox_Field(
90+
self::DATA_SANITIZATION_ENABLED,
91+
$this->get_name(),
92+
__( 'Data Sanitization Enabled', 'wpgraphql-logging' ),
93+
'',
94+
__( 'Enable or disable data sanitization for WPGraphQL logging.', 'wpgraphql-logging' ),
95+
);
96+
97+
98+
$fields[ self::DATA_SANITIZATION_FIELDS ] = new Text_Input_Field(
99+
self::DATA_SANITIZATION_FIELDS,
100+
$this->get_name(),
101+
__( 'Data Sanitization Fields', 'wpgraphql-logging' ),
102+
'',
103+
__( 'A comma-separated list of fields to sanitize for WPGraphQL logging.', 'wpgraphql-logging' ),
104+
__( 'e.g., user.email, user.name, user.firstName, user.lastName', 'wpgraphql-logging' ),
105+
'user_email, user_pass, user_login, user_status, display_name, nickname, first_name, last_name'
106+
);
107+
108+
109+
return apply_filters( 'wpgraphql_logging_data_management_fields', $fields );
110+
}
111+
}

plugins/wpgraphql-logging/src/Admin/Settings/Templates/admin.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,23 @@
6767
<li><?php esc_html_e( 'Enable/disable logging', 'wpgraphql-logging' ); ?></li>
6868
<li><?php esc_html_e( 'Set IP restrictions', 'wpgraphql-logging' ); ?></li>
6969
<li><?php esc_html_e( 'Log only for admin users', 'wpgraphql-logging' ); ?></li>
70-
<li><?php esc_html_e( 'Filter specific queries', 'wpgraphql-logging' ); ?></li>
71-
<li><?php esc_html_e( 'Set data sampling rates', 'wpgraphql-logging' ); ?></li>
72-
<li><?php esc_html_e( 'Log for specific events', 'wpgraphql-logging' ); ?></li>
70+
<li><?php esc_html_e( 'Data sampling', 'wpgraphql-logging' ); ?></li>
71+
<li><?php esc_html_e( 'Log specific queries', 'wpgraphql-logging' ); ?></li>
72+
<li><?php esc_html_e( 'Exclude queries', 'wpgraphql-logging' ); ?></li>
73+
<li><?php esc_html_e( 'Log response', 'wpgraphql-logging' ); ?></li>
7374
</ul>
7475
<?php
7576
break;
7677

7778
case 'data_management':
7879
?>
79-
<p><?php esc_html_e( 'Manage how logging data is stored, retained, and exported.', 'wpgraphql-logging' ); ?></p>
80-
<p><em><?php esc_html_e( 'Configuration options coming soon.', 'wpgraphql-logging' ); ?></em></p>
81-
<?php
82-
break;
83-
84-
case 'security':
85-
?>
86-
<p><?php esc_html_e( 'Configure security settings for logging data and access controls.', 'wpgraphql-logging' ); ?></p>
87-
<p><em><?php esc_html_e( 'Configuration options coming soon.', 'wpgraphql-logging' ); ?></em></p>
80+
<p><?php esc_html_e( 'Manage how logging data is sanitized and deleted.', 'wpgraphql-logging' ); ?></p>
81+
<ul class="wpgraphql-logging-feature-list">
82+
<li><?php esc_html_e( 'Enable/disable data deletion', 'wpgraphql-logging' ); ?></li>
83+
<li><?php esc_html_e( 'Number of days logs are stored', 'wpgraphql-logging' ); ?></li>
84+
<li><?php esc_html_e( 'Enable/disable data sanitization', 'wpgraphql-logging' ); ?></li>
85+
<li><?php esc_html_e( 'List fields for sanitization', 'wpgraphql-logging' ); ?></li>
86+
</ul>
8887
<?php
8988
break;
9089

@@ -106,7 +105,7 @@
106105
<div class="inside wpgraphql-logging-docs">
107106
<ul>
108107
<li><a href="https://github.com/wpengine/hwptoolkit/tree/main/plugins/wpgraphql-logging#getting-started" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Getting Started', 'wpgraphql-logging' ); ?></a></li>
109-
<li><a href="https://github.com/wpengine/hwptoolkit/tree/main/plugins/wpgraphql-logging" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Documentation', 'wpgraphql-logging' ); ?></a></li>
108+
<li><a href="https://github.com/wpengine/hwptoolkit/blob/main/README.md" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Documentation', 'wpgraphql-logging' ); ?></a></li>
110109
<li><a href="https://github.com/wpengine/hwptoolkit" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'HWP Toolkit', 'wpgraphql-logging' ); ?></a></li>
111110
</ul>
112111
<p><?php esc_html_e( 'WPGraphQL Logging is part of the HWP Toolkit, our comprehensive suite of tools and examples for headless WordPress.', 'wpgraphql-logging' ); ?></p>

0 commit comments

Comments
 (0)