Twillio How To Send SMS for Custom Post Type
Twillio has a tutorial where one assembles a plugin that sends SMS notices when 'post' is published. The issue I face is many 'post' types are published a day and that would generate an annoying number of test messages. So, I'm attempting to modify the code so a custom post type is used to generate SMS. I am so far unable to successfully generate a successful SMS event when publishing posts in the CPT called "SMS". Below is just one of my attempts. I try a conditional to run the code for my CPT, but it's not working (works fine for 'post' type or the default post)
function post_published_notification( $ID, $post ) {
//$post_type = get_post_type($post);
if ( get_post_type($post, get_the_ID() ) == 'SMS' ) {
$sid = '##########';
$token = '#############';
$from = '+1530#######';
$client = new Client($sid, $token);
$title = $post-post_title;
$body = sprintf('New Post: %s', $title);
$blogusers = get_users('blogid=$IDrole=subscriber');
foreach ($blogusers as $user) {
$to = get_user_meta($user-ID, 'mobile', true);
if (intval($to) == 0) {
continue;
}
$client-messages-create(
$to,
array(
'from' = $from,
'body' = $body
)
);
}
}
}
add_action('publish_post', 'post_published_notification', 10, 2);