/*
Theme Name: Web Craft Theme
Author: Matteo Burchielli
Author URI: https://matteoburchielli.it
Template: yootheme
Version: 1.0.0
Data creazione: 08/2025
*/

/* Le tue personalizzazioni CSS qui */

// Per aggiornare TUTTE le immagini esistenti (esegui una volta)
function update_all_media_titles() {
    $attachments = get_posts(array(
        'post_type' => 'attachment',
        'posts_per_page' => -1,
        'post_status' => 'inherit'
    ));
    
    foreach($attachments as $attachment) {
        // Ottieni il nome del file caricato originale
        $filename = get_post_meta($attachment->ID, '_wp_attached_file', true);
        $filename = pathinfo($filename, PATHINFO_FILENAME);
        
        // Aggiorna il title con il nome file esatto
        wp_update_post(array(
            'ID' => $attachment->ID,
            'post_title' => $filename
        ));
    }
    
    echo "Titoli aggiornati!";
}

// Attiva questa funzione visitando: tuosito.com/?update_titles=1
if(isset($_GET['update_titles'])) {
    update_all_media_titles();
}