Created
December 11, 2017 14:11
-
-
Save EricBusch/04fcfbb64253d63ee2911cedf7570623 to your computer and use it in GitHub Desktop.
Update the attached image's description, caption & alt text with values from the product. [datafeedr][dfrps]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Update the attached image's description, caption & | |
* alt text with values from the product when the image is imported. | |
* | |
* @param integer $attachment_id Attachment ID of imported image. | |
* @param Dfrps_Image_Importer $image_importer | |
*/ | |
function mycode_update_image_meta( $attachment_id, $image_importer ) { | |
$image_id = $attachment_id; | |
$image_description = $image_importer->post->post_content; | |
$image_caption = $image_importer->post->post_excerpt; | |
$image_alt_text = $image_importer->post->post_title; | |
/** | |
* Update Image Description (post_content) & Caption (post_excerpt) | |
*/ | |
wp_update_post( array( | |
'ID' => $image_id, | |
'post_content' => $image_description, | |
'post_excerpt' => $image_caption, | |
) ); | |
/** | |
* Update Image Alt Text | |
*/ | |
update_post_meta( $image_id, '_wp_attachment_image_alt', $image_alt_text ); | |
} | |
add_action( 'dfrps_image_imported_successfully', 'mycode_update_image_meta', 20, 2 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment