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

前端之家收集整理的这篇文章主要介绍了WordPress投稿功能添加邮件提醒功能的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="content14">
<p style="PADDING-BOTTOM: 5px; WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; FONT: 14px/22px 宋体; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0); WORD-SPACING: 0px; PADDING-TOP: 5px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">

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


<p style="PADDING-BOTTOM: 5px; WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,0); WORD-SPACING: 0px; PADDING-TOP: 5px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">  打开wordpress添加投稿功能,下面我们将对这篇文章中的代码进行修改。在第二段代码第78行插入以下代码


<pre style="BORDER-BOTTOM: rgb(187,187,187) 1px dashed; BORDER-LEFT: rgb(187,187) 5px solid; PADDING-BOTTOM: 3px; WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255); TEXT-INDENT: 0px; MARGIN: 8px; PADDING-LEFT: 3px; WIDTH: 600px; PADDING-RIGHT: 3px; FONT: 14px/22px Consolas,Monaco,"Bitstream Vera Sans Mono","Courier New",Courier,monospace; WORD-WRAP: break-word; WHITE-SPACE: pre-wrap; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0); BORDER-TOP: rgb(187,187) 1px dashed; BORDER-RIGHT: rgb(187,187) 1px dashed; WORD-SPACING: 0px; PADDING-TOP: 3px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="sh_javascript sh_sourceCode" name="code"><span style="FONT-STYLE: normal; COLOR: rgb(255,0); FONT-WEIGHT: normal" class="sh_comment">// 其中 ludou_tougao_email 是自定义栏目的名称
<span style="FONT-STYLE: normal; COLOR: rgb(0,0); FONT-WEIGHT: bold" class="sh_function">addpostMeta<span class="sh_symbol">($status<span class="sh_symbol">, <span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string">'ludou_tougao_email'<span class="sh_symbol">, $email<span class="sh_symbol">, TRUE<span class="sh_symbol">);
<p style="PADDING-BOTTOM: 5px; WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,0); WORD-SPACING: 0px; PADDING-TOP: 5px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">

二、添加提醒功能PHP代码


<p style="PADDING-BOTTOM: 5px; WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,0); WORD-SPACING: 0px; PADDING-TOP: 5px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">  在主题目录下的functions.PHP添加以下PHP代码(将以下代码中的露兜博客名称和URL改成你自己的):


<pre style="BORDER-BOTTOM: rgb(187,187) 1px dashed; WORD-SPACING: 0px; PADDING-TOP: 3px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="sh_javascript sh_sourceCode" name="code"><span style="FONT-STYLE: normal; COLOR: rgb(165,42,42); FONT-WEIGHT: normal" class="sh_keyword">function <span style="FONT-STYLE: normal; COLOR: rgb(0,0); FONT-WEIGHT: bold" class="sh_function">tougao_notify<span class="sh_symbol">($mypost<span class="sh_symbol">) <span class="sh_cbracket">{
$email <span class="sh_symbol">= <span style="FONT-STYLE: normal; COLOR: rgb(0,0); FONT-WEIGHT: bold" class="sh_function">get_post_meta<span class="sh_symbol">($mypost<span class="sh_symbol">->ID<span class="sh_symbol">,255); FONT-WEIGHT: normal" class="sh_string">"ludou_tougao_email"<span class="sh_symbol">, <span style="FONT-STYLE: normal; COLOR: rgb(165,42); FONT-WEIGHT: normal" class="sh_keyword">true<span class="sh_symbol">);

<span style="FONT-STYLE: normal; COLOR: rgb(165,42); FONT-WEIGHT: normal" class="sh_keyword"&gt;if<span class="sh_symbol"&gt;( <span class="sh_symbol"&gt;!<span style="FONT-STYLE: normal; COLOR: rgb(0,0); FONT-WEIGHT: bold" class="sh_function"&gt;empty<span class="sh_symbol"&gt;($email<span class="sh_symbol"&gt;) <span class="sh_symbol"&gt;) <span class="sh_cbracket"&gt;{
    <span style="FONT-STYLE: normal; COLOR: rgb(255,0); FONT-WEIGHT: normal" class="sh_comment"&gt;// 以下是<a href="https://www.jb51.cc/tag/youjian/" target="_blank" class="keywords">邮件</a><a href="https://www.jb51.cc/tag/biaoti/" target="_blank" class="keywords">标题</a>
    $subject <span class="sh_symbol"&gt;= <span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string"&gt;'您在露兜<a href="https://www.jb51.cc/tag/boke/" target="_blank" class="keywords">博客</a>的投稿已发布'<span class="sh_symbol"&gt;;
    <span style="FONT-STYLE: normal; COLOR: rgb(255,0); FONT-WEIGHT: normal" class="sh_comment"&gt;// 以下是<a href="https://www.jb51.cc/tag/youjian/" target="_blank" class="keywords">邮件</a><a href="https://www.jb51.cc/tag/neirong/" target="_blank" class="keywords">内容</a>
    $message <span class="sh_symbol"&gt;= <span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string"&gt;'

<span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string">

露兜博客

提醒您: 您投递的文章

' <span class="sh_symbol">. $mypost<span class="sh_symbol">->post_title <span class="sh_symbol">. <span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string">'

已发布


<span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string">
<span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string">

您可以点击以下链接查看具体内容:

<span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string"> <a href="' <span class="sh_symbol">. <span style="FONT-STYLE: normal; COLOR: rgb(0,0); FONT-WEIGHT: bold" class="sh_function">get_permalink<span class="sh_symbol">( $mypost<span class="sh_symbol">->ID <span class="sh_symbol">) <span class="sh_symbol">. <span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string">'">点此查看完整內容


<span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string">

===================================================================


<span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string">

感谢您对 露兜博客 的关注和支持


<span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string">

该信件由系统自动发出,请勿回复,谢谢.

'<span class="sh_symbol">;

    <span style="FONT-STYLE: normal; COLOR: rgb(0,0); FONT-WEIGHT: bold" class="sh_function"&gt;add_filter<span class="sh_symbol"&gt;(<span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string"&gt;'wp_mail_content_type'<span class="sh_symbol"&gt;,<span style="FONT-STYLE: normal; COLOR: rgb(0,0); FONT-WEIGHT: bold" class="sh_function"&gt;create_function<span class="sh_symbol"&gt;(<span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string"&gt;''<span class="sh_symbol"&gt;,255); FONT-WEIGHT: normal" class="sh_string"&gt;'return "text/html";'<span class="sh_symbol"&gt;));
    @<span style="FONT-STYLE: normal; COLOR: rgb(0,0); FONT-WEIGHT: bold" class="sh_function"&gt;wp_mail<span class="sh_symbol"&gt;( $email<span class="sh_symbol"&gt;, $subject<span class="sh_symbol"&gt;, $message <span class="sh_symbol"&gt;);
<span class="sh_cbracket"&gt;}

<span class="sh_cbracket">}

<span style="FONT-STYLE: normal; COLOR: rgb(255,0); FONT-WEIGHT: normal" class="sh_comment">// 当投稿的文章从草稿状态变更到已发布时,给投稿者发提醒邮件
<span style="FONT-STYLE: normal; COLOR: rgb(0,0); FONT-WEIGHT: bold" class="sh_function">add_action<span class="sh_symbol">(<span style="FONT-STYLE: normal; COLOR: rgb(255,255); FONT-WEIGHT: normal" class="sh_string">'draft_to_publish'<span class="sh_symbol">,255); FONT-WEIGHT: normal" class="sh_string">'tougao_notify'<span class="sh_symbol">,255); FONT-WEIGHT: normal" class="sh_number">6<span class="sh_symbol">);
<p style="PADDING-BOTTOM: 5px; WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,0); WORD-SPACING: 0px; PADDING-TOP: 5px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">  以上功能需要你的服务器支持mail函数

原文链接:https://www.f2er.com/wordpress/15416.html

猜你在找的wordpress相关文章