Estoy tratando de hacer que un complemento de cámara web sea compatible con el formulario de contacto 7.
Este código me permite guardar la imagen de la cámara web directamente en la galería.
add_action('init','web_cam_form_submittion');
function web_cam_form_submittion(){
if(isset($_POST['web_cam_submit']))
{
$img = sanitize_text_field($_POST['image']);
if($_POST['slug']){
$slug = sanitize_text_field($_POST['slug']);
}
else{
$slug = "";
}
$base = dirname(__FILE__);
$folderPath = $base."/upload/";
$image_parts = explode(";base64,", $img);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$fileName = uniqid() . '.png';
$file_before_upload = $folderPath . $fileName;
file_put_contents($file_before_upload, $image_base64);
$image_url = $file_before_upload;
$upload_dir = wp_upload_dir();
$image_data = file_get_contents( $image_url );
$filename = basename( $image_url );
if ( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . "https://stackoverflow.com/" . $filename;
}
else {
$file = $upload_dir['basedir'] . "https://stackoverflow.com/" . $filename;
}
file_put_contents( $file, $image_data );
$wp_filetype = wp_check_filetype( $filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $file );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
wp_update_attachment_metadata( $attach_id, $attach_data );
unlink($file_before_upload);
if(has_action("web_cam_media_id")){
do_action("web_cam_media_id",array("media_id"=>$attach_id,"slug" =>$slug));
}
}
else{
return '';
}
}
Lo que quiero hacer es que la imagen capturada cuando envío el formulario me sea enviada como un correo electrónico (archivo adjunto).
¿Cómo puedo conseguir esto? Lo siento por mi mal inglés.
.