Description
The gravityflow_post_update_post action allows custom code to be performed after the Update Post step type has completed.
Parameters
Parameter | Type | Details |
---|---|---|
$post | Post | The post which was updated. |
$feed | Array | The feed which was processed. |
$current_step | Step | The current step. |
Examples
Update the alt tag for a featured image based on a specific field
add_action( 'gravityflow_post_update_post', 'jo_post_update_featured_alt', 10, 3 );
function jo_post_update_featured_alt( $post, $feed, $step ) {
//Adjust for which step(s) you want to update alt tags with
if ( ! $step->get_ID() == '33' ) {
return;
}
$post_id = $post['ID'];
$thumbnail_id = get_post_thumbnail_id( $post_id );
$entry = $step->get_entry();
if ( $thumbnail_id ) {
//Identify based on feed ID which entry field contains the alt text.
switch ( $feed['id'] ) :
case '1037':
$alt_text = $entry['4'];
break;
case '1038':
$alt_text = $entry['150'];
break;
case '78':
$alt_text = $entry['4'];
break;
default:
$alt_text = false;
endswitch;
if ( $alt_text ) {
//Update the _wp_attachment_image_alt meta for the post with the new text.
$result = update_post_meta( $thumbnail_id, '_wp_attachment_image_alt', $alt_text );
}
}
}
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?