Sending notifications with image when post is published
-
Hi, Marco Milesi!
I need your help. Please answer, a.s.a.p.I want to send message with post_thumbnail to all subscribers when I publish post.
1. In my themes function.php I added this:
function post_published( $new_status, $old_status, $post ) { if ( $old_status != 'publish' && $new_status == 'publish' ) { include plugin_dir_path( "telegram-bot" ) . "/telegram-bot.php"; $post_id = $post->ID; $excerpt = apply_filters( 'the_excerpt', $post->content ); $txt = "<b>" . $post->post_title . "</b>" . "\n" . $excerpt . "\n" . "Давоми: " . get_permalink($post_id); if(has_post_thumbnail($post_id)) { $media = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'medium', true ); telegram_sendmessagetoall($txt, $media[0]); } else { telegram_sendmessagetoall($txt); } } } add_action( 'transition_post_status', 'post_published', 10, 3 );
2. I changed your code in /telegram-bot/telegram-bot.php:
function telegram_sendmessagetoall($message, $image_url = false) { query_posts('post_type=telegram_subscribers&posts_per_page=-1'); $count = 0; while (have_posts()): the_post(); if ( telegram_useractive( get_the_title() ) ) { if($image_url) telegram_sendphoto(get_the_title(), $message, $image_url); else telegram_sendmessage(get_the_title(), $message); $count++; } endwhile; }
If I post is without thumb, it works fine, but with thumbnail it isn’t sending, however in log files messages are appearing:
<-PHO- 11/06/2015 21:23:14 67089 Galaxy S7 арзонро? б?лади ёхуд Samsung`нинг нарх сиёсати ?зини о?лайдими? Бу ?афта Samsung компанияси вакили смартфонлар бозори стагнацияси (савдо-соти?нинг узо? муддат т?хт
Please, help!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Sending notifications with image when post is published’ is closed to new replies.