From 601c75ad92925cffd3090b515702811258030bf6 Mon Sep 17 00:00:00 2001 From: Nikita Sinelnikov Date: Wed, 15 Dec 2021 02:46:47 +0200 Subject: [PATCH] - fixed #946; - fixed PHP notices; --- includes/core/class-form.php | 7 +++++-- includes/core/class-password.php | 7 ++++--- includes/core/class-roles-capabilities.php | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/includes/core/class-form.php b/includes/core/class-form.php index b53dead8..4d4efb96 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -114,7 +114,9 @@ if ( ! class_exists( 'um\core\Form' ) ) { $arr_options['status'] = 'success'; $arr_options['post'] = $_POST; - UM()->fields()->set_id = absint( $_POST['form_id'] ); + if ( isset( $_POST['form_id'] ) ) { + UM()->fields()->set_id = absint( $_POST['form_id'] ); + } UM()->fields()->set_mode = 'profile'; $form_fields = UM()->fields()->get_fields(); $arr_options['fields'] = $form_fields; @@ -135,7 +137,8 @@ if ( ! class_exists( 'um\core\Form' ) ) { ); if ( ! empty( $values_array ) ) { - $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] ); + $parent_dropdown = isset( $arr_options['field']['parent_dropdown_relationship'] ) ? $arr_options['field']['parent_dropdown_relationship'] : ''; + $arr_options['items'] = call_user_func( $ajax_source_func, $parent_dropdown ); if ( array_keys( $arr_options['items'] ) !== range( 0, count( $arr_options['items'] ) - 1 ) ) { // array with dropdown items is associative diff --git a/includes/core/class-password.php b/includes/core/class-password.php index e968a683..03754389 100644 --- a/includes/core/class-password.php +++ b/includes/core/class-password.php @@ -504,9 +504,10 @@ if ( ! class_exists( 'um\core\Password' ) ) { $data = get_user_by( 'email', $user ); } - um_fetch_user( $data->ID ); - - UM()->user()->password_reset(); + if ( isset( $data ) && is_a( $data, '\WP_User' ) ) { + um_fetch_user( $data->ID ); + UM()->user()->password_reset(); + } exit( wp_redirect( um_get_core_page('password-reset', 'checkemail' ) ) ); } diff --git a/includes/core/class-roles-capabilities.php b/includes/core/class-roles-capabilities.php index d0ad7dc9..29338c66 100644 --- a/includes/core/class-roles-capabilities.php +++ b/includes/core/class-roles-capabilities.php @@ -21,6 +21,23 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) { function __construct() { add_action( 'wp_roles_init', array( &$this, 'um_roles_init' ), 99999 ); add_action( 'update_option', array( &$this, 'um_on_roles_update' ), 10, 3 ); + add_action( 'set_user_role', array( &$this, 'remove_user_cache' ), 10, 1 ); + } + + + /** + * Flush the Cache User Profile on set new user role(s) + * + * @param int $user_id + */ + function remove_user_cache( $user_id ) { + $user = get_userdata( $user_id ); + + if ( ! is_a( $user, '\WP_User' ) ) { + return; + } + + UM()->user()->remove_cache( $user_id ); }