{"id":2772,"date":"2022-04-27T13:35:43","date_gmt":"2022-04-27T08:05:43","guid":{"rendered":"https:\/\/imageattributespro.com\/?post_type=codex&p=2772"},"modified":"2022-04-27T13:35:43","modified_gmt":"2022-04-27T08:05:43","slug":"iaffpro_after_update_attributes_in_post","status":"publish","type":"codex","link":"https:\/\/imageattributespro.com\/codex\/iaffpro_after_update_attributes_in_post\/","title":{"rendered":"iaffpro_after_update_attributes_in_post"},"content":{"rendered":"

Action hook that is fired at the end of iaffpro_update_attributes_in_post_by_post_id( $post_id )<\/code> 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<\/a>. <\/p>

This action is fired after Image Attributes Pro updates each post.<\/strong> <\/p>

ID of the post that is updated is passed as an argument, $post_id<\/code>.<\/p>

do_action( ‘iaffpro_after_update_attributes_in_post’, $post_id );<\/strong><\/p>

Example Usage<\/h2>

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

\/**\n * Update attributes of images in Product Gallery while updating \n * attributes of a product.\n * \n * @since 3.1\n * \n * @param $post_id (integer) ID of the post that is being updated in iaffpro_update_attributes_in_post_by_post_id()\n *\/\nfunction iaffpro_wc_update_product_gallery_image_attributes( $post_id ) {\n\t\n\t\/\/ Retrieve post type of the post.\n\t$post_type = get_post_type( $post_id );\n\n\t\/\/ Check if post type is WooCommerce product.\n\tif ( strcmp( $post_type, 'product' ) !== 0 ) {\n\t\treturn;\n\t}\n\n\t\/\/ Retrieve Product Gallery image ID's.\n\t$product = new WC_product( $post_id );\n\t$product_gallery_image_ids = $product->get_gallery_image_ids();\n\n\t\/\/ Update every image in Product Gallery.\n\tforeach( $product_gallery_image_ids as $gallery_image ) {\n\n\t\t$parent_post_id = iaffpro_get_parent_post_of_image( $gallery_image );\n\n\t\tif ( $parent_post_id === 0 ) {\n\t\t\t$parent_post_id = $post_id;\n\t\t}\n\n\t\t$attributes = iaffpro_generate_image_attributes( $gallery_image, $parent_post_id, true );\n\t\t\n\t\tiaffpro_update_image( $gallery_image, $attributes, true );\n\t}\n}\nadd_action( 'iaffpro_after_update_attributes_in_post', 'iaffpro_wc_update_product_gallery_image_attributes' );<\/code><\/pre>","protected":false},"excerpt":{"rendered":"

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 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"Action Fired After Each Post Is Updated %%sep%% %%sitename%%","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"tags":[],"codex-type":[26],"class_list":["post-2772","codex","type-codex","status-publish","format-standard","hentry","codex-type-actions"],"_links":{"self":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex\/2772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex"}],"about":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/types\/codex"}],"author":[{"embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/comments?post=2772"}],"version-history":[{"count":4,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex\/2772\/revisions"}],"predecessor-version":[{"id":2776,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex\/2772\/revisions\/2776"}],"wp:attachment":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/media?parent=2772"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/tags?post=2772"},{"taxonomy":"codex-type","embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex-type?post=2772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}