Skip to content

Instantly share code, notes, and snippets.

View arunbasillal's full-sized avatar

Arun Basil Lal arunbasillal

View GitHub Profile
@arunbasillal
arunbasillal / IAP: Preserve triple hyphens while generating image attributes.
Created November 8, 2025 09:26
IAP: Preserve triple hyphens while generating image attributes.
/**
* Preserve triple hyphens while generating image attributes.
*
* Replace triple hyphens in image (---) with a placeholder (IAPHYPHEN) in the image filename.
* Image Attributes Pro already replaces IAPHYPHEN back to a single hyphen ( - ) after applying filters
* in iaffpro_image_name_from_filename().
*
* @param $image_name (string) Name of the image.
* @return $image_name (string) Name of the image with triple hyphens replaced by IAPHYPHEN
*
@arunbasillal
arunbasillal / IAP: %wc_posttitle% Custom image attribute to use title of main product instead of WooCommerce variation title
Created October 24, 2025 13:09
IAP: %wc_posttitle% Custom image attribute to use title of main product instead of WooCommerce variation title.
/**
* Return title of the post where the image is uploaded to.
* For %wc_posttitle%
*
* For WooCommerce variations, this will return the name of the original product
* instead of the variation title.
*
* @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 $args (array) An array containing additional arguments.
@arunbasillal
arunbasillal / IAP: Remove Media Library Meta Box
Last active September 8, 2025 10:59
IAP: Remove Media Library Meta Box
// Remove Image Attributes Pro Media Library Meta Box
remove_action( 'add_meta_boxes_attachment', 'iaffpro_add_meta_box_media_library' );
@arunbasillal
arunbasillal / IAP: Remove processing after WooCommerce product import via CSV
Last active September 8, 2025 10:59
IAP: Remove processing after WooCommerce product import via CSV
// Prevent: Update image attributes after product import from CSV file.
remove_action( 'woocommerce_product_import_inserted_product_object', 'iaffpro_wc_update_image_attributes_after_product_import_from_csv', 10, 2 );
@arunbasillal
arunbasillal / Custom tag %pr_acf_author% for Image Attributes Pro to use ACF Author Field.
Last active October 13, 2023 10:22
IAP: Custom tag %pr_acf_author% to use ACF "Author" Field.
/**
* Custom tag %pr_acf_author% for Image Attributes Pro to use ACF Author Field.
*
* @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 $args (array) An array containing additional arguments.
*
* @return (string) Author of the post / page / product as defined in ACF, if available. Empty string otherwise.
*
* @refer https://imageattributespro.com/codex/iaffpro_get_custom_attribute_tag_tagname/
@arunbasillal
arunbasillal / Custom tag %pr_post_author% for Image Attributes Pro
Created October 10, 2023 20:36
IAP: Custom tag %pr_post_author% for Image Attributes Pro
/**
* Custom tag %pr_post_author% 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 $args (array) An array containing additional arguments.
*
* @return (string) Author of the post / page / product if available. Empty string otherwise.
*
* @refer https://imageattributespro.com/codex/iaffpro_get_custom_attribute_tag_tagname/
@arunbasillal
arunbasillal / IAP: Remove trailing hypens from image filename
Last active November 7, 2023 12:10
IAP: Remove trailing hypens from image filename
/**
* Removes trailing hyphen from filename if any.
*/
function prefix_iaff_clean_filename_helper( $file ) {
// Process only images.
$image_extensions = array (
'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/tiff', 'ico'
);
@arunbasillal
arunbasillal / IAP: Custom tag %pr_yoastmetadesc% for Yoast Meta Description.
Last active April 9, 2023 10:23
Custom tag %pr_yoastmetadesc% for Image Attributes Pro that returns Yoast Meta Description.
/**
* Custom tag %pr_yoastmetadesc% for Image Attributes Pro that returns Yoast Meta Description.
*
* @link https://yoast.com/developer-blog/yoast-seo-14-0-using-yoast-seo-surfaces/
*
* @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 $args (array) An array containing additional arguments.
*
* @return (string) Yoast Meta Description.
@arunbasillal
arunbasillal / IAP: Custom tag %ds_page_title% to return PAGE title
Last active April 24, 2023 07:15
Custom tag %ds_page_title% for Image Attributes Pro that returns title of Page
/**
* Custom tag %ds_page_title% for Image Attributes Pro that returns title of Page.
*
* @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 $args (array) An array containing additional arguments.
*
* @return (string) Title of the page to which the image is uploaded to. Post title if page cannot be found.
*
* @refer https://imageattributespro.com/codex/iaffpro_get_custom_attribute_tag_tagname/
@arunbasillal
arunbasillal / IAP: Update image attributes in WordPress Pages only.
Created April 9, 2023 06:41
Update image attributes in WordPress Pages only.
/**
* Update image attributes in WordPress Pages only.
*
* The post type for a WordPress page is 'page'.
*
* @author Arun Basil Lal
* @link https://imageattributespro.com/codex/iaffpro_included_post_types/
*/
function prefix_iap_update_pages_only( $included_post_types ) {