Skip to content

Commit

Permalink
warn when wp_mail() is already declared; add plugin admin links and f…
Browse files Browse the repository at this point in the history
…ix some other links
  • Loading branch information
webaware committed Jun 22, 2014
1 parent f73f527 commit 89bc8f6
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.svn
languages/disable-emails.mo
14 changes: 9 additions & 5 deletions disable-emails.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php
/*
Plugin Name: Disable Emails
Plugin URI: http://shop.webaware.com.au/downloads/disable-emails/
Description: Stop WordPress from sending any emails. ANY!
Version: 1.2.0
Version: 1.2.1
Author: WebAware
Author URI: http://www.webaware.com.au/
Author URI: http://webaware.com.au/
Text Domain: disable-emails
Domain Path: /languages/
*/

/*
copyright (c) 2014 WebAware Pty Ltd (email : rmckay@webaware.com.au)
copyright (c) 2014 WebAware Pty Ltd (email : support@webaware.com.au)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand All @@ -34,9 +37,8 @@
define('DISABLE_EMAILS_OPTIONS', 'disable_emails');
}

include DISABLE_EMAILS_PLUGIN_ROOT . 'includes/class.DisableEmailsPlugin.php';
include DISABLE_EMAILS_PLUGIN_ROOT . 'includes/class.DisableEmailsPHPMailerMock.php';

include DISABLE_EMAILS_PLUGIN_ROOT . 'includes/class.DisableEmailsPlugin.php';
DisableEmailsPlugin::getInstance();


Expand All @@ -49,4 +51,6 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
return $mailer->wpmail($to, $subject, $message, $headers, $attachments);
}

DisableEmailsPlugin::setActive();

}
39 changes: 37 additions & 2 deletions includes/class.DisableEmailsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class DisableEmailsPlugin {

public $options;

protected $wpmailReplaced = false;

/**
* static method for getting the instance of this singleton object
* @return self
Expand Down Expand Up @@ -55,13 +57,15 @@ private function __construct() {
add_action('init', array($this, 'init'));
add_action('admin_init', array($this, 'adminInit'));
add_action('admin_menu', array($this, 'adminMenu'));
add_action('admin_notices', array($this, 'showWarningAlreadyDefined'));
add_filter('plugin_row_meta', array($this, 'addPluginDetailsLinks'), 10, 2);
}

/**
* init action
*/
public function init() {
load_plugin_textdomain('disable-emails', false, basename(dirname(__FILE__)) . '/languages/');
load_plugin_textdomain('disable-emails', false, basename(dirname(DISABLE_EMAILS_PLUGIN_FILE)) . '/languages/');
}

/**
Expand Down Expand Up @@ -110,6 +114,37 @@ public function settingsValidate($input) {
return $output;
}

}
/**
* action hook for adding plugin details links
*/
public function addPluginDetailsLinks($links, $file) {
if ($file == DISABLE_EMAILS_PLUGIN_NAME) {
$links[] = '<a href="http://wordpress.org/support/plugin/disable-emails">' . __('Get help', 'disable-emails') . '</a>';
$links[] = '<a href="http://wordpress.org/plugins/disable-emails/">' . __('Rating', 'disable-emails') . '</a>';
$links[] = '<a href="http://translate.webaware.com.au/projects/disable-emails">' . _x('Translate', 'translate from English', 'disable-emails') . '</a>';
$links[] = '<a href="http://shop.webaware.com.au/downloads/disable-emails/">' . __('Donate', 'disable-emails') . '</a>';
}

return $links;
}

/**
* warn that wp_mail() is defined so emails cannot be disabled!
*/
public function showWarningAlreadyDefined() {
if (!$this->wpmailReplaced) {
include DISABLE_EMAILS_PLUGIN_ROOT . 'views/warn-already-defined.php';
}
}

/**
* wp_mail() was successfully replaced, so we can activate disabling emails
*/
public static function setActive() {
include DISABLE_EMAILS_PLUGIN_ROOT . 'includes/class.DisableEmailsPHPMailerMock.php';

$plugin = self::getInstance();
$plugin->wpmailReplaced = true;
}

}
27 changes: 25 additions & 2 deletions languages/disable-emails.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ msgid ""
msgstr ""
"Project-Id-Version: disable-emails\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-04-19 10:24+1000\n"
"PO-Revision-Date: 2014-04-19 10:24+1000\n"
"POT-Creation-Date: 2014-06-22 11:05+1000\n"
"PO-Revision-Date: 2014-06-22 11:06+1000\n"
"Last-Translator: Ross McKay <[email protected]>\n"
"Language-Team: \n"
"Language: en_US\n"
Expand All @@ -22,6 +22,23 @@ msgstr ""
"X-Generator: Poedit 1.5.4\n"
"X-Poedit-SearchPath-0: ..\n"

#: ../includes/class.DisableEmailsPlugin.php:122
msgid "Get help"
msgstr ""

#: ../includes/class.DisableEmailsPlugin.php:123
msgid "Rating"
msgstr ""

#: ../includes/class.DisableEmailsPlugin.php:124
msgctxt "translate from English"
msgid "Translate"
msgstr ""

#: ../includes/class.DisableEmailsPlugin.php:125
msgid "Donate"
msgstr ""

#: ../views/settings-form.php:9
msgid "Disable Emails settings"
msgstr ""
Expand All @@ -33,3 +50,9 @@ msgstr ""
#: ../views/settings-form.php:19
msgid "call WordPress hooks so that listeners can act, e.g. log emails"
msgstr ""

#: ../views/warn-already-defined.php:3
msgid ""
"Emails are not disabled! Something else has already declared wp_mail(), so "
"Disable Emails cannot stop emails being sent!"
msgstr ""
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Disable Emails #

Stop WordPress from sending any emails. ANY!

* [Home](http://shop.webaware.com.au/downloads/disable-emails/)
* [GitHub](https://github.com/webaware/disable-emails/)
* [Readme](https://github.com/webaware/disable-emails/blob/master/readme.txt)
* [Download](http://wordpress.org/plugins/disable-emails/)
* [Documentation](http://wordpress.org/plugins/disable-emails/faq/)
* [Support](http://wordpress.org/support/plugin/disable-emails)
* [Translate](http://translate.webaware.com.au/projects/disable-emails)
* [Donate](http://shop.webaware.com.au/downloads/disable-emails/)
17 changes: 12 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
=== Disable Emails ===
Contributors: webaware
Plugin Name: Disable Emails
Plugin URI: http://wordpress.org/plugins/disable-emails/
Plugin URI: http://shop.webaware.com.au/downloads/disable-emails/
Author URI: http://webaware.com.au/
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3QCACKDYDV6VN
Donate link: http://shop.webaware.com.au/downloads/disable-emails/
Tags: disable emails, block emails
Requires at least: 3.6.1
Tested up to: 3.9
Stable tag: 1.2.0
Tested up to: 3.9.1
Stable tag: 1.2.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Stop WordPress from sending any emails. ANY!

== Description ==

Stop a WordPress website from sending any emails using the standard [wp_mail()]() function. No emails will be sent, not even for password resets or administrator notifications.
Stop a WordPress website from sending any emails using the standard [wp_mail()](http://codex.wordpress.org/Function_Reference/wp_mail) function. No emails will be sent, not even for password resets or administrator notifications.

WordPress websites can send emails for a variety of reasons -- e.g user registration, password reset, enquiry form submission, e-commerce purchase -- but sometimes you don't want it to send anything at all. Some reasons for disabling all emails:

Expand All @@ -24,6 +24,10 @@ WordPress websites can send emails for a variety of reasons -- e.g user registra
* bulk-loading data into websites which might trigger emails
* adding new sites into multisite installations

If you'd like to help out by translating this plugin, please sign up for an account and dig in:

* [translate.webaware.com.au/projects/edd-free-link](http://translate.webaware.com.au/projects/disable-emails)

== Installation ==

1. Either install automatically through the WordPress admin, or download the .zip file, unzip to a folder, and upload the folder to your /wp-content/plugins/ directory. Read [Installing Plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins) in the WordPress Codex for details.
Expand All @@ -47,6 +51,9 @@ Behind the scenes, it creates a private copy of PHPMailer and allows the system

== Changelog ==

= 1.2.1 [2014-06-22] =
* added: warn when wp_mail() can't be replaced, so admin knows that emails cannot be disabled

= 1.2.0 [2014-04-19] =
* changed: refactored to fully support filter and action hooks that other plugins might use to listen to and modify emails, e.g. so that email loggers can properly record what would have been sent

Expand Down
4 changes: 4 additions & 0 deletions views/warn-already-defined.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<div class="error">
<p><?php _e("Emails are not disabled! Something else has already declared wp_mail(), so Disable Emails cannot stop emails being sent!", 'disable-emails'); ?></p>
</div>

0 comments on commit 89bc8f6

Please sign in to comment.