phpwordpressmultisitewpmu

update and regenerate thumbnails for wordpress multisite


For my multisite installations (with over 1500 sites on one of them) I am looking for the most efficient way to change the thumbnailsite to 300x300. On a single site you can easily do this by changing the mediasettings and then running the regenerate thumbnails plugin. I don't want to do this manually for all the sites so I'm thinking about how to do this by code.

To set the thumbnailsize is a part which I can figure out. I'll just make a loop that loops through all the sites in the network and use the code to update the default thumbnailsettings:

if (function_exists('add_theme_support')) { 
    add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 300, 300, true ); // default thumbnail size 
}

But I can't figure out how to do the regenerating since I can't really find advice on how to code this. When I search for this I just find developers recommending the regenerate thumbnails plugin. Also with the code I'm a little bit skeptical it'll become too heavy for my wpmu.

Is there something code/plugin that can do what I want ? (regenerate thumbnails for the whole network ?)


Solution

  • With wp cli on the command line you can use the Media regenerate command line for every website:

    wp media regenerate --url=https://sub1.example.com 
    
    wp media regenerate --url=https://sub2.example.com 
    

    Then for a large number of sites you can use a loop which could look like that:

    for i in sub1.example.com sub2.example.com sub3.example.com
    do wp media regenerate --url=https://$i --yes
    done
    

    For each website in the list i, the command line regenerates medias.

    I added the --yes option to Answer yes to the confirmation message.