-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwptt-email-logg.php
156 lines (129 loc) · 4.16 KB
/
wptt-email-logg.php
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/*
Plugin Name: WPTT Email Logging
Plugin URI: http://sfndesign.ca
Description: Stops all emails going out from WordPress and logs them.
Version: 1.3
Author: WP Theme Tutorial, Curtis McHale
Author URI: http://sfndesign.ca
License: GPLv2 or later
*/
/*
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if ( ! class_exists( 'WP_Logging' ) ){
require_once( plugin_dir_path( __FILE__ ) . 'WP_Logging.php' );
}
class WPTT_Email_Logging{
public function __construct(){
if ( $this->is_local() || $this->is_staging() ){
add_filter( 'wp_logging_post_type_args', array( $this, 'change_cpt_args' ) );
}
add_action( 'phpmailer_init', array( $this, 'mail_log' ), 9999 );
} // __construct
/**
* Allows the user to define local sites
*
* @since 1.3
* @author SFNdesign, Curtis McHale
* @access private
*
* @filter wptt_email_logging_is_local Allows other plugins to override internal settings
*/
private function is_local(){
return apply_filters( 'wptt_email_logging_is_local', false );
}
/**
* Allows the user to define staging sites
*
* @since 1.3
* @author SFNdesign, Curtis McHale
* @access private
*
* @filter wptt_email_logging_is_staging Allows other plugins to override internal settings
*/
private function is_staging(){
return apply_filters( 'wptt_email_logging_is_staging', false );
}
/**
* Allows the user to define live sites
*
* @since 1.3
* @author SFNdesign, Curtis McHale
* @access private
*
* @filter wptt_email_logging_is_live Allows other plugins to override internal settings
*/
private function is_live(){
return apply_filters( 'wptt_email_logging_is_live', false );
}
/**
* Logs emails coming out of wp_mail by hooking phpmailer_init
*
* @since 1.3
* @author SFNdesign, Curtis McHale
*
* @param array/obj $phpmailer required The PHP mailer object
*
* @return array/obj $phpmailer Our maybe modified PHPmailer object
*
* @uses $this->is_live() Returns true if we are on a defined live environment
*/
public function mail_log( $phpmailer ){
if ( $this->is_live() ) {
return $phpmailer;
} else {
$this->create_log( $phpmailer );
$phpmailer->ClearAllRecipients();
return $phpmailer;
}
} // mail_log
/**
* Creates our log in WP_Logging
*
* @since 1.3
* @author SFNdesign, Curtis McHale
* @access private
*
* @param array/obj $phpmailer required PHPmailer object
*
* @uses esc_attr() Keeping our email titles safe
* @uses wp_kses_post() Sanitizing content just like a WordPress post allows
* @uses WP_Logging::insert_log Inserts a log in WP_Logging
*/
private function create_log( $phpmailer ){
$subject = $phpmailer->Subject;
$content = $phpmailer->Body;
$log_data = array(
'post_title' => 'Logged WordPress email Subject: ' . esc_attr( $subject ) .' ',
'post_content' => wp_kses_post( $content ),
'log_type' => 'event',
);
$log_meta = array(
'phpmailer' => $phpmailer,
);
WP_Logging::insert_log( $log_data, $log_meta );
} // create_log
/**
* Changes the default WP_Logging CPT items so that the default is to show
* them in the WordPress admin.
*
* @since 1.0
* @author SFNdesign, Curtis McHale
*/
public function change_cpt_args( $args = array() ){
$args['public'] = true;
return $args;
} // change_cpt_args
} // WPTT_Email_Logging
$GLOBALS['wptt_basic_email_logging'] = new WPTT_Email_Logging();