WordPress: avoid PHP notice if the anonymous user does not have any capabilities
authorMathieu Lutfy <mathieu@symbiotic.coop>
Thu, 4 Mar 2021 21:34:33 +0000 (16:34 -0500)
committerMathieu Lutfy <mathieu@bidon.ca>
Thu, 4 Mar 2021 21:49:01 +0000 (16:49 -0500)
CRM/Core/Permission/WordPress.php

index 3325d0fc117c3f23a4ba3dee0e04cf42b6f4ff6f..03eeb9be3b0fa7c7be72ed61bdb036082ef2ac82 100644 (file)
@@ -76,10 +76,8 @@ class CRM_Core_Permission_WordPress extends CRM_Core_Permission_Base {
     else {
       //check the capabilities of Anonymous user)
       $roleObj = new WP_Roles();
-      if (
-        $roleObj->get_role('anonymous_user') != NULL &&
-        array_key_exists($str, $roleObj->get_role('anonymous_user')->capabilities)
-      ) {
+      $anonObj = $roleObj->get_role('anonymous_user');
+      if (!empty($anonObj->capabilities) && array_key_exists($str, $anonObj->capabilities)) {
         return TRUE;
       }
     }