Last active
September 3, 2015 16:03
-
-
Save BFTrick/9bd089bc53b11f7ac3fb to your computer and use it in GitHub Desktop.
Send an email when a page loads.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WooCommerce Send Email | |
* Plugin URI: https://gist.github.com/BFTrick/9bd089bc53b11f7ac3fb | |
* Description: Send an email when a page loads. Useful for testing email functionality. | |
* Author: Patrick Rauland | |
* Author URI: http://speakinginbytes.com/ | |
* Version: 1.0 | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
* | |
*/ | |
if ( ! class_exists( 'WC_Send_Email' ) ) : | |
class WC_Send_Email { | |
protected static $instance = null; | |
/** | |
* Initialize the plugin. | |
* | |
* @since 1.0 | |
*/ | |
private function __construct() { | |
if ( class_exists( 'WooCommerce' ) && class_exists( 'WC_Emails' ) ) { | |
// set subject | |
$subject = 'WC Send Mail Test'; | |
// load the mailer | |
$mailer = WC()->mailer(); | |
$mailer->send( get_option( 'admin_email' ), $subject, $mailer->wrap_message( $subject, 'a test message', true ), '', '' ); | |
} | |
} | |
/** | |
* Return an instance of this class. | |
* | |
* @return object A single instance of this class. | |
* @since 1.0 | |
*/ | |
public static function get_instance() { | |
// If the single instance hasn't been set, set it now. | |
if ( null == self::$instance ) { | |
self::$instance = new self; | |
} | |
return self::$instance; | |
} | |
} | |
add_action( 'admin_init', array( 'WC_Send_Email', 'get_instance' ), 0 ); | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment