@@ -27,14 +27,14 @@ class SettingsPage {
2727 public const PLUGIN_MENU_SLUG = 'wpgraphql-logging ' ;
2828
2929 /**
30- * The field collection.
30+ * The settings field collection.
3131 *
3232 * @var \WPGraphQL\Logging\Admin\Settings\Fields\SettingsFieldCollection|null
3333 */
3434 protected ?SettingsFieldCollection $ field_collection = null ;
3535
3636 /**
37- * The instance of the plugin .
37+ * The instance of the settings page .
3838 *
3939 * @var \WPGraphQL\Logging\Admin\SettingsPage|null
4040 */
@@ -116,6 +116,7 @@ public function register_settings_page(): void {
116116 'wpgraphql_logging_main_page_config ' => [
117117 'tabs ' => $ tab_labels ,
118118 'current_tab ' => $ this ->get_current_tab (),
119+ 'nonce ' => wp_create_nonce ( 'wpgraphql-logging-settings-tab-action ' ),
119120 ],
120121 ],
121122 );
@@ -158,13 +159,16 @@ public function get_current_tab( array $tabs = [] ): string {
158159 if ( empty ( $ tabs ) ) {
159160 return $ this ->get_default_tab ();
160161 }
161- // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading GET parameter for tab navigation only, no form processing
162+
162163 if ( ! isset ( $ _GET ['tab ' ] ) || ! is_string ( $ _GET ['tab ' ] ) ) {
163164 return $ this ->get_default_tab ();
164165 }
165166
166- // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading GET parameter for tab navigation only, no form processing
167- $ tab = sanitize_text_field ( $ _GET ['tab ' ] );
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 ' ) ) {
168+ return $ this ->get_default_tab ();
169+ }
170+
171+ $ tab = sanitize_text_field ( wp_unslash ( $ _GET ['tab ' ] ) );
168172
169173 if ( '' === $ tab ) {
170174 return $ this ->get_default_tab ();
@@ -192,7 +196,6 @@ public function get_default_tab(): string {
192196 * @param string $hook_suffix The current admin page hook suffix.
193197 */
194198 public function load_scripts_styles ( string $ hook_suffix ): void {
195- // Only load on our settings page.
196199 if ( ! str_contains ( $ hook_suffix , self ::PLUGIN_MENU_SLUG ) ) {
197200 return ;
198201 }
@@ -210,18 +213,19 @@ public function load_scripts_styles( string $hook_suffix ): void {
210213
211214 // Enqueue admin scripts if they exist.
212215 $ script_path = trailingslashit ( WPGRAPHQL_LOGGING_PLUGIN_URL ) . 'assets/js/settings/wp-graphql-logging-settings.js ' ;
213- if ( ! file_exists ( trailingslashit ( WPGRAPHQL_LOGGING_PLUGIN_DIR ) . 'assets/js/settings/wp-graphql-logging-settings.js ' ) ) {
214- return ;
216+ if ( file_exists ( trailingslashit ( WPGRAPHQL_LOGGING_PLUGIN_DIR ) . 'assets/js/settings/wp-graphql-logging-settings.js ' ) ) {
217+ wp_enqueue_script (
218+ 'wpgraphql-logging-settings-js ' ,
219+ $ script_path ,
220+ [],
221+ WPGRAPHQL_LOGGING_VERSION ,
222+ true
223+ );
215224 }
216225
217- wp_enqueue_script (
218- 'wpgraphql-logging-settings-js ' ,
219- $ script_path ,
220- [],
221- WPGRAPHQL_LOGGING_VERSION ,
222- true
223- );
224-
226+ /**
227+ * Fire off action to enqueue scripts and styles.
228+ */
225229 do_action ( 'wpgraphql_logging_admin_enqueue_scripts ' , $ hook_suffix );
226230 }
227231
0 commit comments