Hi, Greg!
I have got code snippet from UM support and i combined with your, so i have this code now:
//Adverts on social activity wall
add_action( “publish_advert”, “on_advert_publish” );
function on_advert_publish( $post_id ) {
$advert = get_post( $post_id );
// add UM activity here
function um_activity_new_cpt( $post_id ) {
if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) return;
if ( get_post_type( $post_id ) != ‘cpt_slug’ || get_post_status( $post_id ) != ‘publish’ ) return;
if ( ! UM()->options()->get(‘activity-new-post’) )
return;
$post = get_post( $post_id );
$user_id = $post->post_author;
um_fetch_user( $user_id );
$author_name = um_user(‘display_name’);
$author_profile = um_user_profile_url();
if (has_post_thumbnail( $post_id ) ) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘large’ );
$post_image = ‘<span></span>’;
} else {
$post_image = ”;
}
if ( $post->post_content ) {
$post_excerpt = ‘<span>’ . wp_trim_words( strip_shortcodes( $post->post_content ), $num_words = 25, $more = null ) . ‘</span>’;
} else {
$post_excerpt = ”;
}
UM()->Activity_API()->api()->save(
array(
‘template’ => ‘new-post’,
‘wall_id’ => $user_id,
‘related_id’ => $post_id,
‘author’ => $user_id,
‘author_name’ => $author_name,
‘author_profile’ => $author_profile,
‘post_title’ => ‘<span>’ . $post->post_title . ‘</span>’,
‘post_url’ => get_permalink( $post_id ),
‘post_excerpt’ => $post_excerpt,
‘post_image’ => $post_image,
)
);
}
}
add_action(‘save_post’, ‘um_activity_new_cpt’, 99999, 1 );
It’s actually work, but unfortunately there is some errors.
Can you please check this code, is there any bugs?
Thank you!