-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwp-email-debug.php
More file actions
109 lines (89 loc) · 2.55 KB
/
wp-email-debug.php
File metadata and controls
109 lines (89 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* Plugin Name: WP E-Mail Debug
* Plugin URI: https://wordpress.org/plugins/wp-email-debug
* Description: Never accidentally send users emails from your testing sites again!
* Version: 1.1.0
* Author: Grant Derepas
* Author URI: https://www.g-force.net
*/
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;