內容簡介
預設情況下,bbPress 會透過一封包含大量 BCC 的郵件發送訂閱通知電子郵件。有諸多原因可以說明發送獨立郵件會更為合理。此外,此外掛會在 WP 計劃序列背景中安靜地執行,不會減慢頁面載入時間。此外,它還可以提高通知性能,減少大型網站的資料庫負載。
@mauriciogarofalo 和 @mechter 的翻譯
預設值
如果您沒有自訂此外掛,以下是您將會得到的預設值:
以 "MyBlog <[email protected]>" 的名義發送郵件 (包含您的 Blog 名稱和管理員電子郵件)
發送郵件至 "Markus <[email protected]>" (名稱為用戶在論壇上的顯示名稱,而不是他們的用戶名)
標題和內容具有更友好的預設值,使用可用的篩選器(請參閱下文)將其變成自己的。
自訂方式
您可以安裝和啟用此外掛,然後就可以使用了,但如果您希望獲得更多控制,以下是一些篩選器和代碼片段可供使用。 如果您尚未直接使用過程式碼,請參閱本頁底部的範例。
可用篩選器
bbp_subscription_email_from( $from ) // $from 可以是一個字串或陣列('name'=>string, 'address'=>string)
bbp_subscription_email_recipients( $recipients ) // $recipients 是陣列的陣列('name'=>string, 'address'=>string)
bbp_subscription_email_headers( $headers )
bbp_forum_subscription_email_subject( $subject, $forum_id, $topic_id )
bbp_forum_subscription_email_message( $message, $forum_id, $topic_id )
bbp_topic_subscription_email_subject( $subject, $forum_id, $topic_id, $reply_id )
bbp_topic_subscription_email_message( $message, $forum_id, $topic_id, $reply_id )
bbp_bounce_address( $bounce_address )
bbp_subscription_disable_async( false )
bbp_forum_subscription_disable_async( false )
bbp_topic_subscription_disable_async( false )
bbp_forum_subscription_notify_author( false )
bbp_topic_subscription_notify_author( false )
幫助程式碼片段
以下是一些提供通知所需數據的程式碼片段:
$blog_name = get_bloginfo( 'name' );
$forum_title = bbp_get_forum_title( $forum_id );
$topic_author_user_id = bbp_get_topic_author_id( $topic_id );
$topic_author_display_name = bbp_get_topic_author_display_name( $topic_id );
$topic_title = wp_specialchars_decode( strip_tags( bbp_get_topic_title( $topic_id ) ), ENT_QUOTES );
$topic_content = wp_specialchars_decode( strip_tags( bbp_get_topic_content( $topic_id ) ), ENT_QUOTES );
$topic_url = get_permalink( $topic_id );
$reply_author_user_id = bbp_get_reply_author_id( $reply_id );
$reply_author_display_name = bbp_get_topic_author_display_name( $reply_id );
$reply_content = strip_tags( bbp_get_reply_content( $reply_id ) );
$reply_url = bbp_get_reply_url( $reply_id ); // 請注意它不是使用 get_permalink() ,而是 bbp_get_reply_url()
範例
以下是一個範例,讓您新的主題通知郵件有一個好的標題。將以下內容添加到主題的functions.php 文件中。如果您的主題不具備此文件,您可以簡單地創建它,系統會自動載入。 請注意範例基本上只是上面的某個篩選器,再加上一些片段和返回語句。很簡單。
add_filter( 'bbp_forum_subscription_email_subject', function( $subject, $forum_id, $topic_id ) {
$blog_name = get_bloginfo( 'name' );
$topic_author_display_name = bbp_get_topic_author_display_name( $topic_id );
$topic_title = wp_spec
外掛標籤
開發者團隊
② 後台搜尋「AsynCRONous bbPress Subscriptions」→ 直接安裝(推薦)
原文外掛簡介
Per default, bbPress is sending subscription notification emails as one email with a bunch of BCCs. There are various reasons why it would make more sense to send individual emails. This plugin does that, quietly in the background via WP cron, without slowing down page load times. Also increases notification performance and reduces database load on large sites.
Translations by @mauriciogarofalo and @mechter
Defaults
If you don’t customize this plugin, this is what you’ll get:
Sends mails from "MyBlog
Sends mail to "Markus
Subject and Message have more user friendly defaults, use the available filters (see below) to make them your own.
Customization
You can install and activate this plugin and it just works, but you have full control over the details if you want to. Below are some filters and code snippets that help you do what you want. If you’re new to working directly with code, please see the example at the bottom of this page.
Available filters
bbp_subscription_email_from( $from ) // $from can be a string or array('name'=>string, 'address'=>string)
bbp_subscription_email_recipients( $recipients ) // $recipients is array of array('name'=>string, 'address'=>string)
bbp_subscription_email_headers( $headers )
bbp_forum_subscription_email_subject( $subject, $forum_id, $topic_id )
bbp_forum_subscription_email_message( $message, $forum_id, $topic_id )
bbp_topic_subscription_email_subject( $subject, $forum_id, $topic_id, $reply_id )
bbp_topic_subscription_email_message( $message, $forum_id, $topic_id, $reply_id )
bbp_bounce_address( $bounce_address )
bbp_subscription_disable_async( false )
bbp_forum_subscription_disable_async( false )
bbp_topic_subscription_disable_async( false )
bbp_forum_subscription_notify_author( false )
bbp_topic_subscription_notify_author( false )
Helpful Snippets
Here are some pointers to get the data you might want in your notifications:
$blog_name = get_bloginfo( 'name' );
$forum_title = bbp_get_forum_title( $forum_id );
$topic_author_user_id = bbp_get_topic_author_id( $topic_id );
$topic_author_display_name = bbp_get_topic_author_display_name( $topic_id );
$topic_title = wp_specialchars_decode( strip_tags( bbp_get_topic_title( $topic_id ) ), ENT_QUOTES );
$topic_content = wp_specialchars_decode( strip_tags( bbp_get_topic_content( $topic_id ) ), ENT_QUOTES );
$topic_url = get_permalink( $topic_id );
$reply_author_user_id = bbp_get_reply_author_id( $reply_id );
$reply_author_display_name = bbp_get_topic_author_display_name( $reply_id );
$reply_content = strip_tags( bbp_get_reply_content( $reply_id ) );
$reply_url = bbp_get_reply_url( $reply_id ); // note that it's not get_permalink()
Example
To have a nice subject line for new topic notifications, add this to your theme’s functions.php. If your theme does not have this file, you can simply create it and it will be loaded automatically. Note how the example is basically just one of the filters above, mixed with some of the snippets and a return statement. It’s that simple.
add_filter( 'bbp_forum_subscription_email_subject', function( $subject, $forum_id, $topic_id ) {
$blog_name = get_bloginfo( 'name' );
$topic_author_display_name = bbp_get_topic_author_display_name( $topic_id );
$topic_title = wp_specialchars_decode( strip_tags( bbp_get_topic_title( $topic_id ) ), ENT_QUOTES );
return "[$blog_name] $topic_author_display_name created a new topic: $topic_title";
}, 10, 3); // first is priority (10 is default and just fine), second is number of arguments your filter expects
