2020-05-22 16:01:16

Related Docs

You have seen all Documentation regarding Send Email If.
Search the complete TukuToi Software Documentation!

Do You Need Help or Expertise?

Is editing Source Code not Your Thing? Are you in a tight Time Schedule and need to deliver a fully scalable and safe solution fast to your Clients?

Maybe you want to incorporate the Software found on TukuToi unbranded and royalty free in your Clients Projects after customizing it as per your Projects requirements?

Or eventually you need some training on any WordPress Plugin, Theme or their creation and maintenance?

How ToSend Email If

Configure and Customize the Send Email If logic

Usage

  1. Install and Activate the Send Email If Plugin like any other WordPress Plugin.
  2. Make sure every user has as Role the Role defined in the source code on line 15 in the send-email-if.php file:
    $role = '';
  3. Make sure each user also has a First Name and Last Name saved.
  4. Make sure every Post has a Email saved in the Email Address field.

Visit a Post while Logged In as a User of the role specified.

At this point an Email will be sent to the Address registered for the Post visited containing the below details.

E Mail Contents

Visit detected!

Hello, {User First And Last Name} has just visited {Post Title}.

How To Amend These Contents

  1. Source Code needs to be edited to change the Email Contents
  2. The file to be edited is send-email-if.php on line 70 the content is built.
  3. That code is a mix of strings which can be edited at liberty, while $current_user-> will define the data that is sent and are Dynamic. These Variables are built using the WordPress API, hence understanding of the WordPress API and User Object is required to amend those. 
    $content = 'Hello, '.$current_user->first_name.' '.$current_user->last_name.' has just visited '.$post-→post_title;
  4. On Line 85 the Subject of the Email is built
    $subject = "Visit detected!";

Plugin Structure and Methods

The plugin is built in 2 files and a Read me.

In the send-email-if.php file, starting with the usual WordPress Plugin Opening Comment, followed by a security check to avoid direct access, we go straight to the functions for the feature. 

Last, in the Bootstrap section we fire all the defined functions on different places of the website (to be precise, in the add_meta_boxes, save_post, wp_footer hooks)

Below the single functions outlined. This might be helpful for any future troubleshooting or tweaking.

I. tkt_sei_register_meta_boxes

This function adds the “box” to the Post Edit screen, where the Email can be added. If this box ever needs to be “disabled”, on line 94 of the file here simply add two dashes (//) like so at the start of the line, and save
//add_action( 'add_meta_boxes', 'tkt_sei_register_meta_boxes' );

II. tkt_sei_save_meta_box

The previous function added the box, this function saves its contents to the database. If the Parent Email Address ever does not save to the database, this is the first place to look for issues. The function can be disabled as well by putting two dashes (//) in front of line 96, like so
//add_action( 'save_post', 'tkt_sei_save_meta_box' );

III. tkt_sei_get_queried_object

This is the core logic that listens to the events on the website, and when a Coach logs in, and visits a single post where an email is saved as Parent Email Address, will gather all data of the Coach and Player, and bundle it for the email. This is the core functionality that gathers the data for the emails sent. If this ever needs to be disabled, you can add two dashes (//) like seen above to line 98 like so
//add_action( 'wp_footer', 'tkt_sei_get_queried_object' );

IV. tkt_sei_send_mail

tkt_sei_send_mail Finally this is where the Email is sent with all data from point III above. It is a short function that simply calls the WordPress native wp_mail() function and passes all data gathered to it. wp_mail() is very reliable as everything in WordPress Core. This function is fired only if number III is fired, hence, we usually won’t need to disable it. But if only the mailer should be stopped for some reason, but no other functionality, then inside this function line 86, by adding the known dashes (//) to disable the code, we can stop the mailer temporarily like so
//wp_mail( $receiver, $subject, $content);

V. metabox.php

metabox.php file is merely some CSS and HTML to create the Email box. That’s where the appearance of the Email Input in the backend, when editing the Players, can be amended with simple HTML and CSS.