{"id":107,"date":"2016-10-25T11:47:31","date_gmt":"2016-10-25T05:47:31","guid":{"rendered":"http:\/\/ronniee.net\/?p=107"},"modified":"2016-10-25T11:47:31","modified_gmt":"2016-10-25T05:47:31","slug":"get-super-users-in-joomla","status":"publish","type":"post","link":"https:\/\/ronniee.net\/?p=107","title":{"rendered":"Get Super users in Joomla"},"content":{"rendered":"\n<pre class=\"lang:php decode:true \" >\/**\r\n\t * Returns the Super Users email information. If you provide a comma separated $email list\r\n\t * we will check that these emails do belong to Super Users and that they have not blocked\r\n\t * system emails.\r\n\t *\r\n\t * @param   null|string  $email  A list of Super Users to email\r\n\t *\r\n\t * @return  array  The list of Super User emails\r\n\t *\r\n\t * @since   3.5\r\n\t *\/\r\n\tprivate function getSuperUsers($email = null)\r\n\t{\r\n\t\t\/\/ Get a reference to the database object\r\n\t\t$db = JFactory::getDBO();\r\n\r\n\t\t\/\/ Convert the email list to an array\r\n\t\tif (!empty($email))\r\n\t\t{\r\n\t\t\t$temp   = explode(',', $email);\r\n\t\t\t$emails = array();\r\n\r\n\t\t\tforeach ($temp as $entry)\r\n\t\t\t{\r\n\t\t\t\t$entry    = trim($entry);\r\n\t\t\t\t$emails[] = $db-&gt;q($entry);\r\n\t\t\t}\r\n\r\n\t\t\t$emails = array_unique($emails);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t$emails = array();\r\n\t\t}\r\n\r\n\t\t\/\/ Get a list of groups which have Super User privileges\r\n\t\t$ret = array();\r\n\r\n\t\ttry\r\n\t\t{\r\n\t\t\t$query = $db-&gt;getQuery(true)\r\n\t\t\t\t\t\t-&gt;select($db-&gt;qn('rules'))\r\n\t\t\t\t\t\t-&gt;from($db-&gt;qn('#__assets'))\r\n\t\t\t\t\t\t-&gt;where($db-&gt;qn('parent_id') . ' = ' . $db-&gt;q(0));\r\n\t\t\t$db-&gt;setQuery($query, 0, 1);\r\n\t\t\t$rulesJSON = $db-&gt;loadResult();\r\n\t\t\t$rules     = json_decode($rulesJSON, true);\r\n\r\n\t\t\t$rawGroups = $rules['core.admin'];\r\n\t\t\t$groups    = array();\r\n\r\n\t\t\tif (empty($rawGroups))\r\n\t\t\t{\r\n\t\t\t\treturn $ret;\r\n\t\t\t}\r\n\r\n\t\t\tforeach ($rawGroups as $g =&gt; $enabled)\r\n\t\t\t{\r\n\t\t\t\tif ($enabled)\r\n\t\t\t\t{\r\n\t\t\t\t\t$groups[] = $db-&gt;q($g);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (empty($groups))\r\n\t\t\t{\r\n\t\t\t\treturn $ret;\r\n\t\t\t}\r\n\t\t}\r\n\t\tcatch (Exception $exc)\r\n\t\t{\r\n\t\t\treturn $ret;\r\n\t\t}\r\n\r\n\t\t\/\/ Get the user IDs of users belonging to the SA groups\r\n\t\ttry\r\n\t\t{\r\n\t\t\t$query = $db-&gt;getQuery(true)\r\n\t\t\t\t\t\t-&gt;select($db-&gt;qn('user_id'))\r\n\t\t\t\t\t\t-&gt;from($db-&gt;qn('#__user_usergroup_map'))\r\n\t\t\t\t\t\t-&gt;where($db-&gt;qn('group_id') . ' IN(' . implode(',', $groups) . ')');\r\n\t\t\t$db-&gt;setQuery($query);\r\n\t\t\t$rawUserIDs = $db-&gt;loadColumn(0);\r\n\r\n\t\t\tif (empty($rawUserIDs))\r\n\t\t\t{\r\n\t\t\t\treturn $ret;\r\n\t\t\t}\r\n\r\n\t\t\t$userIDs = array();\r\n\r\n\t\t\tforeach ($rawUserIDs as $id)\r\n\t\t\t{\r\n\t\t\t\t$userIDs[] = $db-&gt;q($id);\r\n\t\t\t}\r\n\t\t}\r\n\t\tcatch (Exception $exc)\r\n\t\t{\r\n\t\t\treturn $ret;\r\n\t\t}\r\n\r\n\t\t\/\/ Get the user information for the Super Administrator users\r\n\t\ttry\r\n\t\t{\r\n\t\t\t$query = $db-&gt;getQuery(true)\r\n\t\t\t\t\t\t-&gt;select(\r\n\t\t\t\t\t\t\tarray(\r\n\t\t\t\t\t\t\t\t$db-&gt;qn('id'),\r\n\t\t\t\t\t\t\t\t$db-&gt;qn('username'),\r\n\t\t\t\t\t\t\t\t$db-&gt;qn('email'),\r\n\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t)-&gt;from($db-&gt;qn('#__users'))\r\n\t\t\t\t\t\t-&gt;where($db-&gt;qn('id') . ' IN(' . implode(',', $userIDs) . ')')\r\n\t\t\t\t\t\t-&gt;where($db-&gt;qn('sendEmail') . ' = ' . $db-&gt;q('1'));\r\n\r\n\t\t\tif (!empty($emails))\r\n\t\t\t{\r\n\t\t\t\t$query-&gt;where($db-&gt;qn('email') . 'IN(' . implode(',', $emails) . ')');\r\n\t\t\t}\r\n\r\n\t\t\t$db-&gt;setQuery($query);\r\n\t\t\t$ret = $db-&gt;loadObjectList();\r\n\t\t}\r\n\t\tcatch (Exception $exc)\r\n\t\t{\r\n\t\t\treturn $ret;\r\n\t\t}\r\n\r\n\t\treturn $ret;\r\n\t}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/** * Returns the Super Users email information. If you provide a comma separated $email list * we will check that these emails do belong to Super Users and that they have not blocked * system emails. * * @param null|string $email A list of Super Users to email * * @return array The list [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,2],"tags":[],"class_list":["post-107","post","type-post","status-publish","format-standard","hentry","category-joomla3x","category-php"],"_links":{"self":[{"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/posts\/107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ronniee.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=107"}],"version-history":[{"count":1,"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":108,"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions\/108"}],"wp:attachment":[{"href":"https:\/\/ronniee.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ronniee.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ronniee.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}