From 89bc8f692f111912e0ba6606bf9c77f301d5305a Mon Sep 17 00:00:00 2001 From: Ross McKay Date: Sun, 22 Jun 2014 11:12:55 +1000 Subject: [PATCH] warn when wp_mail() is already declared; add plugin admin links and fix some other links --- .gitignore | 2 ++ disable-emails.php | 14 +++++---- includes/class.DisableEmailsPlugin.php | 39 ++++++++++++++++++++++++-- languages/disable-emails.pot | 27 ++++++++++++++++-- readme.md | 12 ++++++++ readme.txt | 17 +++++++---- views/warn-already-defined.php | 4 +++ 7 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 .gitignore create mode 100644 readme.md create mode 100644 views/warn-already-defined.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c7871c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.svn +languages/disable-emails.mo diff --git a/disable-emails.php b/disable-emails.php index 05bfd1b..0a340bf 100644 --- a/disable-emails.php +++ b/disable-emails.php @@ -1,14 +1,17 @@ wpmail($to, $subject, $message, $headers, $attachments); } + DisableEmailsPlugin::setActive(); + } diff --git a/includes/class.DisableEmailsPlugin.php b/includes/class.DisableEmailsPlugin.php index 85c98a0..181ab8c 100644 --- a/includes/class.DisableEmailsPlugin.php +++ b/includes/class.DisableEmailsPlugin.php @@ -7,6 +7,8 @@ class DisableEmailsPlugin { public $options; + protected $wpmailReplaced = false; + /** * static method for getting the instance of this singleton object * @return self @@ -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/'); } /** @@ -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[] = '' . __('Get help', 'disable-emails') . ''; + $links[] = '' . __('Rating', 'disable-emails') . ''; + $links[] = '' . _x('Translate', 'translate from English', 'disable-emails') . ''; + $links[] = '' . __('Donate', 'disable-emails') . ''; + } + 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; + } + +} diff --git a/languages/disable-emails.pot b/languages/disable-emails.pot index fac8faf..63993b6 100644 --- a/languages/disable-emails.pot +++ b/languages/disable-emails.pot @@ -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 \n" "Language-Team: \n" "Language: en_US\n" @@ -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 "" @@ -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 "" diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..de20805 --- /dev/null +++ b/readme.md @@ -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/) diff --git a/readme.txt b/readme.txt index 04660e3..999c6ee 100644 --- a/readme.txt +++ b/readme.txt @@ -1,13 +1,13 @@ === 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 @@ -15,7 +15,7 @@ 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: @@ -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. @@ -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 diff --git a/views/warn-already-defined.php b/views/warn-already-defined.php new file mode 100644 index 0000000..8614483 --- /dev/null +++ b/views/warn-already-defined.php @@ -0,0 +1,4 @@ + +
+

+