diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9aa5f8d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.php] +indent_style = tab +indent_size = 4 + +[*.{markdown,md,mdown,txt}] +indent_size = 4 +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes index 412eeda..0b6acf1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,13 +10,13 @@ *.dbproj merge=union # Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain +*.doc diff=astextplain +*.DOC diff=astextplain *.docx diff=astextplain *.DOCX diff=astextplain *.dot diff=astextplain *.DOT diff=astextplain *.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..38f381e --- /dev/null +++ b/.gitignore @@ -0,0 +1,47 @@ +# Builds +/build +/docs + +# Numerous always-ignore extensions +*.diff +*.err +*.orig +*.log +*.rej +*.swo +*.swp +*.vi +*~ +*.sass-cache + +# OS or Editor folders +.DS_Store +Thumbs.db +.cache +.project +.settings +.tmproj +*.esproj +nbproject +*.sublime-project +*.sublime-workspace + +# Dreamweaver added files +_notes +dwsync.xml + +# Komodo +*.komodoproject +.komodotools + +# Package management +node_modules/ +vendor/ + +# Folders to ignore +.hg +.svn +.CVS +intermediate +.idea +cache diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..1b9a1eb --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "gforceweb/wp-email-debug", + "type": "wordpress-plugin", + "license": "GPL", + "description": "Never accidentally send users emails from your testing sites again!", + "homepage": "https://wordpress.org/plugins/wp-email-debug", + "authors": [ + { + "name": "Grant Derepas", + "homepage": "https://www.g-force.net" + } + ], + "keywords": [ + "wordpress" + ], + "support": { + "issues": "https://github.com/GForceWeb/WP-Email-Debug/issues" + }, + "require-dev": { + "dangoodman/composer-for-wordpress": "^1.0" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..82a67d6 --- /dev/null +++ b/composer.lock @@ -0,0 +1,48 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "a1a311ed33bc88c0d1a42a7fd466fcda", + "content-hash": "21f0d421b8975c98c259c00548a0a290", + "packages": [], + "packages-dev": [ + { + "name": "dangoodman/composer-for-wordpress", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/dangoodman/composer-for-wordpress.git", + "reference": "f7137989fd4b1be4b004dfd7d7bdec8e8d4c6a79" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dangoodman/composer-for-wordpress/zipball/f7137989fd4b1be4b004dfd7d7bdec8e8d4c6a79", + "reference": "f7137989fd4b1be4b004dfd7d7bdec8e8d4c6a79", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dangoodman\\ComposerForWordpress\\ComposerForWordpress" + }, + "autoload": { + "psr-4": { + "Dangoodman\\ComposerForWordpress\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "time": "2016-01-20 15:04:55" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/hooks.php b/hooks.php index f0ebe60..18d7ada 100644 --- a/hooks.php +++ b/hooks.php @@ -1,121 +1,131 @@ - - + + 'WPMDBUG-toolbar', - 'title' => 'Email Debug ON', - 'href' => get_admin_url(NULL, 'options-general.php?page=wpmdbug') - ); - $wp_admin_bar->add_node( $args ); - } + */ +function WPMDBUG_toolbar_link( $wp_admin_bar ) { + if ( WPMailDebugger::doEnforce() ) { + $args = array( + 'id' => 'WPMDBUG-toolbar', + 'title' => 'Email Debug ON', + 'href' => get_admin_url(NULL, 'options-general.php?page=wpmdbug' ) + ); + $wp_admin_bar->add_node( $args ); + } } /** * Add the WP Email Debug settings page to the options menu. + * * @since 1.0.0 * @return void - **/ -function WPMDBUG_settings_menu() -{ - add_options_page('E-Mail Debugger', 'E-Mail Debugger', 'manage_options', 'wpmdbug', 'WPMDBUG_settings_page'); + */ +function WPMDBUG_settings_menu() { + add_options_page( + 'E-Mail Debugger', + 'E-Mail Debugger', + 'manage_options', + 'wpmdbug', + 'WPMDBUG_settings_page' + ); } /** * Show the settings page. + * * @since 1.0.0 * @return void - **/ -function WPMDBUG_settings_page() -{ - require_once WPMDBUG_PATH . 'settings.php'; + */ +function WPMDBUG_settings_page() { + require_once WPMDBUG_PATH . 'settings.php'; } /** * Process posted data from the settings page. + * * @since 1.0.0 * @return void - **/ -function WPMDBUG_handle_settings() -{ - global $WPMDBUGerror; - if (isset($_POST['wpmdbug_submit'])) { - - if (isset($_POST['wpmdbug_enabled'])) { - update_option('WPMDBUG_enabled', TRUE); - } else { - update_option('WPMDBUG_enabled', FALSE); - } - - $newEmail = $_POST['wpmdbug_sendto']; - $newEmail = filter_var($newEmail, FILTER_VALIDATE_EMAIL); - - if ($newEmail === FALSE) { - $WPMDBUGerror = "Invalid Email Address"; - } else { - update_option('WPMDBUG_email', $newEmail); - } - - $debug_scope = $_POST['wpmdbug_scope']; - - if ($debug_scope == 2) { - if (isset($_POST['targetplugins']) && is_array($_POST['targetplugins']) && count($_POST['targetplugins']) > 0) { - update_option('WPMDBUG_plugins', $_POST['targetplugins']); - } else { - $WPMDBUGerror = 'You need to select at least one plugin for the plugin-specific redirect'; - } - } else { - update_option('WPMDBUG_plugins', array()); - } - - } + */ +function WPMDBUG_handle_settings() { + global $WPMDBUGerror; + + if ( ! isset( $_POST[ 'wpmdbug_submit' ] ) ) { + return; + } + + if ( isset( $_POST[ 'wpmdbug_enabled' ] ) ) { + update_option( 'WPMDBUG_enabled', true ); + } else { + update_option( 'WPMDBUG_enabled', false ); + } + + $newEmail = $_POST[ 'wpmdbug_sendto' ]; + $newEmail = filter_var( $newEmail, FILTER_VALIDATE_EMAIL ); + + if ( $newEmail === false ) { + $WPMDBUGerror = 'Invalid Email Address'; + } else { + update_option( 'WPMDBUG_email', $newEmail); + } + + $debug_scope = $_POST[ 'wpmdbug_scope' ]; + + if ( $debug_scope === 2 ) { + if ( isset( $_POST[ 'targetplugins' ] ) && is_array( $_POST[ 'targetplugins' ] ) && count( $_POST[ 'targetplugins' ] ) > 0 ) { + update_option( 'WPMDBUG_plugins', $_POST[ 'targetplugins' ] ); + } else { + $WPMDBUGerror = 'You need to select at least one plugin for the plugin-specific redirect'; + } + } else { + update_option( 'WPMDBUG_plugins', array() ); + } + } /** * Add error messages to admin notices. + * * @since 1.0.0 * @return void - **/ -function WPMDBUG_admin_notices() -{ - global $WPMDBUGerror; - if (!empty($WPMDBUGerror)) { - ?> -
-

-
-

%s

', + $WPMDBUGerror + ); + } + } diff --git a/settings.php b/settings.php index b3704dc..cbe7c2c 100644 --- a/settings.php +++ b/settings.php @@ -1,85 +1,85 @@ 0); +$scopes = get_option( 'WPMDBUG_plugins', array() ); +$scope = ( is_array( $scopes ) && count( $scopes ) > 0 ); -if (!function_exists('get_plugins')) { +if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $plugins = get_plugins(); ?>
-

E-Mail Debugger Settings

-
- - - - - - - - - - - - - - - - - - - -
Enable E-Mail Debugging - -
Redirect E-Mails To - -
  - -
- -
Select Plugins - - - - - - $pdata): if (stripos($plugin, 'wp-mail-debugger.php') !== FALSE) {continue;} ?> - - - - - - -
- /> Select All -
/>
-
-

-
+

E-Mail Debugger Settings

+
+ + + + + + + + + + + + + + + + + + + +
Enable E-Mail Debugging + +
Redirect E-Mails To + +
  + +
+ +
Select Plugins + + + + + + $pdata): if ( stripos( $plugin, 'wp-mail-debugger.php' ) !== FALSE ) { continue; } ?> + + + + + + +
+ /> Select All +
/>
+
+

+
diff --git a/wp-email-debug.php b/wp-email-debug.php index ad2bf47..61f3acb 100644 --- a/wp-email-debug.php +++ b/wp-email-debug.php @@ -8,102 +8,122 @@ * Author URI: https://www.g-force.net */ -if (!defined('ABSPATH')) { - exit(); +if ( ! defined( 'ABSPATH' ) ) { + exit(); } -if (!class_exists('WPMailDebugger')): - - final class WPMailDebugger - { - - private static $instance; - - public static function instantiate() - { - if (!isset(self::$instance) && !self::$instance instanceof WPMailDebugger) { - self::$instance = new WPMailDebugger; - self::$instance->includes(); - } - return self::$instance; - } - - public function includes() - { - - if (!defined('WPMDBUG_PATH')) { - define( 'WPMDBUG_PATH', plugin_dir_path( __FILE__ ) ); - } - - require_once WPMDBUG_PATH . 'hooks.php'; - } - - /** - * Returns true if the debugger is enabled in the plugin's settings. - * @since 1.0.0 - * @return boolean - */ - public static function doEnforce() - { - $enforce = get_option('WPMDBUG_enabled', FALSE); - if ($enforce) { - return TRUE; - } else { - return FALSE; - } - } - - /** - *Returns true if a switch of the email address should be performed, else false. - *@since 1.0.0 - *@return boolean - */ - public static function contextualSwitch() - { - $scope = get_option("WPMDBUG_plugins", array()); - - if (is_array($scope) && count($scope) > 0) { - // A switch depends on selected plugins - $trace = debug_backtrace(); - - foreach ($scope as $sco) { - $plugin_filename = str_replace('\\', '/', WP_PLUGIN_DIR . '/' . $sco); - - foreach ($trace as $call) { - if (isset($call['file'])) { - if ($plugin_filename == str_replace('\\', '/', $call['file']) || stripos($call['file'], dirname($plugin_filename)) !== FALSE) { - return TRUE; - } - } - } - } - return FALSE; - } else { - return TRUE; - } - } - - public static function filterEmail( $args ) - { - $to_address = get_option('WPMDBUG_email', get_bloginfo('admin_email')); - $original = $args['to']; - - if (self::contextualSwitch()) { - $args['to'] = $to_address; - $args['subject'] = '[DEBUG] ' . $args['subject']; - $args['message'] = "Originally intended to be sent to " . $original . "\n" . $args['message']; - } - - return $args; - } - - } - - function WPMDBUG_start() - { - return WPMailDebugger::instantiate(); - } - - WPMDBUG_start(); - -endif; +if ( ! class_exists( 'WPMailDebugger' ) ) { + + final class WPMailDebugger { + + private static $instance; + + public static function instantiate() { + if ( ! isset( self::$instance ) && ! self::$instance instanceof WPMailDebugger ) { + self::$instance = new WPMailDebugger; + self::$instance->includes(); + } + return self::$instance; + } + + public function includes() { + + if ( ! defined( 'WPMDBUG_PATH' ) ) { + define( 'WPMDBUG_PATH', plugin_dir_path( __FILE__ ) ); + } + + require_once WPMDBUG_PATH . 'hooks.php'; + } + + /** + * Returns true if the debugger is enabled in the plugin's settings. + * + * @since 1.0.0 + * @return boolean + */ + public static function doEnforce() { + return apply_filters( 'wp_email_debug_enabled', get_option( 'WPMDBUG_enabled', false ) ); + } + + /** + * Returns true if a switch of the email address should be performed, else false. + * + * @since 1.0.0 + * @return boolean + */ + public static function contextualSwitch() { + + $scope = get_option( 'WPMDBUG_plugins', array() ); + + if ( is_array( $scope ) && count( $scope ) > 0 ) { + + // A switch depends on selected plugins + $trace = debug_backtrace(); + + foreach ( $scope as $sco ) { + $plugin_filename = str_replace( '\\', '/', WP_PLUGIN_DIR . '/' . $sco ); + + foreach ( $trace as $call ) { + if ( isset( $call[ 'file' ] ) ) { + if ( $plugin_filename == str_replace( '\\', '/', $call[ 'file' ] ) || stripos( $call[ 'file' ], dirname( $plugin_filename ) ) !== false ) { + return true; + } + } + } + } + + return false; + } + + return true; + } + + public static function filterEmail( $args ) { + $isHtml = isset( $args[ 'html' ] ); + $prefix = ''; + $message = $isHtml ? $args[ 'html' ] : $args[ 'message' ]; + + if ( self::contextualSwitch() ) { + + // Prefix message + $prefix = sprintf( + __( 'Originally intended to be sent to %s', 'wp-email-debug' ), + $args[ 'to' ] + ); + + if ( ! empty( $prefix ) ) { + $prefix = $prefix . ( $isHtml ? '
' : '\n' ); + } + + // Update email to address + $args[ 'to' ] = get_option( 'WPMDBUG_email', get_bloginfo( 'admin_email' ) ); + + // Update email subject + $args[ 'subject' ] = sprintf( + __( '[DEBUG] %s', 'wp-email-debug' ), + $args[ 'subject' ] + ); + + } + + $message = $prefix . $message; + + if ( $isHtml ) { + $args[ 'html' ] = $message; + } + else { + $args[ 'message' ] = $message; + } + + return $args; + } + + } + + function WPMDBUG_start() { + return WPMailDebugger::instantiate(); + } + + WPMDBUG_start(); + +}