From 34d3b5d343f212957b75f94644ee6e6c6a14663a Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Tue, 15 Oct 2024 17:03:54 +0530 Subject: [PATCH] fixed fatal error with user role --- mlw_quizmaster2.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index ce63fc21..d3ed9218 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -756,11 +756,15 @@ public function qsm_add_user_capabilities() { ); $user = wp_get_current_user(); + if ( empty( $user->roles ) || ! is_array( $user->roles ) ) { + return; + } $roles = (array) $user->roles; $rolename = $roles[0]; - $role = get_role( $rolename ); - + if ( ! $role ) { + return; + } // Remove all capabilities first. foreach ( $administrator_capabilities as $cap ) { if ( $role->has_cap( $cap ) ) {