Skip to content

Instantly share code, notes, and snippets.

Avatar

Arun Basil Lal arunbasillal

View GitHub Profile
@arunbasillal
arunbasillal / iap-load-translation-files
Created February 8, 2023 15:52
Load translation files for Image Attributes Pro
View iap-load-translation-files
/**
* Load translation files for Image Attributes Pro
*/
function iaff_load_plugin_textdomain() {
load_plugin_textdomain( 'auto-image-attributes-from-filename-with-bulk-updater', false, '/auto-image-attributes-from-filename-with-bulk-updater/languages/' );
}
add_action( 'plugins_loaded', 'iaff_load_plugin_textdomain' );
@arunbasillal
arunbasillal / iap-custom-tag-yoast-seo-title
Created February 3, 2023 10:23
Custom tag %yoast_seo_title% for Image Attributes Pro.
View iap-custom-tag-yoast-seo-title
/**
* Custom tag %yoast_seo_title% for Image Attributes Pro.
*
* @param $image_id (integer) The ID of the image that is being updated.
* @param $parent_post_id (integer) Post to which the image is attached (uploaded) to.
* @param $bulk (boolean) True when called from Bulk Updater. False by default.
*
* @return (string) Yoast SEO Title.
*
* @link https://imageattributespro.com/codex/iaffpro_get_custom_attribute_tag_tagname/
@arunbasillal
arunbasillal / iap-custom-tag-image-id
Created February 1, 2023 12:49
Custom tag %image_id% for Image Attributes Pro
View iap-custom-tag-image-id
/**
* Custom tag %image_id% for Image Attributes Pro
*
* @param $image_id (integer) The ID of the image that is being updated.
* @param $parent_post_id (integer) The post to which the image is attached (uploaded) to.
* @param $bulk (boolean) True when called from Bulk Updater. False by default.
*
* @return (string) ID of the image.
*
* @refer https://imageattributespro.com/codex/iaffpro_get_custom_attribute_tag_tagname/
@arunbasillal
arunbasillal / iap-custom-tag-post-slug
Created February 1, 2023 12:47
Custom tag %post_slug% for Image Attributes Pro
View iap-custom-tag-post-slug
/**
* Custom tag %post_slug% for Image Attributes Pro
*
* @param $image_id The ID of the image that is being updated.
* @param $parent_post_id The post to which the image is attached (uploaded) to.
* @param $bulk True when called from Bulk Updater. False by default.
*
* @return string Slug of the post where the image is uploaded to.
*
* @refer https://imageattributespro.com/codex/iaffpro_get_custom_attribute_tag_tagname/
@arunbasillal
arunbasillal / iap-use-captions-as-alt-text
Last active December 15, 2022 07:54
Use Captions as alt text.
View iap-use-captions-as-alt-text
/**
* Use Captions as alt text.
*
* @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/
*/
@arunbasillal
arunbasillal / iap-custom-tag-product-description
Created September 15, 2022 19:10
Custom tag %product_description% for Image Attributes Pro
View iap-custom-tag-product-description
/**
* Custom tag %product_description% for Image Attributes Pro
*
* @param $image_id The ID of the image that is being updated.
* @param $parent_post_id The post to which the image is attached (uploaded) to.
* @param $bulk True when called from Bulk Updater. False by default.
*
* @return string WordPress post content. WooCommerce product long description is saved as post content.
*
* @refer https://imageattributespro.com/codex/iaffpro_get_custom_attribute_tag_tagname/
@arunbasillal
arunbasillal / iap-add-hyphens-to-image-title
Created September 8, 2022 18:02
Add hyphens between words for Image Title in Image Attributes Pro
View iap-add-hyphens-to-image-title
/**
* Add hyphens between words for Image Title in Image Attributes Pro
*
* @param $attributes (array) Associative array of image attributes.
*
* @author Arun Basil Lal
* @link https://imageattributespro.com/codex/iaffpro_image_attributes/
*/
function prefix_iap_add_hyphens_to_image_title( $attributes ) {
@arunbasillal
arunbasillal / iap-random-number-tag
Created August 31, 2022 14:00
Custom tag %random_number% for Image Attributes Pro.
View iap-random-number-tag
/**
* Custom tag %random_number% for Image Attributes Pro.
*
* Generates a random number between 0 and 999.
*
* @param $image_id The ID of the image that is being updated.
* @param $parent_post_id The post to which the image is attached (uploaded) to. 0 if the image is not attached to any post.
* @param $bulk True when called from Bulk Updater. False by default.
*
* @return (integer) A random number between 0 and 999.
@arunbasillal
arunbasillal / iap-update-attributes-when-alt-text-changes
Last active October 17, 2022 06:20
Update image attributes when alt text is updated.
View iap-update-attributes-when-alt-text-changes
/**
* Update image attributes when alt text is updated.
*
* Runs when image alt text is updated using update_post_meta and
* calls iaffpro_auto_image_attributes_pro() function to update image attributes.
*
* Settings from "Bulk Updater Settings" tab are used to update the attributes.
*
* @param int $meta_id ID of metadata entry to update.
* @param int $object_id Image ID.
@arunbasillal
arunbasillal / iap-custom-tag-image-alt-text
Last active August 26, 2022 05:37
Custom tag %image_alt_text% for Image Attributes Pro.
View iap-custom-tag-image-alt-text
/**
* Custom tag %image_alt_text% for Image Attributes Pro.
*
* @param $image_id The ID of the image that is being updated.
* @param $parent_post_id The post to which the image is attached (uploaded) to.
* @param $bulk True when called from Bulk Updater. False by default.
*
* @return (string) Image alt text from Media Library.
*/
function iaffpro_get_custom_attribute_tag_image_alt_text( $image_id, $parent_post_id, $bulk = false ) {