Codex – Image Attributes Pro https://imageattributespro.com Bulk Update WordPress Image Attributes Sat, 08 Nov 2025 09:22:30 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.3 iaffpro_image_name_from_filename_pre https://imageattributespro.com/codex/iaffpro_image_name_from_filename_pre/ https://imageattributespro.com/codex/iaffpro_image_name_from_filename_pre/#respond Sat, 08 Nov 2025 09:15:58 +0000 https://imageattributespro.com/?post_type=codex&p=4988 Filter the file name of the image before Image Attributes Pro starts processing it. Useful to manually intervene each filename before custom filters and regex filters act on it.

/**
* Filter the name of the image before Image Attributes Pro starts processing.
* 
* @since 4.8
* 
* @param $image_name (string) Name of the image.
* @param $image_id (int) ID of the image to work on. 0 for external images.
* @param $bulk (boolean) True when called from the Bulk Updater. False otherwise.
* @param $image_url (string) Optionally pass image url. Used only when generating attributes for external images.
*/
$image_name = apply_filters( 'iaffpro_image_name_from_filename_pre', $image_name, $image_id, $bulk, $image_url );

Example Usage

This filter can be used in conjunction with the iaffpro_image_attributes filter to preserve or bypass Image Attributes Pro’s processing.

For example, let’s say you want to make sure the word, WordPress is represented as is regardless of what capitalization is applied to the rest of the filename.

The following code will first replace the keyword (WordPress) with a placeholder (IAPWPPLACEHOLDER).

/**
 * Preserve the word 'WordPress' while generating image attributes.
 * 
 * Replace 'WordPress' with a placeholder (IAPWPPLACEHOLDER) in the image filename. 
 * This can later be replaced in the iaffpro_image_attributes filter.
 * 
 * @param $image_name (string) Name of the image.
 * @param $image_id (int) ID of the image to work on. 0 for external images.
 * @param $bulk (boolean) True when called from the Bulk Updater. False otherwise.
 * @param $image_url (string) Optionally pass image url. Used only when generating attributes for external images.
 * 
 * @return $image_name (string) Name of the image after adding the placeholder.
 * 
 * @author Arun Basil Lal
 * @link https://imageattributespro.com/codex/iaffpro_image_name_from_filename_pre/
 */
function prefix_iap_preserve_keyword_in_filename( $image_name, $image_id, $bulk, $image_url ) {
	return str_replace( 'WordPress', 'IAPWPPLACEHOLDER', $image_name ); // Adds a placeholder.
}
add_filter( 'iaffpro_image_name_from_filename_pre', 'prefix_iap_preserve_keyword_in_filename', 10, 4 );

Then later the placeholder can be replaced back to the keyword after all the processing is done.

/**
 * Modify image attributes generated by Image Attributes Pro
 *
 * @param $attributes (array) Associative array of image attributes.
 * @param $image_id (int) ID of the current image.
 * @param $parent_post_id (int) ID of the post the image is inserted into. 0 for images not attached to a post.
 * 
 * @author Arun Basil Lal
 * @link https://imageattributespro.com/codex/iaffpro_image_attributes/
 */
function prefix_iap_restore_keyword_in_filename( $attributes, $image_id, $parent_post_id ) {

	foreach ( $attributes as $key => $value ) {
		$attributes[$key] = str_replace( 'IAPWPPLACEHOLDER', 'WordPress', $attributes[$key] );
	}

	return $attributes;
}
add_filter( 'iaffpro_image_attributes', 'prefix_iap_restore_keyword_in_filename', 10, 3 );
]]>
https://imageattributespro.com/codex/iaffpro_image_name_from_filename_pre/feed/ 0
iaffpro_image_used_in_text https://imageattributespro.com/codex/iaffpro_image_used_in_text/ https://imageattributespro.com/codex/iaffpro_image_used_in_text/#respond Sat, 08 Nov 2025 08:18:16 +0000 https://imageattributespro.com/?post_type=codex&p=4972 Modify or add Image Used In context text in the Media Library Meta Box.

Iap Media Library Meta Box
/**
* Filter image used in context.
* Used in /3rd-party/woocommerce.php for WooCommerce related images.
* 
* @since 4.8
* 
* @param $used_in_text (array) Descriptions for the context where the image is used in.
*/
$used_in_text = apply_filters( 'iaffpro_image_used_in_text', $used_in_text );

Used internally to add WooCommerce related context text. $used_in_text is an associative array and the array keys must match the array key used in $posts array.

Refer iaffpro_get_posts_by_attachment_id for a complete picture.

Example Usage

Let’s take the same example of Listings from iaffpro_get_posts_by_attachment_id‘s documentation.

To add a context text in the Media Library meta box, the code will look like below.

/**
 * Add Listings related image used in text.
 * 
 * @link https://imageattributespro.com/codex/iaffpro_image_used_in_text/
 * 
 * @param $used_in_text (array) Descriptions for the context where the image is used in.
 * 
 * @return $used_in_text (array) Descriptions with Listings related context added to it.
 */
function prefix_iap_my_listings_used_in_text( $used_in_text ) {

	$used_in_text[ '05_my_listings' ] = __( '(as Listings main image)', 'auto-image-attributes-pro' );

	return $used_in_text;
}
add_filter( 'iaffpro_image_used_in_text', 'prefix_iap_my_listings_used_in_text' );

Note that, 05_my_listings is the same array key that we used with the iaffpro_get_posts_by_attachment_id filter.

]]>
https://imageattributespro.com/codex/iaffpro_image_used_in_text/feed/ 0
iaffpro_get_posts_by_attachment_id https://imageattributespro.com/codex/iaffpro_get_posts_by_attachment_id/ https://imageattributespro.com/codex/iaffpro_get_posts_by_attachment_id/#respond Sat, 08 Nov 2025 07:51:22 +0000 https://imageattributespro.com/?post_type=codex&p=4967 Filter the results of Image Attributes Pro’s image search.

Image Attributes Pro attempts to a comprehensive search to find out where an image is used. As of version 4.8, Image Attributes Pro looks for an image in the following locations.

  • Featured image of a post, page or product (or any registered custom post type).
  • HTML content of posts, pages or products.
  • Checks if the image is uploaded to a post (denoted as “Uploaded to” in the Media Library).

On top of this, if the website uses WooCommerce, the search is extended to the following locations as well. Internally this filter is used to search WooCommerce specific locations.

  • WooCommerce product variation image.
  • WooCommerce product gallery.
/**
* Filter $posts array.
* Used in /3rd-party/woocommerce.php to add search in WooCommerce products.
* 
* @since 4.8
* 
* @param $posts (array) An associative array of posts where the image is used.
* @param $attachment_id (int) ID of the image.
*/
$posts = apply_filters( 'iaffpro_get_posts_by_attachment_id', $posts, $attachment_id );

The $posts is an associative array with it’s keys starting with a number.

  • 10_thumbnail: If the image is used as a featured image, then that has the highest preference.
  • 20_wc_product_variation_image: WooCommerce product variation image.
  • 30_wc_product_image_gallery: WooCommerce product where the image is part of the product gallery.
  • 40_content: Posts where image is used within the content.
  • 50_uploaded_to: The post ID to with the image is uploaded to.

When an image is used in multiple locations, the post / product associated with the lowest number will be considered to generate image attributes.

Also refer related filter, iaffpro_image_used_in_text.

Example Usage

Let’s say you have a listing website that uses a non WordPress system to create a listing. One image is set as the main image for the listing. Let’s also assume that this image is possibly used in other parts of your website. Maybe in a WordPress post.

Out of the box, Image Attributes Pro will find the post on which the image is used and will use it to generate image attributes. For instance, %posttitle% custom image attribute tag will be the title of the post and not that of the listing as it should be.

To find listings where the image is used and to add it to Image Attributes Pro’s search results, your code could look like so.

/**
* Find Listings where an image is used.
* 
* @link https://imageattributespro.com/codex/iaffpro_get_posts_by_attachment_id/
* 
* @param $posts (array) An associative array of posts where the image is used.
* @param $attachment_id (int) ID of the image.
* 
* @return $posts (array) Array with Listings added to the original $posts array.
*/
function prefix_iap_get_my_listings_by_attachment_id( $posts, $attachment_id ) {
	
	$listings = array();
	
	// Your database query to find listings goes here. 

	$listings = array_unique( $listings );

	$posts['05_my_listings'] = $listings;

	return $posts;
}
add_filter( 'iaffpro_get_posts_by_attachment_id', 'prefix_iap_get_my_listings_by_attachment_id', 10, 2 );

Note that the array key (05_my_listings) starts with a number (05 in this example) and it’s lower than the first key of the default array, which is 10_thumbnail. This will tell Image Attributes Pro to give listings as the highest priority while generating image attributes for that specific image.

]]>
https://imageattributespro.com/codex/iaffpro_get_posts_by_attachment_id/feed/ 0
iaffpro_disable_event_logging https://imageattributespro.com/codex/iaffpro_disable_event_logging/ https://imageattributespro.com/codex/iaffpro_disable_event_logging/#respond Mon, 20 Oct 2025 06:02:57 +0000 https://imageattributespro.com/?post_type=codex&p=4937 Image Attributes Pro keeps a log of the bulk updater activity by writing into a log file.

The default location of this file is in \wp-content\uploads\iap-logs\iap-bu-log.log. Log from this file will be displayed in the Event Log in the Bulk Updater tab of Image Attributes Pro.

Event logging can be disabled by setting the filter iaffpro_disable_event_logging to true. The default value is set to false.

/**
 * Check if event logging is disabled.
 * 
 * @since 4.7
 * 
 * @param (bool) Set as true to disable event log file generation. Default to false.
 */
if ( apply_filters( 'iaffpro_disable_event_logging', false ) ) {
	return false;
}

Available since Image Attributes Pro version 4.7.

Example Usage

To disable event logging and generation of log file, add this line to the functions.php of your active theme.

/**
 * Disable event log file generation in Image Attributes Pro.
 * 
 * @link https://imageattributespro.com/codex/iaffpro_disable_event_logging/
 * 
 * @return (bool) true. 
 */
add_filter( 'iaffpro_disable_event_logging', '__return_true' );
]]>
https://imageattributespro.com/codex/iaffpro_disable_event_logging/feed/ 0
iaffpro_custom_attribute_tag_trim_list https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_trim_list/ https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_trim_list/#respond Thu, 30 Mar 2023 08:15:23 +0000 https://imageattributespro.com/?post_type=codex&p=3520 Image Attributes Pro version 4.3 and newer will trim separators like hyphen (-) and pipe symbol (|) if they appear the end of a custom generated image attribute. Any white spaces are also trimmed.

  • For instance, if you have a custom image attribute as: %posttitle% - %yoastfocuskw%.
  • Post title is Hello World.
  • The post doesn’t have a Yoast Focus Keyword.
  • Then the generated, image attribute will be Hello World - normally.
  • Image Attributes Pro will remove the orphan hyphen and turn it into Hello World.
/**
 * Filter characters to trim.
 * 
 * @since 4.3
 * 
 * @param (string) Default list of characters to trim include space, 
 * pipe symbol (|) and hyphen (-).
 */
$trim_list = apply_filters( 'iaffpro_custom_attribute_tag_trim_list', ' |-' );

Example Usage

Let’s say you use comma as a separator and want to it to be trimmed as well if it appears at the end of an image attribute. Adding the following code to the functions.php of your active theme will take care of it.

/**
 * Trim comma if it appears at the end of image attributes.
 * 
 * For Image Attributes Pro
 * 
 * @author Arun Basil Lal
 * @link https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_trim_list/
 * 
 * @param $trim_list (string) Default list of characters to trim include space, 
 * pipe symbol (|) and hyphen (-).
 */
function prefix_iap_trim_comma_from_image_attributes( $trim_list ) {
	
	// Add comma to the end of existing list of characters to trim.
	$trim_list = $trim_list . ',';
	return $trim_list;
}
add_filter( 'iaffpro_custom_attribute_tag_trim_list', 'prefix_iap_trim_comma_from_image_attributes' );
]]>
https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_trim_list/feed/ 0
iaffpro_bu_run_bulk_updater() https://imageattributespro.com/codex/iaffpro_bu_run_bulk_updater/ https://imageattributespro.com/codex/iaffpro_bu_run_bulk_updater/#respond Mon, 27 Mar 2023 18:08:26 +0000 https://imageattributespro.com/?post_type=codex&p=3499 Runs the bulk updater of Image Attributes Pro, one batch at a time. Image attributes will be updated as per the Bulk Updater Settings.

iaffpro_bu_run_bulk_updater( $batch_size );

Accepts one parameter, $batch_size which is an integer. The default batch size is 20 which can be filtered using iaffpro_bu_batch_size filter.

Image Attributes Pro version 4.2 and later varies the images per batch based on the server conditions. However, if you override the default batch size using iaffpro_bu_batch_size filter, the variable batch size is not used.

Example Usage

// Run Image Attributes Pro Bulk Updater
iaffpro_bu_run_bulk_updater( 25 );

For a better more elaborate example, refer: Run Image Attributes Pro Bulk Updater Programmatically / via Cron Job

]]>
https://imageattributespro.com/codex/iaffpro_bu_run_bulk_updater/feed/ 0
iaffpro_bu_batch_size https://imageattributespro.com/codex/iaffpro_bu_batch_size/ https://imageattributespro.com/codex/iaffpro_bu_batch_size/#respond Thu, 19 Jan 2023 07:40:02 +0000 https://imageattributespro.com/?post_type=codex&p=3266 Modify the batch size of the bulk updater of Image Attributes Pro. This filter can be used to increase or decrease the default batch size.

A higher batch size means more images are processed in the same batch. Make sure your server is capable of handling the load or else it could lead to PHP time outs. You should be fine with 20-50 images per batch on most servers.

/**
 * Filter the Bulk Updater batch size.
 * 
 * @since 4.1
 * 
 * @param $batch_size (int) Defines the number of images that will be 
 * processed in a single call to the function. 
 * Higher batch sizes can lead to PHP time outs.
 */
$batch_size = apply_filters( 'iaffpro_bu_batch_size', $batch_size );

Available since Image Attributes Pro version 4.1. The default batch size shipped with version 4.0 was 10 which was later updated in version 4.2 to 20.

Image Attributes Pro version 4.2 and later varies the images per batch based on the server conditions. However, if you override the default batch size using this filter, the variable batch size is not used.

Example Usage

In this example, we will set the batch size to 40.

/**
 * Modify Image Attributes Pro Bulk Updater batch size.
 *
 * @link https://imageattributespro.com/codex/iaffpro_bu_batch_size/
 *  
 * @param $batch_size (int) Defines the number of images that will be 
 * processed in a single call to the function.
 * 
 * @return (int) New batch size.
 */
function prefix_iap_modify_bu_batch_size( $batch_size ) {
	return 40;
}
add_filter( 'iaffpro_bu_batch_size', 'prefix_iap_modify_bu_batch_size' );
]]>
https://imageattributespro.com/codex/iaffpro_bu_batch_size/feed/ 0
iaffpro_after_update_attributes_in_post https://imageattributespro.com/codex/iaffpro_after_update_attributes_in_post/ https://imageattributespro.com/codex/iaffpro_after_update_attributes_in_post/#respond Wed, 27 Apr 2022 08:05:43 +0000 https://imageattributespro.com/?post_type=codex&p=2772 Action hook that is fired at the end of iaffpro_update_attributes_in_post_by_post_id( $post_id ) function. This function is used to update image attributes of all images in a post and is used by the bulk updater and bulk actions.

This action is fired after Image Attributes Pro updates each post.

ID of the post that is updated is passed as an argument, $post_id.

do_action( ‘iaffpro_after_update_attributes_in_post’, $post_id );

Example Usage

Image Attributes Pro uses this action in /3rd-party/woocommerce.php to update the attributes of WooCommerce Product Gallery images while updating a product. That code is presented below as an example.

/**
 * Update attributes of images in Product Gallery while updating 
 * attributes of a product.
 * 
 * @since 3.1
 * 
 * @param $post_id (integer) ID of the post that is being updated in iaffpro_update_attributes_in_post_by_post_id()
 */
function iaffpro_wc_update_product_gallery_image_attributes( $post_id ) {
	
	// Retrieve post type of the post.
	$post_type = get_post_type( $post_id );

	// Check if post type is WooCommerce product.
	if ( strcmp( $post_type, 'product' ) !== 0 ) {
		return;
	}

	// Retrieve Product Gallery image ID's.
	$product = new WC_product( $post_id );
	$product_gallery_image_ids = $product->get_gallery_image_ids();

	// Update every image in Product Gallery.
	foreach( $product_gallery_image_ids as $gallery_image ) {

		$parent_post_id = iaffpro_get_parent_post_of_image( $gallery_image );

		if ( $parent_post_id === 0 ) {
			$parent_post_id = $post_id;
		}

		$attributes = iaffpro_generate_image_attributes( $gallery_image, $parent_post_id, true );
		
		iaffpro_update_image( $gallery_image, $attributes, true );
	}
}
add_action( 'iaffpro_after_update_attributes_in_post', 'iaffpro_wc_update_product_gallery_image_attributes' );
]]>
https://imageattributespro.com/codex/iaffpro_after_update_attributes_in_post/feed/ 0
iaffpro_custom_attribute_tag_tag_names https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_tag_names/ https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_tag_names/#comments Tue, 22 Mar 2022 09:33:47 +0000 https://imageattributespro.com/?post_type=codex&p=2614 The default output of %tag% custom attribute tag of Image Attributes Pro is the first tag associated with a post. If a post has multiple tags, only one of them will be used while generating image attributes.

This filter can be used to modify the output of %tag% custom attribute tag.

/**
 * Filter the list of tags returned by %tag% custom attribute tag. 
 * Default value is first tag name.
 * 
 * @since 3.0
 * 
 * @param $tags[0] (string) The first tag available. This is the default value.
 * @param $tags (array) Contains the names of all tags associated with $parent_post_id.
 */
return apply_filters( 'iaffpro_custom_attribute_tag_tag_names', $tags[0], $tags );

Example Code

In the following example, the output is modified using the filter. Once the code is applied (for example when added to functions.php of active theme), %tag% will output a comma separated list of tags when a post has multiple tags.

/**
 * Generate a comma separated list of tags to be used as image attributes.
 * This modifies the output generated by %tag% custom attributes tag in Image Attributes Pro.
 * 
 * @link https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_tag_names/
 * 
 * @param $first_tag (string) The first tag available.
 * @param $tags (array) Contains the names of all tags associated with given post.
 * 
 * @return (string) Comma separated list of all tags.
 */
function prefix_iap_add_all_tags_in_custom_attribute_tag_tag( $first_tag, $tags ) {

    // Returns all tags as a comma separated list. 
    return implode( ',', $tags );
}
add_filter( 'iaffpro_custom_attribute_tag_tag_names', 'prefix_iap_add_all_tags_in_custom_attribute_tag_tag', 10, 2 );

Related: iaffpro_custom_attribute_tag_category_names

]]>
https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_tag_names/feed/ 1
iaffpro_custom_attribute_tag_category_names https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_category_names/ https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_category_names/#comments Tue, 22 Mar 2022 09:24:29 +0000 https://imageattributespro.com/?post_type=codex&p=2612 The default output of %category% custom attribute tag of Image Attributes Pro is the first category associated with a post. If a post has multiple categories, only one of them will be used while generating image attributes.

This filter can be used to modify the output of %category% custom attribute tag.

/**
 * Filter the list of categories returned by %category% custom attribute tag. 
 * Default value is first category name.
 * 
 * @since 3.0
 * 
 * @param $categories[0] (string) The first category available. This is the default value.
 * @param $categories (array) Contains the names of all categories associated with $parent_post_id.
 */
return apply_filters( 'iaffpro_custom_attribute_tag_category_names', $categories[0], $categories );

Example Usage

In the following example, the output is modified using the filter. Once the code is applied (for example when added to functions.php of active theme), %category% will output a comma separated list of categories when a post has multiple categories.

/**
 * Generate a comma separated list of categories to be used as image attributes.
 * This modifies the output generated by %category% custom attributes tag in Image Attributes Pro.
 * 
 * @link https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_category_names/
 * 
 * @param $first_category (string) The first category available.
 * @param $categories (array) Contains the names of all categories associated with given post.
 * 
 * @return (string) Comma separated list of all categories.
 */
function prefix_iap_add_all_categories_in_custom_attribute_tag_category( $first_category, $categories ) {

    // Returns all categories as a comma separated list. 
    return implode( ',', $categories );
}
add_filter( 'iaffpro_custom_attribute_tag_category_names', 'prefix_iap_add_all_categories_in_custom_attribute_tag_category', 10, 2 );

Related: iaffpro_custom_attribute_tag_tag_names

]]>
https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_category_names/feed/ 1