Wordpress Schedule post功能不起作用


Wordpress Schedule post function not working?

我正在开发一个插件,当使用发布帖子时,该插件会发送电子邮件

 add_action('save_post','my_function');
 my_function($post_id)
 {
  //do everything here
 }

无论何时发布新帖子或从快速编辑、更新,它都可以正常工作

但问题是,当一篇文章被安排在未来发布时,它就不起作用了,为此我在谷歌上搜索了一下,发现了以下

  add_action('publish_future_post', 'my_function');

这与用于上述动作的功能相同,

我还发现以下一些结果的行动,

  add_action('future_to_publish', 'my_function');

但最后2个动作不起作用,意味着它没有发送任何电子邮件,

有人能帮我弄清楚吗,

@Andrew Bartel

这是我的完整功能,

  function my_function($post_id) {
   $post= get_post($post_id);
    if ($post->post_type == 'post' && $post->post_status == 'publish') {
     global $current_user;
  get_currentuserinfo();
  $usernamme = $current_user->user_login;
  $email= $current_user->user_email;
  $fname = $current_user->user_firstname;
  $lname = $current_user->user_lastname;
 $disname =  $current_user->display_name;
 $id =  $current_user->ID;
 $user = new WP_User($id);

if ( !empty( $user->roles ) && is_array( $user->roles ) ) 
{
    foreach ( $user->roles as $role )
        $user_role = $role;
        $upper = ucfirst($user_role);
}
$email_post_options = get_option('email_post_options');
$adminemail =(!empty($email_post_options['adminemail'])) ? $email_post_options['adminemail'] : get_bloginfo('admin_email');
if(isset($email_post_options['rol']))
{
            $msg = '';
            $postdet = get_post($post_id);
            $title = $postdet->post_title;
            //$excerpt = substr($postdet->post_content,0,150);
            $pdate = $postdet->post_date;
            $permalink = get_permalink($post_id);
            $price = get_post_meta( $post_id, '_my_meta_value_key', true );
            $date = get_post_meta( $post_id, '_my_meta_date_key', true );

    foreach($email_post_options['rol'] as $mailrol) // the roles which are saved from the plugin settings page, which is telling that who's role email will be received when a new post from the user is created.
    {

         if($mailrol==$upper)
         {
             $name = $fname.' '.$lname;
            $usename = ($name!=' ')? $name : $usernamme;

            $msg .='Full Name / Username : ' .$usename."'n";
            $msg .='Title : '.$title."'n";
            //$msg .='<p>Content : '.$excerpt.'</p>';
            $msg .='Link = '.$permalink."'n";
            $msg .='Price is = '.$price."'n";
            $msg .='Added date = '.$date."'n";
            $msg .='Published date = '.$pdate."'n";
            $msg .='Total Posts : '.count_user_posts($id)."'n";
            echo $msg;
            if($email_post_options['npemail']==1)
            {
                wp_mail($adminemail, 'New Post', $msg);
            }

         }
    }
}
  } // end if
} // end function

这是我的职责,如果你对此有任何困惑,请告诉我。

在第3行,您正在检查帖子的postrongtatus,并明确检查发布,这只为(您猜到了)发布的帖子设置。当一篇文章计划稍后发布时,它的状态设置为"未来"。例如,前三行:

function my_function($post_id) {
    $post= get_post($post_id);
    if ($post->post_type == 'post' && ($post->post_status == 'publish' || $post->post_status == 'future') ) {

如果这对你有用,请告诉我。