{"id":2382,"date":"2021-11-30T14:17:43","date_gmt":"2021-11-30T08:47:43","guid":{"rendered":"https:\/\/imageattributespro.com\/?p=2382"},"modified":"2023-03-27T23:46:07","modified_gmt":"2023-03-27T18:16:07","slug":"run-bulk-updater-programmatically","status":"publish","type":"post","link":"https:\/\/imageattributespro.com\/run-bulk-updater-programmatically\/","title":{"rendered":"Run Image Attributes Pro Bulk Updater Programmatically \/ via Cron Job"},"content":{"rendered":"

Image Attributes Pro updates image attributes such as image alt text and image title using it’s bulk updater. The bulk updater is designed to cycle through each image on your WordPress website and update it’s attributes. <\/p>

The bulk updater is housed in the Bulk Updater tab<\/code> of Image Attributes Pro and runs using Java Script as long as the browser tab is kept open. <\/p>

\"Bulk_updater\"<\/figure>

If you have a use case where you need to run the Bulk Updater programmatically instead, the following function is for you. <\/strong><\/p>

\/**\n * Run Image Attributes Pro Bulk Updater Programmatically\n * \n * Note: Requires Image Attributes Pro version 4.0 or above.\n * \n * @param (int) $batch_size Defines the number of images that will be processed\n * in a single call to the function. Higher batch sizes can lead to PHP time outs. \n * \n * @link https:\/\/imageattributespro.com\/run-bulk-updater-programmatically\/\n * @author Arun Basil Lal\n *\/\nfunction prefix_iap_run_bulk_updater( $batch_size = 20 ) {\n\n\t\/\/ Return while call is made from ajax.\n\tif ( wp_doing_ajax() ) {\n\t\treturn;\n\t}\n\n\t\/\/ Return if Image Attributes Pro is not active.\n\tif ( ! function_exists( 'iaff_is_pro' ) || ! iaff_is_pro() ) {\n\t\treturn;\n\t}\n\n\t\/\/ Return if all images are updated. \n\tif ( iaff_count_remaining_images() === 0 ) {\n\t\treturn;\n\t}\n\n\t\/**\n\t * Action hook that is fired at the start of the \n\t * Bulk Updater before updating any image.\n\t * \n\t * @link https:\/\/imageattributespro.com\/codex\/iaff_before_bulk_updater\/\n\t *\/\n\tdo_action('iaff_before_bulk_updater');\n\n\t\/\/ Process one batch of images. \n\tiaffpro_bu_run_bulk_updater( $batch_size );\n\n\t\/**\n\t * Action hook that is fired at the end of the \n\t * Bulk Updater after updating all images.\n\t * \n\t * @link https:\/\/imageattributespro.com\/codex\/iaff_after_bulk_updater\/\n\t *\/\n\tdo_action('iaff_after_bulk_updater'); \n}<\/code><\/pre>

Things to note:<\/strong><\/p>