Changeset 12018 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-profiles-wp-activity-notifier/wporg-profiles-wp-activity-notifier.php
- Timestamp:
- 08/12/2022 09:13:47 PM (4 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
r12017 r12018 28 28 } 29 29 30 /** 31 * Initialize class. 32 */ 30 33 private function __construct() { 31 34 $is_wordcamp = defined( 'IS_WORDCAMP_NETWORK' ) && IS_WORDCAMP_NETWORK; … … 50 53 } 51 54 55 /** 56 * Register hook callbacks. 57 */ 52 58 public function init() { 53 59 add_action( 'transition_post_status', array( $this, 'maybe_notify_new_published_post' ), 10, 3 ); … … 56 62 add_action( 'wp_insert_comment', array( $this, 'insert_comment' ), 10, 2 ); 57 63 58 // bbPress 2.x topic support 64 // bbPress 2.x topic support. 59 65 add_action( 'bbp_new_topic', array( $this, 'notify_forum_new_topic' ), 12 ); 60 66 add_action( 'bbp_spammed_topic', array( $this, 'notify_forum_remove_topic' ) ); … … 66 72 add_action( 'wporg_bbp_archived_topic', array( $this, 'notify_forum_remove_topic' ) ); 67 73 68 // bbPress 2.x reply support 74 // bbPress 2.x reply support. 69 75 add_action( 'bbp_new_reply', array( $this, 'notify_forum_new_reply' ), 12 ); 70 76 add_action( 'bbp_spammed_reply', array( $this, 'notify_forum_remove_reply' ) ); … … 80 86 * Indicates whether it is permitted to notify about a post or not. 81 87 * 82 * @param WP_Post $post The post 88 * @param WP_Post $post The post. 83 89 * @param string $action 'publish' for new posts, 'update' for existing posts, 'comment' for new comments. 84 90 * … … 107 113 if ( is_plugin_active( 'subscribers-only.php' ) ) { 108 114 $notifiable = false; 109 } 110 111 elseif ( ! in_array( $post->post_type, $notifiable_post_types, true ) ) { 112 $notifiable = false; 113 } 114 115 elseif ( 'publish' != $post->post_status ) { 116 $notifiable = false; 117 } 118 119 elseif ( ! empty( $post->post_password ) ) { 120 $notifiable = false; 121 } 122 123 // Some Handbook posts are automatically created and don't have an author. 124 elseif ( $post->wporg_markdown_source || ! $post->post_author ) { 125 $notifiable = false; 126 } 127 128 elseif ( $post->_xpost_original_permalink || str_starts_with( $post->post_name, 'xpost-' ) ) { 129 $notifiable = false; 130 } 131 132 else { 115 } elseif ( ! in_array( $post->post_type, $notifiable_post_types, true ) ) { 116 $notifiable = false; 117 } elseif ( 'publish' != $post->post_status ) { 118 $notifiable = false; 119 } elseif ( ! empty( $post->post_password ) ) { 120 $notifiable = false; 121 } elseif ( $post->wporg_markdown_source || ! $post->post_author ) { 122 // Some Handbook posts are automatically created and don't have an author. 123 $notifiable = false; 124 } elseif ( $post->_xpost_original_permalink || str_starts_with( $post->post_name, 'xpost-' ) ) { 125 $notifiable = false; 126 } else { 133 127 $notifiable = true; 134 128 } … … 140 134 * Only send notification for post getting published. 141 135 * 142 * @param string $new_status The new status for the post 143 * @param string $old_status The old status for the post 144 * @param WP_Post $post The post 136 * @param string $new_status The new status for the post. 137 * @param string $old_status The old status for the post. 138 * @param WP_Post $post The post. 145 139 */ 146 140 public function maybe_notify_new_published_post( $new_status, $old_status, $post ) { … … 164 158 * Sends activity notification for new blog post. 165 159 * 166 * @param WP_Post $post The published post 160 * @param WP_Post $post The published post. 167 161 * @param string $type 'new' for new posts, 'update' for existing ones. 168 162 */ … … 215 209 * Handler for comment creation. 216 210 * 217 * @param int $id Comment ID 218 * @param WP_Comment $comment Comment 219 */ 220 function insert_comment( $id, $comment ) {211 * @param int $id Comment ID. 212 * @param WP_Comment $comment Comment. 213 */ 214 public function insert_comment( $id, $comment ) { 221 215 if ( 1 == $comment->comment_approved ) { 222 216 $this->maybe_notify_new_approved_comment( 'approved', '', $comment ); … … 227 221 * Only send notification for comment getting published on a public post. 228 222 * 229 * @param string $new_status The new status for the comment 230 * @param string $old_status The old status for the comment 231 * @param WP_Comment $comment The comment 223 * @param string $new_status The new status for the comment. 224 * @param string $old_status The old status for the comment. 225 * @param WP_Comment $comment The comment. 232 226 */ 233 227 public function maybe_notify_new_approved_comment( $new_status, $old_status, $comment ) { … … 250 244 * Sends activity notification for new comment. 251 245 * 252 * @param WP_Comment $comment The comment 253 * @param WP_Post $post The comment's post 246 * @param WP_Comment $comment The comment. 247 * @param WP_Post $post The comment's post. 254 248 */ 255 249 private function notify_new_approved_comment( $comment, $post ) { … … 286 280 * @access private 287 281 * 288 * @param string $activity .The activity type. One of: create-topic, remove-topic.289 * @param int $topic_id Topic ID.282 * @param string $activity The activity type. One of: create-topic, remove-topic. 283 * @param int $topic_id Topic ID. 290 284 */ 291 285 private function _notify_forum_topic_payload( $activity, $topic_id ) { … … 307 301 308 302 $url = bbp_get_topic_permalink( $topic_id ); 309 // Remove moderator flags 303 // Remove moderator flags. 310 304 $url = remove_query_arg( array( 'view' ), $url ); 311 305 … … 351 345 * @access private 352 346 * 353 * @param string $activity .The activity type. One of: create-reply, remove-reply.354 * @param int $reply_id Reply ID.347 * @param string $activity The activity type. One of: create-reply, remove-reply. 348 * @param int $reply_id Reply ID. 355 349 */ 356 350 private function _notify_forum_reply_payload( $activity, $reply_id ) { … … 372 366 373 367 $url = bbp_get_reply_url( $reply_id ); 374 // Remove moderator flags 368 // Remove moderator flags. 375 369 $url = remove_query_arg( array( 'view' ), $url ); 376 370 … … 451 445 // Remove blockquoted text since the text isn't original. 452 446 $text = preg_replace( '/<blockquote>.+?<\/blockquote>/s', '', $text ); 453 454 447 $text = trim( strip_tags( $text ) ); 455 448 … … 475 468 $text .= '…'; 476 469 } 477 } 478 479 // Else trim by words. 480 else { 470 } else { 471 // Else trim by words. 481 472 $text = wp_trim_words( $text, $length ); 482 473 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)