• 售前

  • 售后

热门帖子
入门百科

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

[复制链接]
无人岛屿颈 显示全部楼层 发表于 2021-8-15 19:29:55 |阅读模式 打印 上一主题 下一主题
一、添加一个存储投稿者邮箱的自界说栏目
  打开WordPress添加投稿功能,下面我们将对这篇文章中的代码举行修改。在第二段代码第78行插入以下代码:
  1. <span style="FONT-STYLE: normal; COLOR: rgb(255,0,0); FONT-WEIGHT: normal" class="sh_comment">// 其中 ludou_tougao_email 是自定义栏目的名称</span>
  2. <span style="FONT-STYLE: normal; COLOR: rgb(0,0,0); FONT-WEIGHT: bold" class="sh_function">add_post_meta</span><span class="sh_symbol">(</span>$status<span class="sh_symbol">,</span> <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">'ludou_tougao_email'</span><span class="sh_symbol">,</span> $email<span class="sh_symbol">,</span> TRUE<span class="sh_symbol">);</span>
复制代码
二、添加提醒功能php代码
  在主题目录下的functions.php添加以下php代码(将以下代码中的露兜博客名称和URL改成你自己的):
  1. <span style="FONT-STYLE: normal; COLOR: rgb(165,42,42); FONT-WEIGHT: normal" class="sh_keyword">function</span> <span style="FONT-STYLE: normal; COLOR: rgb(0,0,0); FONT-WEIGHT: bold" class="sh_function">tougao_notify</span><span class="sh_symbol">(</span>$mypost<span class="sh_symbol">)</span> <span class="sh_cbracket">{</span>
  2.     $email <span class="sh_symbol">=</span> <span style="FONT-STYLE: normal; COLOR: rgb(0,0,0); FONT-WEIGHT: bold" class="sh_function">get_post_meta</span><span class="sh_symbol">(</span>$mypost<span class="sh_symbol">-></span>ID<span class="sh_symbol">,</span> <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">"ludou_tougao_email"</span><span class="sh_symbol">,</span> <span style="FONT-STYLE: normal; COLOR: rgb(165,42,42); FONT-WEIGHT: normal" class="sh_keyword">true</span><span class="sh_symbol">);</span>
  3.     <span style="FONT-STYLE: normal; COLOR: rgb(165,42,42); FONT-WEIGHT: normal" class="sh_keyword">if</span><span class="sh_symbol">(</span> <span class="sh_symbol">!</span><span style="FONT-STYLE: normal; COLOR: rgb(0,0,0); FONT-WEIGHT: bold" class="sh_function">empty</span><span class="sh_symbol">(</span>$email<span class="sh_symbol">)</span> <span class="sh_symbol">)</span> <span class="sh_cbracket">{</span>
  4.         <span style="FONT-STYLE: normal; COLOR: rgb(255,0,0); FONT-WEIGHT: normal" class="sh_comment">// 以下是邮件标题</span>
  5.         $subject <span class="sh_symbol">=</span> <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">'您在露兜博客的投稿已发布'</span><span class="sh_symbol">;</span>
  6.         <span style="FONT-STYLE: normal; COLOR: rgb(255,0,0); FONT-WEIGHT: normal" class="sh_comment">// 以下是邮件内容</span>
  7.         $message <span class="sh_symbol">=</span> <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">'</span>
  8. <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">        <p><strong>露兜博客</strong> 提醒您: 您投递的文章 <strong>'</span> <span class="sh_symbol">.</span> $mypost<span class="sh_symbol">-></span>post_title <span class="sh_symbol">.</span> <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">'</strong> 已发布</p></span>
  9. <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">    </span>
  10. <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">        <p>您可以点击以下链接查看具体内容:<br /></span>
  11. <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">        <a href="'</span> <span class="sh_symbol">.</span> <span style="FONT-STYLE: normal; COLOR: rgb(0,0,0); FONT-WEIGHT: bold" class="sh_function">get_permalink</span><span class="sh_symbol">(</span> $mypost<span class="sh_symbol">-></span>ID <span class="sh_symbol">)</span> <span class="sh_symbol">.</span> <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">'">点此查看完整內容</a></p></span>
  12. <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">        <p>===================================================================</p></span>
  13. <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">        <p><strong>感谢您对 <a href="https://www.jb51.net" target="_blank">露兜博客</a> 的关注和支持</strong></p></span>
  14. <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">        <p><strong>该信件由系统自动发出, 请勿回复, 谢谢.</strong></p>'</span><span class="sh_symbol">;</span>
  15.         
  16.         <span style="FONT-STYLE: normal; COLOR: rgb(0,0,0); FONT-WEIGHT: bold" class="sh_function">add_filter</span><span class="sh_symbol">(</span><span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">'wp_mail_content_type'</span><span class="sh_symbol">,</span><span style="FONT-STYLE: normal; COLOR: rgb(0,0,0); FONT-WEIGHT: bold" class="sh_function">create_function</span><span class="sh_symbol">(</span><span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">''</span><span class="sh_symbol">,</span> <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">'return "text/html";'</span><span class="sh_symbol">));</span>
  17.         @<span style="FONT-STYLE: normal; COLOR: rgb(0,0,0); FONT-WEIGHT: bold" class="sh_function">wp_mail</span><span class="sh_symbol">(</span> $email<span class="sh_symbol">,</span> $subject<span class="sh_symbol">,</span> $message <span class="sh_symbol">);</span>
  18.     <span class="sh_cbracket">}</span>
  19. <span class="sh_cbracket">}</span>
  20. <span style="FONT-STYLE: normal; COLOR: rgb(255,0,0); FONT-WEIGHT: normal" class="sh_comment">// 当投稿的文章从草稿状态变更到已发布时,给投稿者发提醒邮件</span>
  21. <span style="FONT-STYLE: normal; COLOR: rgb(0,0,0); FONT-WEIGHT: bold" class="sh_function">add_action</span><span class="sh_symbol">(</span><span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">'draft_to_publish'</span><span class="sh_symbol">,</span> <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_string">'tougao_notify'</span><span class="sh_symbol">,</span> <span style="FONT-STYLE: normal; COLOR: rgb(255,0,255); FONT-WEIGHT: normal" class="sh_number">6</span><span class="sh_symbol">);</span>
复制代码
  以上功能需要你的服务器支持mail函数。

帖子地址: 

回复

使用道具 举报

分享
推广
火星云矿 | 预约S19Pro,享500抵1000!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

草根技术分享(草根吧)是全球知名中文IT技术交流平台,创建于2021年,包含原创博客、精品问答、职业培训、技术社区、资源下载等产品服务,提供原创、优质、完整内容的专业IT技术开发社区。
  • 官方手机版

  • 微信公众号

  • 商务合作