From b509018276a4983c5603ff0b6b1361dd952e8cb3 Mon Sep 17 00:00:00 2001 From: yuriinalivaiko Date: Wed, 18 Sep 2024 23:16:11 +0300 Subject: [PATCH] - make it impossible to create a user without a role even with incorrect "Registration Default Role" setting. --- includes/core/class-form.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/core/class-form.php b/includes/core/class-form.php index 0593c112..5b7e0475 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -1009,7 +1009,9 @@ if ( ! class_exists( 'um\core\Form' ) ) { $global_role = get_option( 'default_role' ); // WP Global settings $um_global_role = UM()->options()->get( 'register_role' ); // UM Settings Global settings - if ( ! empty( $um_global_role ) ) { + + $existing_roles = array_keys( wp_roles()->roles ); + if ( ! empty( $um_global_role ) && in_array( $um_global_role, $existing_roles, true ) ) { $global_role = $um_global_role; // Form Global settings } @@ -1023,7 +1025,7 @@ if ( ! class_exists( 'um\core\Form' ) ) { $role = get_post_meta( $post_id, "_um_{$mode}_role", true ); } - if ( empty( $role ) ) { // custom role is default, return default role's slug + if ( empty( $role ) || ! in_array( $role, $existing_roles, true ) ) { // custom role is default, return default role's slug $role = $global_role; }