80 public function send( $to, $subject =
false, $from =
'', $placeholders = array() ) {
85 if ( is_numeric( $this->from ) ) {
86 $user =
new WP_User( $from );
87 $this->from = sprintf(
'%s <%s>', $user->data->display_name, $user->get(
'user_email' ) );
91 if ( empty( $this->from ) ) {
93 $this->from = sprintf(
'%s <%s>', get_option(
'blogname' ), get_option(
'admin_email' ) );
98 if ( is_numeric( $to ) ) {
99 $user =
new WP_User( $to );
100 $email = sanitize_email( $user->get(
'user_email' ) );
103 if ( empty( $email ) ) {
106 $to = sprintf(
' %s <%s>', $user->data->display_name, $user->get(
'user_email' ) );
109 if ( $subject ===
false ) {
110 $subject = apply_filters(
'the_title', $this->post_title );
115 $body = $this->replacePlaceholder( $body, $user, $placeholders );
117 return wp_mail( $to, $subject, $body, $this->headers() );
127 private function headers()
131 'From: ' . $this->from,
132 'Content-Type: text/html'
136 if ( !empty( $this->cc ) ) {
137 $this->cc = explode(
',', $this->cc );
138 foreach ( $this->cc as $email ) {
139 $headers[] = sprintf(
'Cc: %s', $email );
143 if ( !empty( $this->bcc ) ) {
144 $this->bcc = explode(
',', $this->bcc );
145 foreach ( $this->bcc as $email ) {
146 $headers[] = sprintf(
'Bcc: %s', $email );
150 $headers = apply_filters(
'wpdk_mail_headers', $headers );
152 return implode(
"\r\n", $headers );
167 private function replacePlaceholder( $content, $id_user =
false, $extra = array() ) {
169 if (
false === $id_user ) {
170 $id_user = get_current_user_id();
171 $user =
new WP_User( $id_user );
173 elseif ( is_object( $id_user ) && is_a( $id_user,
'WP_User' ) ) {
176 elseif ( is_numeric( $id_user ) ) {
177 $user =
new WP_User( $id_user );
183 $str_replaces = array(
190 if ( !empty( $extra ) ) {
191 $str_replaces = array_merge( $str_replaces, $extra );
194 $str_replaces = apply_filters(
'wpdk_mail_replace_placeholders', $str_replaces, $id_user );
196 $content = strtr( $content, $str_replaces );
228 $placeholders = array(
229 self::USER_FIRST_NAME => array(
230 __(
'User First name', WPDK_TEXTDOMAIN ),
233 self::USER_LAST_NAME => array(
234 __(
'User Last name', WPDK_TEXTDOMAIN ),
237 self::USER_DISPLAY_NAME => array(
238 __(
'User Display name', WPDK_TEXTDOMAIN ),
241 self::USER_EMAIL => array(
242 __(
'User email', WPDK_TEXTDOMAIN ),
247 return apply_filters(
'wpdk_mail_placeholders', $placeholders );