少々困難な質問かとは存じますが、すでにご経験済みの方などおられましたらどうかご教授ください。
ギャラリーにアップするだけでなく、ギャラリーを挿入して投稿を公開した際でしたら、以下のように変更するとメールへの添付が可能です。
1.「function mail()」を変更
function mail($recipients = array(), $subject = '', $message = '', $type='text') {
上記を次のようにします。
// function mail($recipients = array(), $subject = '', $message = '', $type='text') { function mail($recipients = array(), $subject = '', $message = '', $type='text', $attachment = array()) {
2.メール送信処理「@wp_mail()」を変更(※「} // end mail()」のすぐ前)
} else { $status = @wp_mail($this->myemail, $subject, $mailtext, $headers); } return $status; } // end mail()
上記を次のようにします。
} elseif( !empty($attachment) ) { $status = @wp_mail($this->myemail, $subject, $mailtext, $headers, $attachment); } else { $status = @wp_mail($this->myemail, $subject, $mailtext, $headers); } return $status; } // end mail()
3.画像を取得して、添付用の配列に入れる処理を追加します。(※「$gallid」「str_replace(">", ">", $content)」等、探し易いものを目印にしてください。)
$gallid = '[gallery id="' . $post->ID . '"'; $content = str_replace('[gallery', $gallid, $post->post_content); $content = apply_filters('the_content', $content); $content = str_replace("]]>", "]]>", $content); // ここから以降を追加 preg_match_all('#img.*?src="(.+?)"#', $content, $attach_arr, PREG_SET_ORDER); $cnt = count($attach_arr); for($n=0; $n<$cnt; $n++) { $attachment[] .= preg_replace('#^http://.+(wp-content/.+)$#', ABSPATH . '$1', $attach_arr[$n][1]); } // ここまで追加
4.「Plain Text - Excerpt」「Plain Text - Full」等、各メールを「$this->mail()」に渡す処理を変更します。(※「// first we send plaintext summary emails」等のコメントが目印になると思います。)
} else { // first we send plaintext summary emails $registered = $this->get_registered("cats=$post_cats_string&format=excerpt&author=$post->post_author"); if ( empty($registered) ) { $recipients = (array)$public; } elseif ( empty($public) ) { $recipients = (array)$registered; } else { $recipients = array_merge((array)$public, (array)$registered); } $this->mail($recipients, $subject, $excerpt_body); // next we send plaintext full content emails $this->mail($this->get_registered("cats=$post_cats_string&format=post&author=$post->post_author"), $subject, $full_body); // next we send html excerpt content emails $this->mail($this->get_registered("cats=$post_cats_string&format=html_excerpt&author=$post->post_author"), $subject, $html_excerpt_body, 'html'); // finally we send html full content emails $this->mail($this->get_registered("cats=$post_cats_string&format=html&author=$post->post_author"), $subject, $html_body, 'html'); } } // end publish()
上記を次のように変更します。
} else { // first we send plaintext summary emails $registered = $this->get_registered("cats=$post_cats_string&format=excerpt&author=$post->post_author"); if ( empty($registered) ) { $recipients = (array)$public; } elseif ( empty($public) ) { $recipients = (array)$registered; } else { $recipients = array_merge((array)$public, (array)$registered); } if(!empty($attachment)) { $this->mail($recipients, $subject, $excerpt_body, '', $attachment); } else { $this->mail($recipients, $subject, $excerpt_body); } // next we send plaintext full content emails if(!empty($attachment)) { $this->mail($this->get_registered("cats=$post_cats_string&format=post&author=$post->post_author"), $subject, $full_body, '', $attachment); } else { $this->mail($this->get_registered("cats=$post_cats_string&format=post&author=$post->post_author"), $subject, $full_body); } // next we send html excerpt content emails if(!empty($attachment)) { $this->mail($this->get_registered("cats=$post_cats_string&format=html_excerpt&author=$post->post_author"), $subject, $html_excerpt_body, 'html', $attachment); } else { $this->mail($this->get_registered("cats=$post_cats_string&format=html_excerpt&author=$post->post_author"), $subject, $html_excerpt_body, 'html'); } // finally we send html full content emails if(!empty($attachment)) { $this->mail($this->get_registered("cats=$post_cats_string&format=html&author=$post->post_author"), $subject, $html_body, 'html', $attachment); } else { $this->mail($this->get_registered("cats=$post_cats_string&format=html&author=$post->post_author"), $subject, $html_body, 'html'); } } } // end publish()
※テキストエディタ等で目印を検索して、編集箇所を探してください。(※上記の手順は、出現箇所の早い順番に変更するようになっています。)
※希望の動作と違ったり、もし上手く動作しないようでしたら、返信で教えてください。
お世話になります。もしもまだご覧になっておられましたら、お教えください。どうも、JPG画像以外の画像形式、GIFやPNGが添付できない世なのですが、どこを修正すればよいでしょうか?恐縮ですが、お教えくださいますと助かります。よろしくお願いします。
2012/01/29 16:58:29こちらでは問題なく添付されます。
2012/01/29 23:04:25ギャラリーへのアップは出来るのに、メールに添付されないという事でしょうか?
メールソフトの問題ではないかと思いますが、何というソフトを使用していますか?