/** * Listen to the join site event and check for email subscriptions * * @param string $event What event was fired * @param string $type What was the type of event * @param ElggRelationship $object The relationship object, containing the user and site * * @return void */ function newsletter_join_site_event_handler($event, $type, $object) { if (!empty($object) && $object instanceof ElggRelationship) { $user = get_user($object->guid_one); if (!empty($user)) { $subscription = newsletter_get_subscription($user->email); if (!empty($subscription)) { newsletter_convert_subscription_to_user_setting($subscription, $user); } } } }
/** * Check if there is a email subscription for the user's email address * If so, convert the settings to the user and remove the email subscription * * @param string $hook Which hook was triggered * @param string $type What was the type of hook * @param array $returnvalue null * @param array $params null * * @return void */ public static function convertEmailSubscriptionToUserSetting($hook, $type, $returnvalue, $params) { $user_guid = (int) get_input('guid'); $user = get_user($user_guid); if (empty($user)) { return; } $subscription = newsletter_get_subscription($user->email); if (!empty($subscription)) { newsletter_convert_subscription_to_user_setting($subscription, $user); } }
/** * Listen to the join site event and check for email subscriptions * * @param string $event What event was fired * @param string $type What was the type of event * @param ElggRelationship $object The relationship object, containing the user and site * * @return void */ public static function join($event, $type, $object) { if (!$object instanceof \ElggRelationship) { return; } if ($object->relationship !== 'member_of_site') { return; } $user = get_user($object->guid_one); if (empty($user)) { return; } $subscription = newsletter_get_subscription($user->email); if (!empty($subscription)) { newsletter_convert_subscription_to_user_setting($subscription, $user); } }
/** * Check if there is a email subscription for the user's email address * If so, convert the settings to the user and remove the email subscription * * @param string $hook Which hook was triggered * @param string $type What was the type of hook * @param array $returnvalue null * @param array $params null * * @return void */ function newsletter_usersettings_save_handler($hook, $type, $returnvalue, $params) { $user_guid = (int) get_input("guid"); $user = get_user($user_guid); if (!empty($user)) { $subscription = newsletter_get_subscription($user->email); if (!empty($subscription)) { newsletter_convert_subscription_to_user_setting($subscription, $user); } } }