Changeset 11978
- Timestamp:
- 07/19/2022 06:01:45 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-emails.php
r11563 r11978 5 5 * Support Forum Email modifications. 6 6 * 7 * This filters outgoing bbPress emails to 'unroll' subscription emails from a set of BCC's to individual emails. 7 * This provides some overrides to work around limitations / bugs in bbPress related to email. 8 * 1. Filters outgoing bbPress emails to 'unroll' subscription emails from a set of BCC's to individual emails. 9 * 2. Sends subscription emails upon approval for topics/replies. 8 10 */ 9 11 class Emails { 12 const SUBSCRIPTIONS_TRIGGER_KEY = '_wporg_trigger_notifications_on_approve'; 10 13 11 14 public function __construct() { … … 17 20 add_action( 'bbp_pre_notify_subscribers', [ $this, 'start_unroll' ] ); 18 21 add_action( 'bbp_post_notify_subscribers', [ $this, 'stop_unroll' ] ); 19 } 22 23 // Subscriptions - Send subscriptions after approval/unspam. 24 add_action( 'bbp_new_topic', [ $this, 'bbp_new_topic' ], 20, 2 ); 25 add_action( 'bbp_new_reply', [ $this, 'bbp_new_reply' ], 20, 3 ); 26 27 add_action( 'bbp_unspammed_topic', [ $this, 'maybe_trigger_bbp_new_topic' ], 10, 1 ); 28 add_action( 'bbp_approved_topic', [ $this, 'maybe_trigger_bbp_new_topic' ], 10, 1 ); 29 //add_action( 'bbp_untrashed_topic', [ $this, 'maybe_trigger_bbp_new_topic' ], 10, 1 ); 30 31 add_action( 'bbp_unspammed_reply', [ $this, 'maybe_trigger_bbp_new_reply' ], 10, 1 ); 32 add_action( 'bbp_approved_reply', [ $this, 'maybe_trigger_bbp_new_reply' ], 10, 1 ); 33 //add_action( 'bbp_untrashed_reply', [ $this, 'maybe_trigger_bbp_new_reply' ], 10, 1 ); 34 } 35 36 // --- Email BCC unrolling... 20 37 21 38 /** … … 108 125 return $filter_return; 109 126 } 127 128 // --- bbPress not sending notifications if it's caught in spam/moderation queue 129 130 /** 131 * Add postmeta to new unpublished replies, to send notifications once it's published. 132 */ 133 public function bbp_new_reply( $reply_id, $topic_id, $forum_id ) { 134 if ( bbp_is_reply_published( $reply_id ) && bbp_is_topic_public( $topic_id ) ) { 135 return; 136 } 137 138 add_post_meta( $reply_id, self::SUBSCRIPTIONS_TRIGGER_KEY, 1 ); 139 } 140 141 /** 142 * Add postmeta to new unpublished topics, to send notifications once it's published. 143 */ 144 public function bbp_new_topic( $topic_id, $forum_id ) { 145 if ( bbp_is_topic_public( $topic_id ) ) { 146 return; 147 } 148 149 add_post_meta( $topic_id, self::SUBSCRIPTIONS_TRIGGER_KEY, 1 ); 150 } 151 152 /** 153 * Send forum subscriptions for a previously-unpublished topic. 154 */ 155 public function maybe_trigger_bbp_new_topic( $topic_id ) { 156 if ( ! get_post_meta( $topic_id, self::SUBSCRIPTIONS_TRIGGER_KEY, true) ) { 157 return; 158 } 159 160 if ( ! bbp_is_topic_public( $topic_id ) ) { 161 return; 162 } 163 164 $forum_id = bbp_get_topic_forum_id( $topic_id ); 165 $topic_author = bbp_get_reply_author_id( $reply_id ); 166 167 // Remove the bbPress topic update handler 168 remove_action( 'bbp_new_topic', 'bbp_update_topic' ); 169 170 // Call the bbp_new_topic action.. 171 do_action( 'bbp_new_topic', $topic_id, $forum_id, array(), $topic_author ); 172 173 add_action( 'bbp_new_topic', 'bbp_update_topic', 10, 5 ); // bbPress requests 5, but calls it with 4.. 174 175 delete_post_meta( $topic_id, self::SUBSCRIPTIONS_TRIGGER_KEY ); 176 } 177 178 /** 179 * Send topic subscriptions for a previously-unpublished topic. 180 */ 181 public function maybe_trigger_bbp_new_reply( $reply_id ) { 182 if ( ! get_post_meta( $reply_id, self::SUBSCRIPTIONS_TRIGGER_KEY, true ) ) { 183 return; 184 } 185 186 $topic_id = bbp_get_reply_topic_id( $reply_id ); 187 $forum_id = bbp_get_topic_forum_id( $topic_id ); 188 $reply_author = bbp_get_reply_author_id( $reply_id ); 189 190 if ( ! bbp_is_reply_published( $reply_id ) || ! bbp_is_topic_public( $topic_id ) ) { 191 return; 192 } 193 194 remove_action( 'bbp_new_reply', 'bbp_update_reply' ); 195 196 do_action( 'bbp_new_reply', $reply_id, $topic_id, $forum_id, array(), $reply_author, false, false ); 197 198 add_action( 'bbp_new_reply', 'bbp_update_reply', 10, 7 ); 199 200 delete_post_meta( $reply_id, self::SUBSCRIPTIONS_TRIGGER_KEY ); 201 } 202 110 203 }
Note: See TracChangeset
for help on using the changeset viewer.