ちなみにfunctionにはcontactform7にカスタム投稿で作った項目の値を挿入させるためのものです。
コードは以下になります。
add_filter('wpcf7_special_mail_tags', 'my_special_mail_tags',10,2);
function my_special_mail_tags($output, $name)
{
//UAとIPを追加
if(!isset($re_agent)){ $re_agent = $_SERVER['HTTP_USER_AGENT']; }
if('user_agent' == $name){ $output = $re_agent; }
if(!isset($re_addr)){ $re_addr = $_SERVER['REMOTE_ADDR']; }
if('remote_addr' == $name){ $output = gethostbyaddr($re_addr); }
//特別なタグを追加
if ( ! isset( $_POST['_wpcf7_unit_tag'] ) || empty( $_POST['_wpcf7_unit_tag'] ) )
return $output;
if ( ! preg_match( '/^wpcf7-f(\d+)-p(\d+)-o(\d+)$/', $_POST['_wpcf7_unit_tag'], $matches ) )
return $output;
$post_id = (int) $matches[2];
if ( ! $post = get_post( $post_id ) )
return $output;
$name = preg_replace( '/^wpcf7\./', '_', $name );
if ( 'showdate_check' == $name )
$output = get_post_meta($post->ID,showdate,true);
if ( 'showplace_check' == $name )
$output = get_post_meta($post->ID,showplace,true);
return $output;
}