Mail this for wordpress

Last changed: August 29, 2014 Comments: 1

This plugin gives your visitors the opportunity to mail themselfs the published article they are reading on your website. Since wordpress is used for many many different purposes, i thought it would be a bad idea to decide for you what kind of content you allow to be emaild to your visitors. The plugin will simply get the whole content which has been stored in the database, without any manipulations, except for the translation of HTML entities to their applicable characters. However, you are able to manipulate the content before sending the email. Therefore you can call the method “DoFunctions”, and supply the functions in an array as parameter.
Please note that the method “TheForm” must be called at last.

Callable methods

  • Constructor (Instance = mandatory)
  • FormMessages (Overwrite default messages)
  • DoFunctions (Perform default functions on the post content before sending the email)
  • AntiBot (Simple math calculation)
  • TheForm (Show the form)

Default style classes (span)

  • error
  • ok

How to use?
Just upload this plugin as you are used to and activate it.
When you did activate the plugin you might open your single.php (or whatever file you use to display your posts) and paste the below PHP code somewhere in this page.

<?php
if (class_exists('Os_MailTheContent')){

}
?>

The above piece of PHP code will check if the class exists (did you activate the plugin ?).

Creating the instance
Next you have to create an instance of the class like this:

<?php
if (class_exists('Os_MailTheContent')){
$mail = new Os_MailTheContent(); // Create instance so the feature can be used
$mail = new Os_MailTheContent(true); // Force visitors to be logged on before using this feature
}
?>

Right here you have some options, which controls the form and core functionality.

The messages
The default messages are like this:

<?php
    // Default messages
    private $mail_messages      = array(    'mail_send_error'       =>  '<span class="error">Something went wrong during the mail attempt.</span>',
                                            'mail_check_error'      =>  '<span class="error">The given email address did not pass the validator.</span>',
                                            'anti_bot_error'        =>  '<span class="error">Wrong answer on the calculation.</span>',
                                            'mail_send'             =>  '<span class="ok">Successfully send!</span>',
                                            'not_logged_on'         =>  '<span class="error">Please logon before using this feature</span>'
                                            );
?>

You can overwrite them, if you use the following piece of code.

<?php
if (class_exists('Os_MailTheContent')){
$mail = new Os_MailTheContent(); // Create instance so the feature can be used
$mail->FormMessages(    array(  'mail_send_error'   => 'The message if the email failed to send', 
                                                        'mail_check_error'  => 'The email did not pass the validator', 
                                                        'mail_send'         => 'If the email has been send',
                                                        'anti_bot_error'    => 'If the answer on the simple math question wasnt correct',
                                                        'not_logged_on'         =>  '<span class="error">If the used is not logged on.</span>'
                                                        ));
}
?>

Simple math calculation
The simple math calculation (anti-bot) is optional, so if you want to use the math calculation you have to add the following line as well.

<?php
$mail->AntiBot();
?>

Perform manipulations
You can run your own functions over the content of the article before sending the email like this.

<?php
$mail->DoFunctions(array('strip_shortcodes')); // Will be used by call_user_func() (must be an array)
?>

The form
The last call for a important class method will be calling the actual form. Without this call, no form will be shown.

<?php
$mail->TheForm();
?>

Complete example

                <?php
                    if (class_exists('Os_MailTheContent')){
                        ?><hr /><div id="mail-this-box"><h3>Mail this!</h3><?php
                        $mail = new Os_MailTheContent(true); // Create instance - Force user to be logged on
                        
                        $mail->FormMessages(    array(  'mail_send_error'   => 'Not send', 
                                                        'mail_check_error'  => 'Weird email syntax', 
                                                        'mail_send'         => 'Did send it!',
                                                        'anti_bot_error'    => 'lol, wrong answer',
                                                        'not_logged_on' => 'Please log on first!'
                                                        )); // Overwrite the default messages
                                                        
                        $mail->AntiBot(); // Call the simple calculation method
                        $mail->DoFunctions(array('strip_shortcodes')); // Perform some custom functions over the content
                        $mail->TheForm(); // Call the form
                        ?></div><?php
                    }
                    
                ?>  

Please keep the order of calling the methods like above, but you can leave one or more methods off course. Just keep “$mail->TheForm()” below on the list.

Version: 1.0:

  • Fixed: action atribute value URI
  • Fixed: HTML 5 compatible
Mail this for wordpress
Mail this for wordpress
send-me-a-copy-by-email.zip
3.2 KiB
Details...

Just tell us...