我正在开发一个使用
发布帖子时发送电子邮件的插件 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');
但最后两项行动无效,意味着它没有发送任何电子邮件,
任何人都可以帮我弄清楚,
答案 0 :(得分:0)
@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
它的功能,如果您对此有任何疑惑,请告诉我。
答案 1 :(得分:0)
在第3行,您正在检查帖子的post_status并明确检查发布,该发布仅针对发布(您猜对了)的帖子设置。当邮件计划稍后发布时,它的状态将设置为future。对于您的示例,前三行:
function my_function($post_id) {
$post= get_post($post_id);
if ($post->post_type == 'post' && ($post->post_status == 'publish' || $post->post_status == 'future') ) {
请告诉我这是否适合您。