iaffpro_after_update_attributes_in_post

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' );
Was this article helpful?
Yes, thanks! 👍Not really 👎