dongzhi4498 2015-09-26 21:27
浏览 46
已采纳

上传视频时向作者和管理员发送电子邮件通知的功能

I've been struggling; can anyone help please?

I need the Wordpress Templatic Video theme to send a copy of the email that is sent to users when they upload a new video, to admin as well. Then admin will know to login and publish the video.

The theme should do this, but it doesn't. So, I'm having a go

The theme URL is: http://www.wordpressdirectorytemplates.com/motaz/video

The function that sends an email when users upload a video is:

    /* send email of video post & update submit*/
    global $post;
    $post = get_post($last_postid);
    $author = $post->post_author;
    $name = get_the_author_meta( 'display_name', $author );
    $email = get_the_author_meta( 'user_email', $author );
    $title = $post->post_title;

    $to[] = sprintf( '%s <%s>', $name, $email );
    $subject = sprintf( 'Video Post: %s', $title );
    $message = '';

$message .= "<p>Dear $name</p>";
if(isset($_REQUEST['pid']) && $_REQUEST['pid']!="")
{
        $message .= '<p class="sucess_msg_prop">'. __('Thank you for submitting your video at our site, your request has been updated successfully.','templatic').'</p>';
}else{
   /* if user set by default status publish than show different message */
        $theme_settings = get_option('video_theme_settings');
        if(isset($theme_settings['video_default_status']) && $theme_settings['video_default_status'] == 'publish'){
            $message .= '<p class="sucess_msg_prop">'.__('The video will goes live on the site.','templatic').'</p>';                
        }else{
            $message .= '<p class="sucess_msg_prop">'.__('The video will require admin approval before it goes live on the site.','templatic').'</p>';
            $message .= '<p class="sucess_msg_prop">'.__('You will get an email confirmation once your video has been published.','templatic').'</p>';
        }
}
    $message .= "<p>You can view your video on the following link</p>"; 
    $message .= '<a href="'.get_permalink($last_postid).'">'.get_permalink($last_postid).'</a>';    
    $message .= "<p>Thank you</p>";

    $headers  = 'MIME-Version: 1.0' . "
";
    $headers .= 'Content-type: text/html; charset=UTF-8' . "
";

    $fromEmail = get_option('admin_email');
    $fromEmailName = stripslashes(get_option('blogname'));

    wp_mail( $to, $subject, $message, $headers ); 

    wp_redirect(site_url().'/?page=success&pid='.$last_postid);
    exit;
}   

}

I can get the email to go to admin instead of the user by adding:

    $multiple_recipients = array(
'info@example.com');

And, then putting $multiple_recipients at the start of:

    wp_mail($multiple_recipients , $to, $subject, $message, $headers ); 

But, this is plain wrong. Admin does get an email, but the user doesn't get theirs.

I also tried adding a function to the child theme functions file using the WP Codex for help; but, this is incorrect too:

    function email_friends( $post_ID ) {
    $friends = 'info@example.com';
    wp_mail( $friends, "New Video Uploaded", 'A new video has been uploaded on http://nuntim.com');

    return $post_ID;

    }
    add_action( 'function video_posts_submition_success_msg_fn', 'email_friends' );

Can anyone point me in the right direction?

  • 写回答

1条回答 默认 最新

  • doutouman6245 2015-09-27 09:46
    关注

    you did a wrong add action see the wiki here,

    is the hook video_posts_submition_success_msg_fn exist? if yes, you can add action with something like this

    function email_friends( $post_ID ) {
    
        // may you can play with $post_ID here
    
        $friends = 'info@example.com';
        wp_mail( $friends, "New Video Uploaded", 'A new video has been uploaded on http://nuntim.com');
    
        // return $post_ID; // add_action doesn't have return
    }
    add_action( 'video_posts_submition_success_msg_fn', 'email_friends', 10, 1 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?