Torro Forms // Using torro()->email_notifications()

This page contains the technical documentation for the Torro Forms torro() functions and is written for developers. If you're not a developer you may want to review the Form Builder.

Base functions

There are some basic functions to handle email notifications with the torro() function. Here is a list of the most important functions.

    torro()->email_notifications()->create( $form_id, $args );
    torro()->email_notifications()->update( $notification_id, $args );
    torro()->email_notifications()->get( $notification_id );
    torro()->email_notifications()->delete( $notification_id );
    torro()->email_notifications()->exists( $notification_id );
    torro()->email_notifications()->copy( $notification_id, $form_id );

Create an email notification

Parameters

The create() function needs the parameter $form_id and $args. The parameter $args contains an array with the data for the email notification. The function will give back the form object or an WP_Error.

    
    $args = array(
        'notification_name'	=> 'Notification admin',
        'from_name'		=> 'Mr. Sender',
        'from_email'		=> 'from@emailaddress.xyz',
        'to_name'		=> 'Mr. Recipient',
        'to_email'		=> 'to@emailaddress.xyz',
        'subject'		=> 'Subject of the Mail',
        'message'		=> 'Message of the mail',
    );
    $email_notification = torro()->email_notifications()->create( $form_id, $args );

Return Values

You will get back a Torro_Email_Notification object by this function. To get the ID of the created email notification, get the variable of the object by using $email_notification->id. To catch all eventually occured errors, you have to check if $email_notification is a WP_Error and print out the error message.

    if( ! is_wp_error( $email_notification ) ) {
        $email_notification_id = $email_notification->id;
    } else {
        echo $email_notification->get_error_message();
    }

Update an email notification

Parameters

The update() function needs the parameters $email_notification_id and $args. The $args parameter contains an array with the data for the email notification. The function will give back the email notification object or an WP_Error.

    $args = array(
        'notification_name'	=> 'Notification admin',
        'from_name'		=> 'Mr. Sender',
        'from_email'		=> 'from@emailaddress.xyz',
        'to_name'		=> 'Mr. Recipient',
        'to_email'		=> 'to@emailaddress.xyz',
        'subject'		=> 'Subject of the Mail',
        'message'		=> 'Message of the mail',
    );
    $email_notification = torro()->containers()->update( $email_notification_id, $args );

Return Values

You will get back a Torro_Email_Notification object by this function. To get the ID of the created email notification, get the variable of the object by using $email_notification->id. To catch all eventually occured errors, you have to check if $email_notification is a WP_Error and print out the error message.

    if( ! is_wp_error( $email_notification ) ) {
        $email_notification_id = $email_notification->id;
    } else {
        echo $email_notification->get_error_message();
    }

Getting email notification data

Parameters

To get an email notification you can use the following code.

    $email_notification = torro()->email_notifications()->get( $email_notification_id );

Return Values

You will get back a Torro_Email_Notification object by this function. To get further information you can also use the deeper chained functions to access the container object parameters. Take a look at the autocomplete functionality of your programming IDE.

    $elements = torro()->email_notification()->get( $container_id )->elements;

To catch all eventually occured errors, you have to check if $email_notification is a WP_Error and print out the error message.

    if( ! is_wp_error( $email_notification ) ) {
        $email_notification_id = $email_notification->id;
    } else {
        echo $email_notification->get_error_message();
    }

Deleting an email notification

Parameters

Input the email_notification ID to the function delete.

    $deleted = torro()->email_notifications()->delete( $email_notification_id );

Return Values

To catch all eventually occured errors, you have to check if $deleted is a WP_Error and print out the error message.

    if( is_wp_error( $deleted ) ) {
        echo $deleted->get_error_message();
    }

Checking existance of an email notification

Parameters

Input the email notification ID to the function exists.

    torro()->email_notifications()->exists( $email_notification_id );

Return Values

The function returns true if the email notification exists and false if not.

Copy an email notification

Parameters

To copy a email notification from one form to another, put in the $email_notification_id which have to be copied and the $form_id where to copy the email notification. The email notification and all the content of the email_notification will be copied to the form.

    torro()->email_notifications()->copy( $email_notification_id, $form_id );

Return Values

The function return a Torro_Email_notification object or a WP_Error.

Fork me on GitHub