Title: Programmatically regenerate thumbnails
Last modified: May 3, 2018

---

# Programmatically regenerate thumbnails

 *  Resolved [hzengler](https://wordpress.org/support/users/hzengler/)
 * (@hzengler)
 * [8 years ago](https://wordpress.org/support/topic/programmatically-regenerate-thumbnails/)
 * Hello,
 * I’m currently developing a website for a client and I would like to know if it
   is possible to do the following :
    – Regenerate thumbnails programmatically, 
   in PHP, within a scheduled task.
 * As I didn’t find any documentation about it, I just watched the requests involved
   when clicking the “Regenerate all thumbnails” button. For now, I’ve succeed to
   retrieve the medias IDs via : “/wp-json/wp/v2/media?page=1&per_page=100&_fields
   =id&is_regeneratable=1&exclude_site_icons=1&orderby=id&order=asc” using curl.
   
   Though, I can’t regenerate thumbnails using this URL (971 is an ID used for the
   example) : “/wp-json/regenerate-thumbnails/v1/regenerate/971?only_regenerate_missing_thumbnails
   =true&delete_unregistered_thumbnail_files=false&update_usages_in_posts=false”.
   When I do, I get this error message : “{ [“code”]=> string(14) “rest_forbidden”[“
   message”]=> string(59) “Désolé, vous n’avez pas l’autorisation de faire cela.”[“
   data”]=> array(1) { [“status”]=> int(401) } }”
 * Am I correct in my approach? Do I use the good URLs? Does it involve an authentication?
   Any support would be great 🙂
 * Thank you, and I look forward to hear about you !

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Contributor [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [8 years ago](https://wordpress.org/support/topic/programmatically-regenerate-thumbnails/#post-10299938)
 * Yes, the REST API requires a nonce:
 * [https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/](https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/)
 * It’s probably easier to call it via PHP so that you don’t have to use a nonce:
 * [https://developer.wordpress.org/rest-api/using-the-rest-api/frequently-asked-questions/#can-i-make%c2%a0api-requests%c2%a0from-php-within-a-plugin](https://developer.wordpress.org/rest-api/using-the-rest-api/frequently-asked-questions/#can-i-make%c2%a0api-requests%c2%a0from-php-within-a-plugin)
 * You can make a fresh PHP file that has `require( 'wp-load.php' );` in it and 
   then add code that’s based on the lines at that link.
 *  Plugin Contributor [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [8 years ago](https://wordpress.org/support/topic/programmatically-regenerate-thumbnails/#post-10327832)
 * Actually I just remembered about this plugin that I used during development of
   my own plugin:
 * [https://github.com/WP-API/Basic-Auth](https://github.com/WP-API/Basic-Auth)
 * It allows you to use basic authentication (aka your username and password) to
   access the REST API — no nonce required. This is a bad idea for production use,
   but works great for local development.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Programmatically regenerate thumbnails’ is closed to new replies.

 * ![](https://ps.w.org/regenerate-thumbnails/assets/icon-128x128.png?rev=1753390)
 * [Regenerate Thumbnails](https://wordpress.org/plugins/regenerate-thumbnails/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/regenerate-thumbnails/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/regenerate-thumbnails/)
 * [Active Topics](https://wordpress.org/support/plugin/regenerate-thumbnails/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/regenerate-thumbnails/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/regenerate-thumbnails/reviews/)

## Tags

 * [cron](https://wordpress.org/support/topic-tag/cron/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [programmatically](https://wordpress.org/support/topic-tag/programmatically/)

 * 2 replies
 * 2 participants
 * Last reply from: [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * Last activity: [8 years ago](https://wordpress.org/support/topic/programmatically-regenerate-thumbnails/#post-10327832)
 * Status: resolved