/** * Notify the site admins about pending approvals * * @return void */ function uservalidationbyadmin_notify_admins() { $notify_admins = uservalidationbyadmin_get_admin_notification_setting(); if (!empty($notify_admins) && $notify_admins != "none") { // make sure we can see every user $hidden = access_get_show_hidden_status(); access_show_hidden_entities(true); // get selection options $options = uservalidationbyadmin_get_selection_options(true); $user_count = elgg_get_entities_from_relationship($options); if (!empty($user_count)) { $site = elgg_get_site_entity(); // there are unvalidated users, now find the admins to notify $admin_options = array("type" => "user", "limit" => false, "site_guids" => false, "relationship" => "member_of_site", "relationship_guid" => $site->getGUID(), "inverse_relationship" => true, "joins" => array("JOIN " . elgg_get_config("dbprefix") . "users_entity ue ON e.guid = ue.guid"), "wheres" => array("ue.admin = 'yes'")); $admins = elgg_get_entities_from_relationship($admin_options); // trigger hook to adjust the admin list $params = array("admins" => $admins, "user_count" => $user_count); $admins = elgg_trigger_plugin_hook("notify_admin", "uservalidationbyadmin", $params, $admins); // notify the admins if (!empty($admins)) { foreach ($admins as $admin) { // does the admin have notifications disabled if (elgg_get_plugin_user_setting("notify", $admin->getGUID(), "uservalidationbyadmin") != "no") { $subject = elgg_echo("uservalildationbyadmin:notify:admin:subject"); $msg = elgg_echo("uservalildationbyadmin:notify:admin:message", array($admin->name, $user_count, $site->name, $site->url . "admin/users/pending_approval")); notify_user($admin->getGUID(), $site->getGUID(), $subject, $msg, null, "email"); } } } } // restore hidden setting access_show_hidden_entities($hidden); } }
/** * Listen to the CRON to notify the admins about pending approvals * * @param string $hook the name of the hook * @param string $type the type of the hook * @param string $return_value the current return value * @param array $params supplied params * * @return string */ function uservalidationbyadmin_cron_hook($hook, $type, $return_value, $params) { $notify_admins = uservalidationbyadmin_get_admin_notification_setting(); if (empty($notify_admins) || $notify_admins !== $type) { return $return_value; } // notify the admins about pending approvals uservalidationbyadmin_notify_admins(); return $return_value; }