function custom_multi_image_upload_form_shortcode($atts) { // Récupérer le paramètre prefix du shortcode $atts = shortcode_atts(array( 'prefix' => 'envoi-' ), $atts); ob_start(); ?> Téléchargement en cours... Glissez-déposez vos images ici OU Sélectionner des images Télécharger les images $name) { if ($files['error'][$key] === UPLOAD_ERR_OK) { $file = [ 'name' => $files['name'][$key], 'type' => $files['type'][$key], 'tmp_name' => $files['tmp_name'][$key], 'size' => $files['size'][$key], ]; $allowed_types = ['jpg', 'jpeg', 'png', 'gif', 'webp']; $file_ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); if (in_array($file_ext, $allowed_types) && $file['size'] < 10000000) { $original_name = pathinfo($file['name'], PATHINFO_FILENAME); $new_filename = $prefix . $original_name . '.' . $file_ext; $filename = wp_unique_filename($upload_dir['path'], $new_filename); $destination = $upload_dir['path'] . '/' . $filename; if (move_uploaded_file($file['tmp_name'], $destination)) { // Enregistrer dans la médiathèque WordPress $attachment = [ 'guid' => $upload_dir['url'] . '/' . $filename, 'post_mime_type' => $file['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', $new_filename), 'post_content' => '', 'post_status' => 'inherit' ]; $attach_id = wp_insert_attachment($attachment, $destination); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata($attach_id, $destination); wp_update_attachment_metadata($attach_id, $attach_data); // Compatibilité avec les plugins comme FileBird do_action('add_attachment', $attach_id); $success_count++; } } } } wp_redirect(add_query_arg([ 'success' => '1', 'count' => $success_count ], $_SERVER['REQUEST_URI'])); exit; } });
Téléchargement en cours...
Glissez-déposez vos images ici
OU