Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wp_是自定义发布类型的发布版本(),始终返回false_Php_Wordpress - Fatal编程技术网

Php wp_是自定义发布类型的发布版本(),始终返回false

Php wp_是自定义发布类型的发布版本(),始终返回false,php,wordpress,Php,Wordpress,我正在使用wp_-mail()在发布新的自定义帖子类型sfwd-lessons时发送电子邮件 我只希望这是发送新的职位,而不是修订 $revisions = wp_get_post_revisions( $post->ID ); if( count( $revisions ) === 0 ) { //Send an email } 我认为这只会发送新的帖子: if ( !wp_is_post_revision( $post_id ) ) { …但当现有帖子更新时,它仍在发送

我正在使用
wp_-mail()
在发布新的自定义帖子类型
sfwd-lessons
时发送电子邮件

我只希望这是发送新的职位,而不是修订

$revisions = wp_get_post_revisions( $post->ID );

if( count( $revisions ) === 0 ) {
    //Send an email
}
我认为这只会发送新的帖子:

if ( !wp_is_post_revision( $post_id ) ) { 
…但当现有帖子更新时,它仍在发送电子邮件

完整代码:

// SEND EMAIL ONCE LESSON IS CREATED
function notify_subscriber_new_lesson($post_id) {

    //verify post is not a revision 
if ( !wp_is_post_revision( $post_id ) ) { 

        //gets subscribers to send email to
        // WP_User_Query arguments
        $args = array (
            'role'           => 'Subscriber',
        );


        // The User Query
        $user_query = new WP_User_Query( $args );

        // get email addresses from user objects
         $email_addresses = array();
        foreach ( $user_query->results as $user ) {
            $email_addresses[] = $user->user_email;
        }

        // build message
        $post_title = get_the_title( $post_id ); 
        $post_url = get_permalink( $post_id ); 
        $subject = 'Now available: ' . $post_title; 
        $url = "<a href='". $post_url. "'>" .$post_title. "</a>"; 

            ob_start(); ?>

    <html>
        <head>
            <title>New Download at Website</title>
        </head>
        <body>
            <p>
                Hi <?php echo $user->user_firstname?>,
            </p>
            <p>
                The latest easy to download Video and Podcast is available!
            </p>
            <p>
                <?php echo $url ?>
            </p>
            <p>
                Be sure to log in, download, and gain those Points!
            </p>
            <p>
                Regards,<br />
                Site Owner,<br />
                Company.
            </p>
        </body>
    </html>

    <?php
    $message = ob_get_contents();

    ob_end_clean();

        //send email to all emails
        wp_mail($email_addresses, $subject, $message );
}
}
add_action( 'publish_sfwd-lessons', 'notify_subscriber_new_lesson' );
//创建课程后发送电子邮件
函数通知订户新课程($post\U id){
//验证post不是修订版
如果(!wp_是_post_修订($post_id)){
//获取要向其发送电子邮件的订阅服务器
//WP\u用户\u查询参数
$args=数组(
'角色'=>'订户',
);
//用户查询
$user\u query=新的WP\u user\u查询($args);
//从用户对象获取电子邮件地址
$email_addresses=array();
foreach($user\u query->results as$user){
$email\u addresses[]=$user->user\u email;
}
//构建消息
$post\u title=获取\u标题($post\u id);
$post\u url=get\u permalink($post\u id);
$subject='Now available:'。$post_title;
$url=”“;
ob_start();?>
新网页下载

你好

最新的易于下载的视频和播客可用!

确保登录、下载并获得这些积分!

问候,
网站所有者,
公司。


您应该使用函数wp\u get\u post\u revisions()

$revisions = wp_get_post_revisions( $post->ID );

if( count( $revisions ) === 0 ) {
    //Send an email
}

太好了!当你知道你在做什么的时候就容易了!非常感谢,Andrew@JakeLunniss我不知道我在做什么,我只是看了文档lol你很受欢迎,伙计:)