Changeset 3920
- Timestamp:
- 09/01/2016 09:01:57 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-profiles-wp-activity-notifier/wporg-profiles-wp-activity-notifier.php
r3325 r3920 19 19 add_action( 'transition_comment_status', array( $this, 'maybe_notify_new_approved_comment' ), 10, 3 ); 20 20 add_action( 'wp_insert_comment', array( $this, 'insert_comment' ), 10, 2 ); 21 22 // bbPress 2.x topic support 23 add_action( 'bbp_new_topic', array( $this, 'notify_forum_new_topic' ), 12 ); 24 add_action( 'bbp_spammed_topic', array( $this, 'notify_forum_remove_topic' ) ); 25 add_action( 'bbp_unspammed_topic', array( $this, 'notify_forum_new_topic' ) ); 26 add_action( 'bbp_trashed_topic', array( $this, 'notify_forum_remove_topic' ) ); 27 add_action( 'bbp_untrashed_topic', array( $this, 'notify_forum_new_topic' ) ); 28 add_action( 'bbp_approved_topic', array( $this, 'notify_forum_new_topic' ) ); 29 add_action( 'bbp_unapproved_topic', array( $this, 'notify_forum_remove_topic' ) ); 30 31 // bbPress 2.x reply support 32 add_action( 'bbp_new_reply', array( $this, 'notify_forum_new_reply' ), 12 ); 33 add_action( 'bbp_spammed_reply', array( $this, 'notify_forum_remove_reply' ) ); 34 add_action( 'bbp_unspammed_reply', array( $this, 'notify_forum_new_reply' ) ); 35 add_action( 'bbp_approved_reply', array( $this, 'notify_forum_new_reply' ) ); 36 add_action( 'bbp_unapproved_reply', array( $this, 'notify_forum_remove_reply' ) ); 37 add_action( 'bbp_trashed_reply', array( $this, 'notify_forum_remove_reply' ) ); 38 add_action( 'bbp_untrashed_reply', array( $this, 'notify_forum_new_reply' ) ); 21 39 } 22 40 … … 180 198 } 181 199 200 /** 201 * Handler to actual send topic-related activity payload. 202 * 203 * @access private 204 * 205 * @param string $activity. The activity type. One of: create-topic, remove-topic. 206 * @param int $topic_id Topic ID. 207 */ 208 private function _notify_forum_topic_payload( $activity, $topic_id ) { 209 210 // Don't notify if importing. 211 if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { 212 return; 213 } 214 215 // Bail if site is private. 216 if ( ! bbp_is_site_public() ) { 217 return; 218 } 219 220 // Only handle recognized activities. 221 if ( ! in_array( $activity, array( 'create-topic', 'remove-topic' ) ) ) { 222 return; 223 } 224 225 // Bail on create-topic if topic is not published. 226 if ( 'create-topic' === $activity && ! bbp_is_topic_published( $topic_id ) ) { 227 return; 228 } 229 230 $args = array( 231 'body' => array( 232 'action' => 'wporg_handle_activity', 233 'activity' => $activity, 234 'source' => 'forum', 235 'user' => get_user_by( 'id', bbp_get_topic_author_id( $topic_id ) )->user_login, 236 'post_id' => '', 237 'topic_id' => $topic_id, 238 'forum_id' => bbp_get_topic_forum_id( $topic_id ), 239 'title' => bbp_get_topic_title( $topic_id ), 240 'url' => bbp_get_topic_permalink( $topic_id ), 241 'message' => bbp_get_topic_excerpt( $topic_id, 55 ), 242 'site' => get_bloginfo( 'name' ), 243 'site_url' => site_url(), 244 ) 245 ); 246 247 $x = wp_remote_post( $this->activity_handler_url, $args ); 248 } 249 250 /** 251 * Handler for bbPress 2.x topic creation. 252 * 253 * @param int $topic_id Topic ID. 254 */ 255 public function notify_forum_new_topic( $topic_id ) { 256 $this->_notify_forum_topic_payload( 'create-topic', $topic_id ); 257 } 258 259 /** 260 * Handler for bbPress 2.x topic removal. 261 * 262 * @param int $topic_id Topic ID. 263 */ 264 public function notify_forum_remove_topic( $topic_id ) { 265 $this->_notify_forum_topic_payload( 'remove-topic', $topic_id ); 266 } 267 268 /** 269 * Handler to actual send reply-related activity payload. 270 * 271 * @access private 272 * 273 * @param string $activity. The activity type. One of: create-reply, remove-reply. 274 * @param int $reply_id Reply ID. 275 */ 276 private function _notify_forum_reply_payload( $activity, $reply_id ) { 277 278 // Don't notify if importing. 279 if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { 280 return; 281 } 282 283 // Bail if site is private. 284 if ( ! bbp_is_site_public() ) { 285 return; 286 } 287 288 // Only handle recognized activities. 289 if ( ! in_array( $activity, array( 'create-reply', 'remove-reply' ) ) ) { 290 return; 291 } 292 293 // Bail on create-reply if not published. 294 if ( 'create-reply' === $activity && ! bbp_is_reply_published( $reply_id ) ) { 295 return; 296 } 297 298 $args = array( 299 'body' => array( 300 'action' => 'wporg_handle_activity', 301 'activity' => $activity, 302 'source' => 'forum', 303 'user' => get_user_by( 'id', bbp_get_reply_author_id( $reply_id ) )->user_login, 304 'post_id' => $reply_id, 305 'topic_id' => bbp_get_reply_topic_id( $reply_id ), 306 'forum_id' => bbp_get_reply_forum_id( $reply_id ), 307 'title' => bbp_get_reply_topic_title( $reply_id ) , 308 'url' => bbp_get_reply_url( $reply_id ), 309 'message' => bbp_get_reply_excerpt( $reply_id, 55 ), 310 'site' => get_bloginfo( 'name' ), 311 'site_url' => site_url(), 312 ) 313 ); 314 315 wp_remote_post( $this->activity_handler_url, $args ); 316 317 } 318 319 /** 320 * Handler for bbPress 2.x topic reply creation. 321 * 322 * @param int $reply_id Reply ID. 323 */ 324 public function notify_forum_new_reply( $reply_id ) { 325 $this->_notify_forum_reply_payload( 'create-reply', $reply_id ); 326 } 327 328 /** 329 * Handler for bbPress 2.x topic reply removal. 330 * 331 * @param int $reply_id Reply ID. 332 */ 333 public function notify_forum_remove_reply( $reply_id ) { 334 $this->_notify_forum_reply_payload( 'remove-reply', $reply_id ); 335 } 336 182 337 } 183 338
Note: See TracChangeset
for help on using the changeset viewer.