Skip to content

Commit 102bbdd

Browse files
committed
Minor admin fixes.
1 parent 0076c82 commit 102bbdd

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public function render_field( array $option_value, string $setting_key, string $
5252
$field_value = $this->get_field_value( $option_value, $tab_key, $this->multiple ? [] : '' );
5353

5454
// Ensure we have the correct format for comparison.
55-
$selected_values = $this->multiple ? (array) $field_value : [ (string) $field_value ];
55+
$selected_values = $this->multiple ? (array) $field_value : [ sanitize_text_field( (string) $field_value ) ];
56+
if ( $this->multiple ) {
57+
$selected_values = array_map( 'sanitize_text_field', $selected_values );
58+
}
5659

5760
$html = '<select ';
5861
$html .= 'name="' . esc_attr( $field_name ) . ( $this->multiple ? '[]' : '' ) . '" ';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(
4949
*/
5050
public function render_field( array $option_value, string $setting_key, string $tab_key ): string {
5151
$field_name = $this->get_field_name( $setting_key, $tab_key, $this->get_id() );
52-
$field_value = $this->get_field_value( $option_value, $tab_key, $this->default_value );
52+
$field_value = sanitize_text_field( $this->get_field_value( $option_value, $tab_key, $this->default_value ) );
5353

5454

5555
return sprintf(

plugins/wpgraphql-logging/src/Admin/SettingsPage.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,17 @@ public function get_current_tab( array $tabs = [] ): string {
159159
if ( empty( $tabs ) ) {
160160
return $this->get_default_tab();
161161
}
162-
163-
if ( ! isset( $_GET['tab'] ) || ! is_string( $_GET['tab'] ) ) {
162+
if ( ! isset( $_GET['tab'] ) || ! is_string( $_GET['tab'] ) || ! isset( $_GET['wpgraphql_logging_settings_tab_nonce'] ) || ! is_string( $_GET['wpgraphql_logging_settings_tab_nonce'] ) ) {
164163
return $this->get_default_tab();
165164
}
166165

167-
if ( ! isset( $_GET['wpgraphql_logging_settings_tab_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['wpgraphql_logging_settings_tab_nonce'] ) ), 'wpgraphql-logging-settings-tab-action' ) ) {
166+
$nonce = sanitize_text_field( $_GET['wpgraphql_logging_settings_tab_nonce'] );
167+
if ( false === wp_verify_nonce( $nonce, 'wpgraphql-logging-settings-tab-action' ) ) {
168168
return $this->get_default_tab();
169169
}
170170

171171
$tab = sanitize_text_field( wp_unslash( $_GET['tab'] ) );
172172

173-
if ( '' === $tab ) {
174-
return $this->get_default_tab();
175-
}
176-
177173
if ( array_key_exists( $tab, $tabs ) ) {
178174
return $tab;
179175
}

plugins/wpgraphql-logging/src/Admin/ViewLogsPage.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,23 @@ public function register_settings_page(): void {
8989
'manage_options',
9090
self::ADMIN_PAGE_SLUG,
9191
[ $this, 'render_admin_page' ],
92-
'dashicons-list-view',
92+
'dashicons-chart-line',
9393
25
9494
);
9595

9696
// Updates the list table when filters are applied.
9797
add_action( 'load-' . $this->page_hook, [ $this, 'process_page_actions_before_rendering' ], 10, 0 );
9898

9999
// Enqueue scripts for the admin page.
100-
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
100+
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts_styles' ] );
101101
}
102102

103103
/**
104104
* Enqueues scripts and styles for the admin page.
105105
*
106106
* @param string $hook_suffix The current admin page.
107107
*/
108-
public function enqueue_admin_scripts( string $hook_suffix ): void {
108+
public function enqueue_admin_scripts_styles( string $hook_suffix ): void {
109109
if ( $hook_suffix !== $this->page_hook ) {
110110
return;
111111
}
@@ -153,7 +153,6 @@ public function enqueue_admin_scripts( string $hook_suffix ): void {
153153
*/
154154
public function render_admin_page(): void {
155155

156-
157156
$action = isset( $_REQUEST['action'] ) && is_string( $_REQUEST['action'] )
158157
? sanitize_text_field( $_REQUEST['action'] )
159158
: 'list';

plugins/wpgraphql-logging/tests/wpunit/Admin/View/ViewLogsPageTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public function test_init_returns_same_instance_on_multiple_calls(): void {
6363
$this->assertSame($instance1, $instance2);
6464
}
6565

66-
public function test_enqueue_admin_scripts_only_on_correct_page(): void {
66+
public function test_enqueue_admin_scripts_styles_only_on_correct_page(): void {
6767
$this->set_as_admin();
6868
$instance = ViewLogsPage::init();
6969

7070
// Test with wrong hook suffix
71-
$instance->enqueue_admin_scripts('different-page');
71+
$instance->enqueue_admin_scripts_styles('different-page');
7272
$this->assertFalse(wp_script_is('jquery-ui-datepicker', 'enqueued'));
7373

7474
// Test with correct hook suffix (simulate the page hook)
@@ -77,7 +77,7 @@ public function test_enqueue_admin_scripts_only_on_correct_page(): void {
7777
$pageHookProperty->setAccessible(true);
7878
$pageHookProperty->setValue($instance, 'test-page-hook');
7979

80-
$instance->enqueue_admin_scripts('test-page-hook');
80+
$instance->enqueue_admin_scripts_styles('test-page-hook');
8181
$this->assertTrue(wp_script_is('jquery-ui-datepicker', 'enqueued'));
8282
$this->assertTrue(wp_script_is('jquery-ui-slider', 'enqueued'));
8383
}

0 commit comments

Comments
 (0)