Codex - Image Attributes Pro https://imageattributespro.com/codex/ Bulk Update WordPress Image Attributes Fri, 05 May 2023 10:52:38 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 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. Example Usage Let’s say you use comma as a separator and want to it to be trimmed as well if it […]

The post iaffpro_custom_attribute_tag_trim_list appeared first on Image Attributes Pro.

]]>
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' );

The post iaffpro_custom_attribute_tag_trim_list appeared first on Image Attributes Pro.

]]>
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. 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 […]

The post iaffpro_bu_run_bulk_updater() appeared first on Image Attributes Pro.

]]>
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

The post iaffpro_bu_run_bulk_updater() appeared first on Image Attributes Pro.

]]>
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 […]

The post iaffpro_bu_batch_size appeared first on Image Attributes Pro.

]]>
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' );

The post iaffpro_bu_batch_size appeared first on Image Attributes Pro.

]]>
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 […]

The post iaffpro_after_update_attributes_in_post appeared first on Image Attributes Pro.

]]>
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' );

The post iaffpro_after_update_attributes_in_post appeared first on Image Attributes Pro.

]]>
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 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.

The post iaffpro_custom_attribute_tag_tag_names appeared first on Image Attributes Pro.

]]>
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

The post iaffpro_custom_attribute_tag_tag_names appeared first on Image Attributes Pro.

]]>
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.

The post iaffpro_custom_attribute_tag_category_names appeared first on Image Attributes Pro.

]]>
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

The post iaffpro_custom_attribute_tag_category_names appeared first on Image Attributes Pro.

]]>
https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_category_names/feed/ 1
iaffpro_custom_attribute_tag_tag_taxonomy https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_tag_taxonomy/ https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_tag_taxonomy/#respond Tue, 22 Mar 2022 08:55:38 +0000 https://imageattributespro.com/?post_type=codex&p=2596 Filter the taxonomy name for %tag% custom attribute tag to extend it to tags of other post types. By default %tag% fetches the tag of the WordPress post post type.

The post iaffpro_custom_attribute_tag_tag_taxonomy appeared first on Image Attributes Pro.

]]>
Filter the taxonomy name for %tag% custom attribute tag to extend it to tags of other post types. By default %tag% fetches the tag of the WordPress post post type.

The taxonomy name for the WordPress post‘s tag is post_tag and that of WooCommerce product tag is product_tag.

Taxonomy Name Of WordPress Post Tag Is Post_tag
Taxonomy name of WordPress Post Tag is post_tag.
Taxonomy Name Of WooCommerce Product Tag Is Product_tag
Taxonomy name of WooCommerce Product Tag is product_tag.
/**
 * Filter $tag_taxonomy_name to extend %tag% custom attribute tag to other post types. 
 * 
 * Refer 3rd-party/woocommerce.php for example code.
 * 
 * @since 3.0
 * 
 * @param $tag_taxonomy_name (string) Name of the taxonomy.
 * @param $post_type (string) will have the post type of the parent post where the image is used. 
 */
$tag_taxonomy_name = apply_filters( 'iaffpro_custom_attribute_tag_tag_taxonomy', $tag_taxonomy_name, $post_type );

Usage In Image Attributes Pro

The following code is from Image Attributes Pro version 3.0 and above where the filter is used to extend %tag% to WooCommerce products.

/**
 * Add WooCommerce Product tag taxonomy to custom attribute tag %tag%.
 * 
 * @since 3.0
 * 
 * @param $tag_taxonomy_name (string) Name of the taxonomy.
 * @param $post_type (string) will have the post type of the parent post where the image is used.
 * 
 * @return $tag_taxonomy_name (string) WooCommerce product tag taxonomy name ('product_tag') if $post_type is 'product'.
 */
function iaffpro_add_wc_product_tag_to_custom_attribute_tag_tag ( $tag_taxonomy_name, $post_type ) {

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

	return $tag_taxonomy_name;
}
add_filter( 'iaffpro_custom_attribute_tag_tag_taxonomy', 'iaffpro_add_wc_product_tag_to_custom_attribute_tag_tag', 10, 2 );

Related: iaffpro_custom_attribute_tag_category_taxonomy

The post iaffpro_custom_attribute_tag_tag_taxonomy appeared first on Image Attributes Pro.

]]>
https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_tag_taxonomy/feed/ 0
iaffpro_custom_attribute_tag_category_taxonomy https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_category_taxonomy/ https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_category_taxonomy/#respond Tue, 22 Mar 2022 08:21:21 +0000 https://imageattributespro.com/?post_type=codex&p=2591 Filter the taxonomy name for %category% custom attribute tag to extend it to categories of other post types. By default %category% fetches the category of the WordPress post post type.

The post iaffpro_custom_attribute_tag_category_taxonomy appeared first on Image Attributes Pro.

]]>
Filter the taxonomy name for %category% custom attribute tag to extend it to categories of other post types. By default %category% fetches the category of the WordPress post post type.

The taxonomy name for the WordPress post‘s category is category and that of WooCommerce product category is product_cat.

Taxonomy Name Of WordPress Post Category Is Category
Taxonomy name of WordPress Post category is category.
Taxonomy Name Of WooCommerce Product Category Is Product_cat
Taxonomy name of WooCommerce Product Category is product_cat.
/**
 * Filter $category_taxonomy_name to extend %category% custom 
 * attribute tag to other post types. 
 * 
 * For example, if you have a custom post type named 'library' where 
 * the category taxnomy name is 'genre',
 you can return the 
 * category taxonomy name so that the name of the genre can be retrieved. 
 * 
 * Refer 3rd-party/woocommerce.php for example code.
 * 
 * @since 3.0
 * 
 * @param $category_taxonomy_name (string) Name of the taxonomy.
 * @param $post_type (string) will have the post type of the parent post where 
 * the image is used.
 */
$category_taxonomy_name = apply_filters( 'iaffpro_custom_attribute_tag_category_taxonomy', $category_taxonomy_name, $post_type );

Pro tip: This filter can be used for any taxonomy associated with a post type. Post category or WooCommerce product category is simply a name of a taxonomy.

Usage in Image Attributes Pro

The following code is from Image Attributes Pro version 3.0 and above where the filter is used to extend %category% to WooCommerce products.

/**
 * Add WooCommerce Product category taxonomy to custom attribute tag %category%.
 * 
 * @since 3.0
 * 
 * @param $category_taxonomy_name (string) Name of the taxonomy.
 * @param $post_type (string) will have the post type of the parent post 
 * where the image is used.
 * 
 * @return $category_taxonomy_name (string) WooCommerce product category 
 * taxonomy name ('product_cat') if $post_type is 'product'.
 */
function iaffpro_add_wc_product_category_to_custom_attribute_tag_category ( $category_taxonomy_name, $post_type ) {

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

	return $category_taxonomy_name;
}
add_filter( 'iaffpro_custom_attribute_tag_category_taxonomy', 'iaffpro_add_wc_product_category_to_custom_attribute_tag_category', 10, 2 );

Example Usage

Here is a sample code that you could use.

  • Replace custom_post_type with the name of the post type.
  • Replace custom_taxonomy with the name of the taxonomy.
  • Both these can be found from the browser address bar when you visit the Category page for the custom post type in WordPress admin. Refer to the product category screenshot above.
  • custom_post_type will be what comes after post_type=
  • custom_taxonomy will be what comes after taxonomy=
  • Both these are highlighted below.
/**
 * Add custom category taxonomy (custom_taxonomy) to custom attribute tag %category%.
 * 
 * @param $category_taxonomy_name (string) Name of the taxonomy.
 * @param $post_type (string) will have the post type of the parent post 
 * where the image is used.
 * 
 * @return $category_taxonomy_name (string) Category taxonomy name ('custom_taxonomy') 
 * if $post_type is 'custom_post_type'.
 * 
 * @link https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_category_taxonomy/
 */
function prefix_iap_detect_custom_category ( $category_taxonomy_name, $post_type ) {

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

	return $category_taxonomy_name;
}
add_filter( 'iaffpro_custom_attribute_tag_category_taxonomy', 'prefix_iap_detect_custom_category', 10, 2 );

Related: iaffpro_custom_attribute_tag_tag_taxonomy

The post iaffpro_custom_attribute_tag_category_taxonomy appeared first on Image Attributes Pro.

]]>
https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_category_taxonomy/feed/ 0
iaff_custom_attribute_tags https://imageattributespro.com/codex/iaff_custom_attribute_tags/ https://imageattributespro.com/codex/iaff_custom_attribute_tags/#respond Tue, 22 Mar 2022 06:56:24 +0000 https://imageattributespro.com/?post_type=codex&p=2585 Filter the custom attribute tags of Image Attributes Pro. This filter can be used to add or remove custom attribute tags.

The post iaff_custom_attribute_tags appeared first on Image Attributes Pro.

]]>
Filter the custom attribute tags of Image Attributes Pro. This filter can be used to add or remove custom attribute tags.

Default List Of Tags Available To Generate A Custom Image Attribute
Default list of tags available to generate a custom image attribute.

New tags can be added using this filter and it’s functionality can be defined using the iaffpro_get_custom_attribute_tag_{%tagname%}() function.

/**
 * Filter the custom attribute tags. 

 * 
 * Used by Image Attributes Pro to add custom tags like %yoastfocuskw% 
 * and %rankmathfocuskw% dynamically. 
 * 
 * @since 3.1
 * 
 * @param $available_tags (array) Array containing all custom attribute tags.
 */
return apply_filters( 'iaff_custom_attribute_tags', $available_tags );

Example Usage

Image Attributes Pro version 3.0 and above uses this filter to add the attribute tag for Yoast Focus Keyword when Yoast plugin is installed and active.

/**
 * Add custom attribute tag %yoastfocuskw%
 * 
 * @since 3.0
 * 
 * @param $available_tags (array) Array containing all custom attribute tags.
 * 
 * @return $available_tags (array) Array with yoastfocuskw added to the custom attribute tags. 
 */
function iaffpro_add_custom_attribute_tag_yoastfocuskw( $available_tags ) {

	$available_tags[ 'yoastfocuskw' ] = __( 'Yoast Focus Keyword', 'auto-image-attributes-pro' );

	return $available_tags;

}
add_filter( 'iaff_custom_attribute_tags', 'iaffpro_add_custom_attribute_tag_yoastfocuskw' );

The post iaff_custom_attribute_tags appeared first on Image Attributes Pro.

]]>
https://imageattributespro.com/codex/iaff_custom_attribute_tags/feed/ 0
iaff_after_bulk_updater https://imageattributespro.com/codex/iaff_after_bulk_updater/ https://imageattributespro.com/codex/iaff_after_bulk_updater/#respond Tue, 22 Mar 2022 06:40:55 +0000 https://imageattributespro.com/?post_type=codex&p=2583 Action hook that is fired at the end of the Bulk Updater after updating every image.

The post iaff_after_bulk_updater appeared first on Image Attributes Pro.

]]>
Action hook that is fired at the end of the Bulk Updater after updating all images.

do_action( 'iaff_after_bulk_updater' );

Fired when:

Example Usage

/**
 * Function that runs at the end of Image Attributes Pro Bulk Updater.
 * 
 * @link https://imageattributespro.com/codex/iaff_after_bulk_updater/
 */
function prefix_iap_do_after_bulk_updater() {
    // Things to do after running Bulk Updater. 
}
add_action( 'iaff_after_bulk_updater', 'prefix_iap_do_after_bulk_updater' );

The post iaff_after_bulk_updater appeared first on Image Attributes Pro.

]]>
https://imageattributespro.com/codex/iaff_after_bulk_updater/feed/ 0