- fix for registration form;

This commit is contained in:
Mykyta Synelnikov
2023-06-30 21:55:59 +03:00
parent 246de13726
commit 7fafa3a4b3
9 changed files with 373 additions and 403 deletions
+29 -43
View File
@@ -1,29 +1,26 @@
<?php
namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'um\core\Register' ) ) {
/**
* Class Register
* @package um\core
*/
class Register {
/**
* Register constructor.
*/
function __construct() {
add_action( 'um_after_register_fields', array( $this, 'add_nonce' ) );
add_action( 'um_submit_form_register', array( $this, 'verify_nonce' ), 1, 1 );
public function __construct() {
add_action( 'um_after_register_fields', array( $this, 'add_nonce' ) );
add_action( 'um_submit_form_register', array( $this, 'verify_nonce' ), 1, 2 );
}
/**
* Add registration form notice
*/
@@ -31,49 +28,38 @@ if ( ! class_exists( 'um\core\Register' ) ) {
wp_nonce_field( 'um_register_form' );
}
/**
* Verify nonce handler
*
* @param $args
*
* @return mixed
* @param array $args
* @param array $form_data
*/
public function verify_nonce( $args ) {
public function verify_nonce( $args, $form_data ) {
/**
* UM hook
* Filters allow nonce verifying while UM Register submission.
*
* @type filter
* @title um_register_allow_nonce_verification
* @description Enable/DIsable nonce verification of registration
* @input_vars
* [{"var":"$allow_nonce","type":"bool","desc":"Enable nonce"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_register_allow_nonce_verification', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_register_allow_nonce_verification', 'my_register_allow_nonce_verification', 10, 1 );
* function my_register_allow_nonce_verification( $allow_nonce ) {
* // your code here
* return $allow_nonce;
* }
* ?>
* @param {bool} $allow_nonce Is allowed verify nonce on register. By default, allowed = `true`.
* @param {array} $form_data Form's metakeys. Since 2.6.7.
*
* @return {bool} Is allowed verify.
*
* @since 2.0
* @hook um_register_allow_nonce_verification
*
* @example <caption>Disable verifying nonce on the register page.</caption>
* add_filter( 'um_login_allow_nonce_verification', '__return_false' );
*/
$allow_nonce_verification = apply_filters( 'um_register_allow_nonce_verification', true );
if ( ! $allow_nonce_verification ) {
return $args;
$allow_nonce_verification = apply_filters( 'um_register_allow_nonce_verification', true, $form_data );
if ( ! $allow_nonce_verification ) {
return;
}
if ( ! wp_verify_nonce( $args['_wpnonce'], 'um_register_form' ) || empty( $args['_wpnonce'] ) || ! isset( $args['_wpnonce'] ) ) {
$url = apply_filters( 'um_register_invalid_nonce_redirect_url', add_query_arg( [ 'err' => 'invalid_nonce' ] ) );
exit( wp_redirect( $url ) );
if ( empty( $args['_wpnonce'] ) || ! wp_verify_nonce( $args['_wpnonce'], 'um_register_form' ) ) {
// @todo add hookdocs
$url = apply_filters( 'um_register_invalid_nonce_redirect_url', add_query_arg( array( 'err' => 'invalid_nonce' ) ) );
wp_safe_redirect( $url );
exit;
}
return $args;
}
}
}
}