{"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 If you have a use case where you need to run the Bulk Updater programmatically instead, the following function is for you. <\/strong><\/p> Things to note:<\/strong><\/p> You can add the above function in a PHP file \/ script and call the file as a cron job. Remember to load WordPress in that case. <\/p> For example, if you are going to add the PHP file to the root folder of your WordPress installation (the same folder with Bulk Updater tab<\/code> of Image Attributes Pro and runs using Java Script as long as the browser tab is kept open. <\/p>
<\/figure>
\/**\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>
$batch_size<\/code> determines the number of images processed in one call to the function. The value in the above example is
20<\/code> which means that 20 images will be processed for every call to the function. <\/li>\n\n
$batch_size<\/code> means more images will be processed at one. But it will also increase the chance of a PHP time out. Use with caution. <\/li><\/ul>
Run Image Attributes Pro Using Cron Job<\/h2>
wp-config.php<\/code>), then you can load WordPress by adding
require( 'wp-load.php' );<\/code> at the top of the file. <\/p>