Store
Community Documentation

v3 Knowledgebase

Overriding user notification (email) settings

I have recently been looking into how to override notification settings that either have been left over from the default 'email everything' settings or ones that users have set that over tax our systems. For new users notification settings, the best bet is to buy my inexpensive ($10) "Preset new users" mod.

But that will not do anything for the many users that are already members of your site. To deal with those members, we would either have to create a LOT of notification records or find a way to spoof the system into doing what we, as admins, want.

I struggled with this today and I may have a solution.

First, I need a way of communicating to Phpfox the settings that we wish to use. For this I decided to use the settings in the "Preset new members" addon. Otherwise I would have to write a new interface and that would not be fun.

Next, I need to find a block of code that is common to all notifications. I found this in the include/library/phpfox/mail/mail.class.php file.

In the send mail function down around line 394 there is a plugin hook called 'mail_send_query'. This happens to occur right after some code that sets the notification table stuff and right before the call to get the user record(s). This is good in that it is in the right area. It is bad in that the notification table stuff is already set. My solution to this was to call the Phpfox::getLib('database')->clean() command. The result is that the previous notification table setup is discarded and the sql would call just the user data.

But we still want a notification field. Just not the one that would have been provided. I was able to facilitate this with the code:
PHP:
Phpfox::getLib('database')->select("'" $this->_sNotification"' as user_notification, "); 


And make that code conditional on the settings in the Preset new users addon.

So now all we need to do is gather the new code and place it in the admincp->extensions->plugins->create new plugin. I set it up like this:

Product: Preset New Members Settings
Module: Userpresets
Title: Force Userpreset Notification Settings
Hook: mail_send_query
Active: yes

In the code block I used this code:
PHP:
if(phpFox::isModule('Userpresets') && $this->_sNotification !== null)
{
    
Phpfox::getLib('database')->clean();

    
$sAcpSetting str_replace('.''__'$this->_sNotification);
    
$sSetRef 'userpresets.' $sAcpSetting;

    if(
Phpfox::getLib('setting')->isParam($sSetRef) && !Phpfox::getParam($sSetRef))
    {
        
Phpfox::getLib('database')->select("'" $this->_sNotification"' as user_notification, ");
    }



With all of this in place and the cache cleared (as always), the system should send or not send an email for any action based upon what you have set into the Preset new users settings. The user's settings will be ignored. To switch back to using the user's settings, just disable the plugin.

This code will not work unless you have the Preset new users addon and it is active. Also it has been tested for operation but not exhaustively tested for side effects, so if you use this code, do so with caution.

web