好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

WordPress投稿功能添加邮件提醒功能的方法

一、添加一个存储投稿者邮箱的自定义栏目

打开WordPress添加投稿功能,下面我们将对这篇文章中的代码进行修改。在第二段代码第78行插入以下代码:

// 其中 ludou_tougao_email 是自定义栏目的名称   add_post_meta($status,  'ludou_tougao_email' , $email, TRUE); 

二、添加提醒功能php代码

在主题目录下的functions.php添加以下php代码(将以下代码中的露兜博客名称和URL改成你自己的):

function  tougao_notify($mypost) {      $email = get_post_meta($mypost->ID,  "ludou_tougao_email" ,  true );         if ( !empty($email) ) {           // 以下是邮件标题           $subject =  '您在露兜博客的投稿已发布' ;           // 以下是邮件内容           $message = '          <p><strong>露兜博客</strong> 提醒您: 您投递的文章 <strong> ' . $mypost->post_title . ' </strong> 已发布</p>                <p>您可以点击以下链接查看具体内容:<br />          <a href= "' . get_permalink( $mypost->ID ) . '" >点此查看完整內容</a></p>          <p>===================================================================</p>          <p><strong>感谢您对 <a href= "https://www.tuohang.net"  target= "_blank" >露兜博客</a> 的关注和支持</strong></p>          <p><strong>该信件由系统自动发出, 请勿回复, 谢谢.</strong></p>';                    add_filter( 'wp_mail_content_type' ,create_function( '' ,  'return "text/html";' ));          @wp_mail( $email, $subject, $message );      }  }    // 当投稿的文章从草稿状态变更到已发布时,给投稿者发提醒邮件   add_action( 'draft_to_publish' ,  'tougao_notify' , 6); 

以上功能需要你的服务器支持mail函数。

查看更多关于WordPress投稿功能添加邮件提醒功能的方法的详细内容...

  阅读:54次