我正在尝试更改找到的插件here。这是有关组装插件的Twillio教程,该插件使用其系统在WordPress帖子“发布”时发送SMS。我面临的障碍是每天都会发布许多帖子,而我不希望发送多条短信。那会很烦人。因此,我创建了一个名为“ SMS”的自定义帖子类型。我无法配置所描述的插件以使用自定义帖子类型,而不是初始配置中使用默认或“ post” wordpress提供的插件。
// Prepares SMS to be sent when post is published
// function post_published_notifications($ID, $post ) //Original plugin function. I'm unsure of how to reassign global $post
function post_published_notification($ID) // I added this trying to access CPT, sans $post
{
$sid = '####################';
$token = '######################';
$from = '+1530#######';
$client = new Client($sid, $token);
$gallery_args = array(
'post_type'=> 'SMS',
);
$posts_display_gallery = get_posts( $gallery_args ); // My code that doesn't work. Trying to access the CPT named SMS
$title = $posts_display_gallery->post_title; // My code that doesn't work. Trying to assign variable to CPT title.
//$title = $post->post_title; // gets post title. Provided by Twillio. Returns post title.
$body = sprintf('New Post: %s', $title);
$blogusers = get_users('blogid=$ID&role=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 // Custom post type title should be held here.
)
);
}
}
add_action('publish_post', 'post_published_notification', 10, 2);
查看WordPress的专门用于帖子类型绑定的hooks系统,这是指向它们的相关文档的链接,其中包括:
https://developer.wordpress.org/reference/hooks/save_post_post-post_type/