Skip to content

Commit e370d70

Browse files
author
Mukesh Kumar
authored
Update class-contact-form-plugin.php
1 parent 8a316b7 commit e370d70

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/contact-form/class-contact-form-plugin.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,18 @@ protected function __construct() {
296296
);
297297

298298
// POST handler
299-
if (
300-
isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === strtoupper( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) )
301-
&&
302-
isset( $_POST['action'] ) && 'grunion-contact-form' === $_POST['action'] // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verification should happen when hook fires.
303-
&&
304-
isset( $_POST['contact-form-id'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing -- no site changes
305-
) {
306-
add_action( 'template_redirect', array( $this, 'process_form_submission' ) );
307-
}
308-
299+
if (
300+
isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === strtolower( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) )
301+
&& isset( $_POST['action'] ) && 'grunion-contact-form' === sanitize_text_field( wp_unslash( $_POST['action'] ) )
302+
&& isset( $_POST['contact-form-id'] )
303+
) {
304+
// Verify the form nonce early to avoid attaching handlers for forged requests.
305+
if ( ! empty( $_POST['grunion_contact_form_nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['grunion_contact_form_nonce'] ), 'grunion-contact-form' ) ) {
306+
add_action( 'template_redirect', array( $this, 'process_form_submission' ) );
307+
} else {
308+
// Invalid nonce — do not attach handler.
309+
}
310+
}
309311
/*
310312
* Can be dequeued by placing the following in wp-content/themes/yourtheme/functions.php
311313
*

0 commit comments

Comments
 (0)