add_action('wpcf7_before_send_mail', 'custom_handle_cf7_submission');
function custom_handle_cf7_submission($contact_form) {
$submission = WPCF7_Submission::get_instance();
if (!$submission) return;
$posted_data = $submission->get_posted_data();
// CSVファイルのパス(wp-content以下に保存)
$upload_dir = wp_upload_dir();
$csv_file = $upload_dir['basedir'] . '/cf7-submissions.csv';
// ヘッダーがなければ書き込む(初回のみ)
if (!file_exists($csv_file)) {
$headers = array_keys($posted_data);
file_put_contents($csv_file, implode(",", $headers) . "\n", FILE_APPEND);
}
// データを追記
$values = array_map(function ($value) {
return '"' . str_replace('"', '""', $value) . '"'; // CSVエスケープ
}, $posted_data);
file_put_contents($csv_file, implode(",", $values) . "\n", FILE_APPEND);
// 「異常あり」のときだけメール送信
if (isset($posted_data['radio-situation']) && $posted_data['radio-situation'] === '異常あり') {
$contact_form->skip_mail = false; // メール送信を有効化
}
}
Warning: Cannot modify header information - headers already sent by (output started at /home/elmers-fc/www/wp/wp-content/themes/elmers-fc/functions.php:1) in /home/elmers-fc/www/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /home/elmers-fc/www/wp/wp-content/themes/elmers-fc/functions.php:1) in /home/elmers-fc/www/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /home/elmers-fc/www/wp/wp-content/themes/elmers-fc/functions.php:1) in /home/elmers-fc/www/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /home/elmers-fc/www/wp/wp-content/themes/elmers-fc/functions.php:1) in /home/elmers-fc/www/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /home/elmers-fc/www/wp/wp-content/themes/elmers-fc/functions.php:1) in /home/elmers-fc/www/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /home/elmers-fc/www/wp/wp-content/themes/elmers-fc/functions.php:1) in /home/elmers-fc/www/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /home/elmers-fc/www/wp/wp-content/themes/elmers-fc/functions.php:1) in /home/elmers-fc/www/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1896
Warning: Cannot modify header information - headers already sent by (output started at /home/elmers-fc/www/wp/wp-content/themes/elmers-fc/functions.php:1) in /home/elmers-fc/www/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1896
{"id":21872,"date":"2025-03-16T15:48:56","date_gmt":"2025-03-16T06:48:56","guid":{"rendered":"http:\/\/elmers-fc.com\/wp\/wp-content\/uploads\/2025\/03\/20250308-154511-Original.jpg"},"modified":"2025-03-16T15:55:32","modified_gmt":"2025-03-16T06:55:32","slug":"20250308-154511-original","status":"inherit","type":"attachment","link":"https:\/\/elmers-fc.com\/wp\/?attachment_id=21872#main","title":{"rendered":"20250308-154511-Original"},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"jetpack_post_was_ever_published":false},"class_list":["post-21872","attachment","type-attachment","status-inherit","hentry"],"jetpack_shortlink":"https:\/\/wp.me\/a4wVxl-5GM","jetpack_sharing_enabled":true,"description":{"rendered":"