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 = '您在露兜博客的投稿已發(fā)布';
    // 以下是郵件內(nèi)容
    $message = '
    <p><strong>露兜博客</strong> 提醒您: 您投遞的文章 <strong>' . $mypost->post_title . '</strong> 已發(fā)布</p>
    <p>您可以點擊以下鏈接查看具體內(nèi)容:<br />
    <a href=' . get_permalink( $mypost->id ) . '>點此查看完整內(nèi)容</a></p>
    <p>===================================================================</p>
    <p><strong>感謝您對 <a href=http://www.ludou.org target=_blank>露兜博客</a> 的關(guān)注和支持</strong></p>
    <p><strong>該信件由系統(tǒng)自動發(fā)出, 請勿回復(fù), 謝謝.</strong></p>';
    add_filter('wp_mail_content_type',create_function('', 'return text/html;'));
    @wp_mail( $email, $subject, $message );
    }
    }
    // 當投稿的文章從草稿狀態(tài)變更到已發(fā)布時,給投稿者發(fā)提醒郵件
    add_action('draft_to_publish', 'tougao_notify', 6);
    以上功能需要你的服務(wù)器支持mail函數(shù)。