We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Hook to admin mail verify? | Forum

Topic location: Forum home » Support » General Questions
Marcus
Marcus Jan 3 '19

I would like to send email to user when their email have been verified by admin in admin panel.


I can do that by hacking into this like but I would really like to hook to it from a plugin please point me in the right direction?



else if ( isset($_POST['email_verify']) )
            {
                $userDtos = $userService->findUserListByIdList($users);
               
                foreach ( $userDtos as $dto )
                {
                    /* @var $dto BOL_User */
                    $dto->emailVerify = 1;
                    $userService->saveOrUpdate($dto);
                }

                OW::getFeedback()->info($language->text('admin', 'user_feedback_email_verified'));
            }



ADMIN_UserListParams

AppXprt
AppXprt Jan 3 '19
I'm not sure how the email notifications work as I haven't looked into it, but I am familiar with hooking into events from a plugin...

Look at some plugins with an event_handler.php in its classes directory..


So basically in the plugins event handler, you assign the events you want to hook into, to a custom function you write...


Here a plugin binds to the mailbox plugin to be able to send push notifications on new messages:


public function genericInit()    {        

OW::getEventManager()->bind('mailbox.ping', array($this, 'sendNotification'));  

}


This binds the sendNotification function to the mailbox.ping event so the sendNotification function executes along with anything else bound to that event.


Then some of the sendNotification function:


    public function sendNotification( OW_Event $event )

    {


        $eventParams = $event->getParams();

        $params = $eventParams['params'];


        if ($eventParams['command'] == 'mailbox_api_ping')

        {

            return $this->onApiPing($event);

        }


        if ($eventParams['command'] != 'mailbox_ping')

        {

            return;

        }


        if ( !OW::getUser()->isAuthenticated() )

        {

            $event->setData(array('error'=>"You have to sign in"));

            return;

}


        Blah Blah Blah...

        Command has been verified, User is Authenticated -> (Grab User?) Email Logic here

        (Email command verification will be different from all this)

}


You'll likely need to reverse your specific event_handler to create your event handler and event function.


Here is the important part... 


While you are developing, you're bound to break stuff and if you break something after binding to a certain event, it will break that event and all functions tied to it usually, until you get your function code fixed... 


So don't panic if the event (emails?) stop working after you bind to the event and start coding your custom event function.

Just keep working through it to find and fix your bugs and chances are your event will start working again once everything in your custom function is right.

The Forum post is edited by AppXprt Jan 3 '19
Marcus
Marcus Jan 4 '19
Thanks so much for your reply. Do you think a could catch ADMIN_UserListParams $_POST['email_verify'] event with event_handler.php?  Do I have to create a folder called Admin inside of wich put another folder called class with event_nandler.php in it?
AppXprt
AppXprt Jan 4 '19
Take a look at multiple free plugins for their file structure and layout.

There are certain procedures that must be followed when creating a plugin.


Here is a skeleton plugin that I was able to learn some from:

https://developers.oxwall.com/store/item/695


This is the plugin I used to reverse engineer how to hook into Oxwall events:

https://github.com/oxwall/mailbox


Specifically this event_handler.php:

https://github.com/oxwall/mailbox/blob/master/classes/event_handler.php


Notice in my post above, I only hook into 1 event, but you can see multiple events are defined in:

public function genericInit()


Same should be for whatever plugin/event you're trying to hook into.


I suggest downloading multiple plugin zip's and looking at all their internals for similarities and differences to know what is commonly included in plugins.


I am thinking about putting all the helpful info I've been given by Dave and other dev's in a plugin howto.


You can do it, trust yourself, don't give up and just keep trying...


Development is all trial and error until you get the hang of it!

The Forum post is edited by AppXprt Jan 4 '19
Marcus
Marcus Jan 5 '19

Amazing! Thanks so much that will teach me a lot! Happey new year.


P.S. Most of the plugins I created I used reverse engineering :)

The Forum post is edited by Marcus Jan 5 '19