gpt4 book ai didi

wordpress - 当我发布新帖子时(而不是当我更新已发布的帖子时),wordpress Hook 是什么?

转载 作者:行者123 更新时间:2023-12-02 22:45:50 24 4
gpt4 key购买 nike

我想在新帖子首次发布时(而不是编辑时)发送电子邮件

我尝试过:

add_action('publish_post', 'postPublished');

但是 postPublished 当我更新已发布的帖子时也会调用。我只想仅在第一次发布帖子时将其称为

问候

最佳答案

我认为您正在寻找的钩子(Hook)是draft_to_publish

如果您只想在新帖子上发送电子邮件,我会考虑在帖子发布时进行定位。您甚至可以查看transition_post_status Hook 并只是条件化帖子是否已被编辑,这样的事情可以工作:

function so_post_40744782( $new_status, $old_status, $post ) {
if ( $new_status == 'publish' && $old_status != 'publish' ) {
$author = "foobar";
$message = "We wanted to notify you a new post has been published.";
wp_mail($author, "New Post Published", $message);
}
}
add_action('transition_post_status', 'so_post_40744782', 10, 3 );

关于wordpress - 当我发布新帖子时(而不是当我更新已发布的帖子时),wordpress Hook 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40744782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com