Changeset 12062
- Timestamp:
- 09/14/2022 04:56:00 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
r12020 r12062 11 11 class WPOrg_WP_Activity_Notifier { 12 12 /** 13 * @var WPOrg_WP_Activity_Notifier The singleton instance. 13 * The singleton instance. 14 * 15 * @var WPOrg_WP_Activity_Notifier 14 16 */ 15 17 private static $instance; … … 154 156 } 155 157 158 /** 159 * Gutenberg sends two requests when we hit the Publish/Update button. 160 * https://github.com/WordPress/wordpress.org/pull/84#discussion_r919290748 161 * 162 * For the first request, $old_status would be different from $new_status, 163 * if the post, for example, is changed from draft to published. 164 * For the second request (from the same Publish/Update button hit), 165 * $old_status would be the same as $new_status in the same example, 166 * both their values would be 'publish'. 167 * 168 * This brings the result that only the first request from Gutenberg could 169 * pass the condition if ($old_status == $new_status) { return; }. 170 * 171 * However, only the second request would carry the data from meta boxes, 172 * which is what we need here, so we need to put this logic above that 173 * condition. 174 */ 175 if ( 'wporg_workshop' === $post->post_type ) { 176 $this->notify_workshop_presenter( $post ); 177 } 178 156 179 if ( $old_status == $new_status ) { 157 180 return; … … 165 188 } 166 189 190 /** 191 * Sends activity notification for workshop presenter. 192 * 193 * @param WP_Post $post Post object. 194 */ 195 private function notify_workshop_presenter( $post ) { 196 if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { 197 return; 198 } 199 200 $presenter_wporg_username = filter_input( INPUT_POST, 'presenter-wporg-username' ); 201 202 if ( empty( $presenter_wporg_username ) ) { 203 return; 204 } 205 206 $unique_presenter_wporg_username = array_unique( array_map( 'trim', explode( ',', $presenter_wporg_username ) ) ); 207 $permalink = get_permalink( $post ); 208 $title = wp_kses_data( $post->post_title ); 209 $content = wp_trim_words( 210 strip_shortcodes( has_excerpt( $post ) ? $post->post_excerpt : $post->post_content ), 211 55 212 ); 213 214 foreach ( $unique_presenter_wporg_username as $username ) { 215 $user_id = get_user_by( 'slug', strtolower( $username ) )->ID; 216 217 if ( ! $user_id ) { 218 continue; 219 } 220 221 $args = array( 222 'action' => 'wporg_handle_activity', 223 'component' => 'learn', 224 'type' => 'workshop_presenter_assign', 225 'user_id' => $user_id, 226 'primary_link' => $permalink, 227 'item_id' => $post->ID, 228 'content' => $content, 229 'message' => sprintf( 230 'Assigned as a presenter on the Learn WordPress tutorial, <i><a href="%s">%s</a></i>', 231 $permalink, 232 $title, 233 ), 234 ); 235 236 Profiles\api( $args ); 237 } 238 } 167 239 168 240 /** … … 294 366 * @param int $topic_id Topic ID. 295 367 */ 296 private function _notify_forum_topic_payload( $activity, $topic_id ) {368 private function notify_forum_topic_payload( $activity, $topic_id ) { 297 369 if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { 298 370 return; … … 303 375 } 304 376 305 if ( ! in_array( $activity, array( 'create-topic', 'remove-topic' ) ) ) {377 if ( ! in_array( $activity, array( 'create-topic', 'remove-topic' ), true ) ) { 306 378 return; 307 379 } … … 316 388 317 389 $args = array( 318 'action' => 'wporg_handle_activity',319 'activity' => $activity,320 'source' => 'forum',321 'user' => get_user_by( 'id', bbp_get_topic_author_id( $topic_id ) )->user_login,322 'post_id' => '',323 'topic_id' => $topic_id,324 'forum_id' => bbp_get_topic_forum_id( $topic_id ),325 'title' => strip_tags( bbp_get_topic_title( $topic_id ) ),326 'url' => $url,327 'message' => bbp_get_topic_excerpt( $topic_id, 55 ),328 'site' => get_bloginfo( 'name' ),329 'site_url' => site_url(),390 'action' => 'wporg_handle_activity', 391 'activity' => $activity, 392 'source' => 'forum', 393 'user' => get_user_by( 'id', bbp_get_topic_author_id( $topic_id ) )->user_login, 394 'post_id' => '', 395 'topic_id' => $topic_id, 396 'forum_id' => bbp_get_topic_forum_id( $topic_id ), 397 'title' => strip_tags( bbp_get_topic_title( $topic_id ) ), 398 'url' => $url, 399 'message' => bbp_get_topic_excerpt( $topic_id, 55 ), 400 'site' => get_bloginfo( 'name' ), 401 'site_url' => site_url(), 330 402 ); 331 403 … … 339 411 */ 340 412 public function notify_forum_new_topic( $topic_id ) { 341 $this-> _notify_forum_topic_payload( 'create-topic', $topic_id );413 $this->notify_forum_topic_payload( 'create-topic', $topic_id ); 342 414 } 343 415 … … 348 420 */ 349 421 public function notify_forum_remove_topic( $topic_id ) { 350 $this-> _notify_forum_topic_payload( 'remove-topic', $topic_id );422 $this->notify_forum_topic_payload( 'remove-topic', $topic_id ); 351 423 } 352 424 … … 359 431 * @param int $reply_id Reply ID. 360 432 */ 361 private function _notify_forum_reply_payload( $activity, $reply_id ) {433 private function notify_forum_reply_payload( $activity, $reply_id ) { 362 434 if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { 363 435 return; … … 368 440 } 369 441 370 if ( ! in_array( $activity, array( 'create-reply', 'remove-reply' ) ) ) {442 if ( ! in_array( $activity, array( 'create-reply', 'remove-reply' ), true ) ) { 371 443 return; 372 444 } … … 381 453 382 454 $args = array( 383 'action' => 'wporg_handle_activity',384 'activity' => $activity,385 'source' => 'forum',386 'user' => get_user_by( 'id', bbp_get_reply_author_id( $reply_id ) )->user_login,387 'post_id' => $reply_id,388 'topic_id' => bbp_get_reply_topic_id( $reply_id ),389 'forum_id' => bbp_get_reply_forum_id( $reply_id ),390 'title' => strip_tags( bbp_get_reply_topic_title( $reply_id ) ),391 'url' => $url,392 'message' => $this->get_reply_excerpt( $reply_id, 15 ),393 'site' => get_bloginfo( 'name' ),394 'site_url' => site_url(),455 'action' => 'wporg_handle_activity', 456 'activity' => $activity, 457 'source' => 'forum', 458 'user' => get_user_by( 'id', bbp_get_reply_author_id( $reply_id ) )->user_login, 459 'post_id' => $reply_id, 460 'topic_id' => bbp_get_reply_topic_id( $reply_id ), 461 'forum_id' => bbp_get_reply_forum_id( $reply_id ), 462 'title' => strip_tags( bbp_get_reply_topic_title( $reply_id ) ), 463 'url' => $url, 464 'message' => $this->get_reply_excerpt( $reply_id, 15 ), 465 'site' => get_bloginfo( 'name' ), 466 'site_url' => site_url(), 395 467 ); 396 468 … … 404 476 */ 405 477 public function notify_forum_new_reply( $reply_id ) { 406 $this-> _notify_forum_reply_payload( 'create-reply', $reply_id );478 $this->notify_forum_reply_payload( 'create-reply', $reply_id ); 407 479 } 408 480 … … 413 485 */ 414 486 public function notify_forum_remove_reply( $reply_id ) { 415 $this-> _notify_forum_reply_payload( 'remove-reply', $reply_id );487 $this->notify_forum_reply_payload( 'remove-reply', $reply_id ); 416 488 } 417 489 … … 452 524 public function trim_text( $text, $length = 15, $trim_style = 'words' ) { 453 525 $length = (int) $length; 454 $trim_style = in_array( $trim_style, array( 'chars', 'words' ) ) ? $trim_style : 'words';526 $trim_style = in_array( $trim_style, array( 'chars', 'words' ), true ) ? $trim_style : 'words'; 455 527 456 528 // Remove blockquoted text since the text isn't original. … … 479 551 $text .= '…'; 480 552 } 481 } else { 482 // Else trim by words. 553 } else { // Else trim by words. 483 554 $text = wp_trim_words( $text, $length ); 484 555 }
Note: See TracChangeset
for help on using the changeset viewer.