Changeset 14821 for sites/trunk/profiles.wordpress.org/public_html/wp-content/plugins/wporg-profiles-activity-handler/wporg-profiles-activity-handler.php
- Timestamp:
- 04/22/2026 04:17:07 AM (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/profiles.wordpress.org/public_html/wp-content/plugins/wporg-profiles-activity-handler/wporg-profiles-activity-handler.php
r14549 r14821 33 33 34 34 /** 35 * @var WPOrg_Profiles_Activity_Handler|null 36 */ 37 protected static $instance = null; 38 39 /** 40 * Returns the shared instance, constructing it on first call. 41 * 42 * Used by both the bootstrap at the bottom of this file and by the 43 * CLI queue processor to avoid duplicate hook registration. 44 */ 45 public static function get_instance() { 46 return self::$instance ??= new self(); 47 } 48 49 /** 35 50 * Constructor. 36 51 */ … … 82 97 */ 83 98 public function plugins_loaded() { 84 add_action( 'wp_ajax_nopriv_wporg_handle_activity', array( $this, ' handle_activity' ) );99 add_action( 'wp_ajax_nopriv_wporg_handle_activity', array( $this, 'ajax_handle_activity' ) ); 85 100 } 86 101 … … 156 171 157 172 /** 158 * Checks that required POSTarguments are defined and have a value.173 * Checks that required arguments are defined and have a value. 159 174 * 160 175 * Ends request and reports on any missing arguments, if necessary. 161 176 * 162 * @param array $args The array of required POST arguments. 163 */ 164 protected function require_args( $args ) { 177 * @param array $args The array of required argument names. 178 * @param array $data The request data to check against. 179 */ 180 protected function require_args( $args, array $data ) { 165 181 $missing = array(); 166 182 167 183 foreach ( $args as $arg ) { 168 if ( empty( $ _POST[ $arg ] ) ) {184 if ( empty( $data[ $arg ] ) ) { 169 185 $missing[] = $arg; 170 186 } … … 177 193 178 194 /** 179 * Primary AJAX handler. 195 * AJAX wrapper for handle_activity(). 196 * 197 * Validates the request, delegates to handle_activity(), and dies with the result. 198 */ 199 public function ajax_handle_activity() { 200 try { 201 do_action( 'wporg_profiles_before_handle_activity' ); 202 203 if ( true !== apply_filters( 'wporg_is_valid_activity_request', false ) ) { 204 status_header( 400 ); 205 die( '-1 Not a valid activity request' ); 206 } 207 208 $result = $this->handle_activity( wp_unslash( $_POST ) ); 209 210 if ( is_wp_error( $result ) ) { 211 $status = $result->get_error_data()['status'] ?? 500; 212 status_header( $status ); 213 trigger_error( $result->get_error_message(), E_USER_WARNING ); 214 die( '-1 ' . $result->get_error_message() ); 215 } 216 217 die( '1' ); 218 } catch ( Exception $exception ) { 219 status_header( 500 ); 220 trigger_error( $exception->getMessage(), E_USER_WARNING ); 221 die( '-1 ' . $exception->getMessage() ); 222 } 223 } 224 225 /** 226 * Primary handler for activity requests. 180 227 * 181 228 * Funnels incoming requests to appropriate sub-handler based on 182 * $_POST['source'] value. 183 * 184 * By default (and for security), this does nothing. The filter 185 * 'wporg_is_valid_activity_request' must be hooked in order to provide 186 * the appropriate validity checks on the request to permit the incoming 187 * activity notification to be handled. 188 * 189 * TODO: Make this a generic handler and require sub-handlers to 190 * register themselves. 191 */ 192 public function handle_activity() { 193 try { 194 /* 195 * This is useful for testing on your sandbox. 196 * 197 * e.g., Edit `$_POST['user_id']` so that activity goes to a test account rather than a real one. 198 */ 199 do_action( 'wporg_profiles_before_handle_activity' ); 200 201 // Return error if not a valid activity request. 202 if ( true !== apply_filters( 'wporg_is_valid_activity_request', false ) ) { 203 throw new Exception( '-1 Not a valid activity request' ); 204 } 205 206 // Return error if activities are not enabled. 207 if ( ! bp_is_active( 'activity' ) ) { 208 throw new Exception( '-1 Activity component not activated' ); 209 } 210 211 $source = sanitize_text_field( $_POST['source'] ?? $_POST['component'] ); 212 213 // The original `action` was the `admin-ajax.php` action, which is no longer needed. 214 // Renaming this allows simple handlers to pass the sanitized $_POST directly to `bp_activity_add()`. 215 $_POST['action'] = $_POST['message'] ?? ''; 216 217 // Slack and GlotPress sometimes include user IDs in a different location, and they always use 218 // `sanitize_activity()`, which checks for a valid user ID. Checking here too adds complexity and 219 // is unnecessary. 220 if ( ! in_array( $source, array( 'slack', 'glotpress' ), true ) ) { 221 if ( empty( $_POST['user'] ) && empty( $_POST['user_id'] ) ) { 222 throw new Exception( '-1 No user specified.' ); 223 } 224 } 225 226 // Disable default BP moderation 227 remove_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2 ); 228 remove_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2 ); 229 230 // Disable requirement that user have a display_name set 231 remove_filter( 'bp_activity_before_save', 'bporg_activity_requires_display_name' ); 232 233 // If an activity doesn't require special logic, then `add_activity()` can be called directly. Compare 234 // Learn and Slack to see the difference. 235 switch ( $source ) { 236 case 'forum': 237 $activity_id = $this->handle_forum_activity(); 238 break; 239 case 'learn': 240 $activity_id = bp_activity_add( $this->sanitize_activity( $_POST ) ); 241 break; 242 case 'glotpress': 243 $activity_id = $this->handle_glotpress_activity( $_POST ); 244 break; 245 case 'plugin': 246 $activity_id = $this->handle_plugin_activity(); 247 break; 248 case 'theme': 249 $activity_id = $this->handle_theme_activity(); 250 break; 251 case 'trac': 252 $activity_id = $this->handle_trac_activity(); 253 break; 254 case 'wordcamp': 255 $activity_id = $this->handle_wordcamp_activity(); 256 break; 257 case 'wordpress': 258 $activity_id = $this->handle_wordpress_activity(); 259 break; 260 case 'slack': 261 $activity_id = $this->handle_slack_activity(); 262 break; 263 default: 264 throw new Exception( '-1 Unrecognized activity source' ); 265 break; 266 } 267 268 if ( is_wp_error( $activity_id ) ) { 269 throw new Exception( '-1 Unable to save activity: ' . $activity_id->get_error_message() ); 270 } elseif ( str_starts_with( $activity_id, '-1' ) ) { 271 throw new Exception( $activity_id ); 272 } elseif ( false === $activity_id || intval( $activity_id ) <= 0 ) { 273 throw new Exception( '-1 Unable to save activity' ); 274 } else { 275 $this->maybe_update_last_activity(); 276 } 277 278 $response = '1'; 279 280 } catch ( Exception $exception ) { 281 trigger_error( $exception->getMessage(), E_USER_WARNING ); 282 283 $response = $exception->getMessage(); 284 } 285 286 die( $response ); 229 * $data['source'] value. 230 * 231 * @param array $data The request data. 232 * @return true|WP_Error 233 */ 234 public function handle_activity( array $data ) { 235 if ( ! bp_is_active( 'activity' ) ) { 236 return new WP_Error( 'activity_inactive', 'Activity component not activated', [ 'status' => 500 ] ); 237 } 238 239 $source = sanitize_text_field( $data['source'] ?? $data['component'] ); 240 241 // The original `action` was the `admin-ajax.php` action, which is no longer needed. 242 // Renaming this allows simple handlers to pass the sanitized data directly to `bp_activity_add()`. 243 $data['action'] = $data['message'] ?? ''; 244 245 // Slack and GlotPress sometimes include user IDs in a different location, and they always use 246 // `sanitize_activity()`, which checks for a valid user ID. Checking here too adds complexity and 247 // is unnecessary. 248 if ( ! in_array( $source, array( 'slack', 'glotpress' ), true ) ) { 249 if ( empty( $data['user'] ) && empty( $data['user_id'] ) ) { 250 return new WP_Error( 'no_user', 'No user specified.', [ 'status' => 400 ] ); 251 } 252 } 253 254 // Disable default BP moderation 255 remove_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2 ); 256 remove_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2 ); 257 258 // Disable requirement that user have a display_name set 259 remove_filter( 'bp_activity_before_save', 'bporg_activity_requires_display_name' ); 260 261 // If an activity doesn't require special logic, then `add_activity()` can be called directly. Compare 262 // Learn and Slack to see the difference. 263 switch ( $source ) { 264 case 'forum': 265 $activity_id = $this->handle_forum_activity( $data ); 266 break; 267 case 'generic': 268 case 'learn': 269 $activity_id = bp_activity_add( $this->sanitize_activity( $data ) ); 270 break; 271 case 'glotpress': 272 $activity_id = $this->handle_glotpress_activity( $data ); 273 break; 274 case 'plugin': 275 $activity_id = $this->handle_plugin_activity( $data ); 276 break; 277 case 'theme': 278 $activity_id = $this->handle_theme_activity( $data ); 279 break; 280 case 'trac': 281 $activity_id = $this->handle_trac_activity( $data ); 282 break; 283 case 'wordcamp': 284 $activity_id = $this->handle_wordcamp_activity( $data ); 285 break; 286 case 'wordpress': 287 $activity_id = $this->handle_wordpress_activity( $data ); 288 break; 289 case 'slack': 290 $activity_id = $this->handle_slack_activity( $data ); 291 break; 292 default: 293 return new WP_Error( 'unknown_source', 'Unrecognized activity source', [ 'status' => 400 ] ); 294 } 295 296 if ( is_wp_error( $activity_id ) ) { 297 return new WP_Error( 'activity_failed', 'Unable to save activity: ' . $activity_id->get_error_message(), [ 'status' => 500 ] ); 298 } elseif ( is_string( $activity_id ) && str_starts_with( $activity_id, '-1' ) ) { 299 return new WP_Error( 'activity_failed', $activity_id, [ 'status' => 500 ] ); 300 } elseif ( false === $activity_id || intval( $activity_id ) <= 0 ) { 301 return new WP_Error( 'activity_failed', 'Unable to save activity', [ 'status' => 500 ] ); 302 } 303 304 $this->maybe_update_last_activity( $data ); 305 306 return true; 287 307 } 288 308 … … 292 312 * 293 313 */ 294 public static function maybe_update_last_activity( ) {295 296 $user = self::get_user( $ _POST['user'] ?? ( $_POST['user_id'] ?? 0 ) );314 public static function maybe_update_last_activity( array $data = array() ) { 315 316 $user = self::get_user( $data['user'] ?? ( $data['user_id'] ?? 0 ) ); 297 317 if ( ! $user ) { 298 318 return; … … 317 337 318 338 /** 319 * Sanitize `$_POST`args intended for `bp_activity_add()`.339 * Sanitize request args intended for `bp_activity_add()`. 320 340 * 321 341 * @throws Exception … … 374 394 * - Removing a topic reply 375 395 */ 376 private function handle_forum_activity( ) {377 $user = self::get_user( $ _POST['user'] );396 private function handle_forum_activity( array $data ) { 397 $user = self::get_user( $data['user'] ); 378 398 $type = ''; 379 399 380 400 // Check for valid user. 381 401 if ( ! $user ) { 382 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $ _POST['user'] );402 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $data['user'] ); 383 403 } 384 404 … … 390 410 'remove-reply' => 'forum_reply_remove', 391 411 ); 392 if ( ! empty( $ _POST['activity'] ) && ! empty( $activities[ $_POST['activity'] ] ) ) {393 $type = $activities[ $ _POST['activity'] ];412 if ( ! empty( $data['activity'] ) && ! empty( $activities[ $data['activity'] ] ) ) { 413 $type = $activities[ $data['activity'] ]; 394 414 } else { 395 415 return '-1 Unrecognized forum activity.'; … … 408 428 $required_args[] = 'post_id'; 409 429 } 410 $this->require_args( $required_args );430 $this->require_args( $required_args, $data ); 411 431 412 432 // Determine 'item_id' value based on context. 413 433 $item_id = in_array( $type, array( 'forum_topic_create', 'forum_topic_remove' ) ) ? 414 intval( $ _POST['topic_id'] ) :415 intval( $ _POST['post_id'] );434 intval( $data['topic_id'] ) : 435 intval( $data['post_id'] ); 416 436 417 437 // Find an existing activity uniquely identified by the reported criteria. … … 425 445 'type' => str_replace( 'remove', 'create', $type ), 426 446 'item_id' => $item_id, 427 'secondary_item_id' => intval( $ _POST['forum_id'] ),447 'secondary_item_id' => intval( $data['forum_id'] ), 428 448 ); 429 449 $activity_id = bp_activity_get_activity_id( $args ); … … 443 463 $action = sprintf( 444 464 'Created a topic, <i><a href="%s">%s</a></i>, on the site %s', 445 esc_url( $ _POST['url'] ),446 esc_html( $ _POST['title'] ),447 esc_html( $ _POST['site'] )465 esc_url( $data['url'] ), 466 esc_html( $data['title'] ), 467 esc_html( $data['site'] ) 448 468 ); 449 469 … … 452 472 $action = sprintf( 453 473 'Posted a <a href="%s">reply</a> to <i>%s</i>, on the site %s', 454 esc_url( $ _POST['url'] ),455 esc_html( $ _POST['title'] ),456 esc_html( $ _POST['site'] )474 esc_url( $data['url'] ), 475 esc_html( $data['title'] ), 476 esc_html( $data['site'] ) 457 477 ); 458 478 } … … 461 481 'user_id' => $user->ID, 462 482 'action' => $action, 463 'content' => esc_html( $ _POST['message'] ),464 'primary_link' => esc_url( $ _POST['url'] ),483 'content' => esc_html( $data['message'] ), 484 'primary_link' => esc_url( $data['url'] ), 465 485 'component' => 'forums', 466 486 'type' => $type, 467 487 'item_id' => $item_id, 468 'secondary_item_id' => intval( $ _POST['forum_id'] ),488 'secondary_item_id' => intval( $data['forum_id'] ), 469 489 'hide_sitewide' => false, 470 490 ); … … 497 517 * - Creating new plugin 498 518 */ 499 private function handle_plugin_activity( ) {500 $user = self::get_user( $ _POST['user'] );519 private function handle_plugin_activity( array $data ) { 520 $user = self::get_user( $data['user'] ); 501 521 502 522 if ( ! $user ) { 503 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $ _POST['user'] );523 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $data['user'] ); 504 524 } 505 525 … … 508 528 'action' => sprintf( 509 529 'Released a new plugin, <a href="%s">%s</a>', 510 esc_url( $ _POST['url'] ),511 $ _POST['title']530 esc_url( $data['url'] ), 531 $data['title'] 512 532 ), 513 533 'content' => '', 514 'primary_link' => $ _POST['url'],534 'primary_link' => $data['url'], 515 535 'component' => 'plugins', 516 536 'type' => 'plugin_create', 517 'item_id' => intval( $ _POST['plugin_id'] ),537 'item_id' => intval( $data['plugin_id'] ), 518 538 'secondary_item_id' => false, 519 539 'hide_sitewide' => false, … … 529 549 * - Creating new theme 530 550 */ 531 private function handle_theme_activity( ) {532 $user = self::get_user( $ _POST['user'] );551 private function handle_theme_activity( array $data ) { 552 $user = self::get_user( $data['user'] ); 533 553 534 554 if ( ! $user ) { 535 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $ _POST['user'] );555 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $data['user'] ); 536 556 } 537 557 … … 540 560 'action' => sprintf( 541 561 'Released a new theme, <a href="%s">%s</a>', 542 esc_url( $ _POST['url'] ),543 $ _POST['title']562 esc_url( $data['url'] ), 563 $data['title'] 544 564 ), 545 565 'content' => '', 546 'primary_link' => $ _POST['url'],566 'primary_link' => $data['url'], 547 567 'component' => 'themes', 548 568 'type' => 'theme_create', 549 'item_id' => intval( $ _POST['theme_id'] ),569 'item_id' => intval( $data['theme_id'] ), 550 570 'secondary_item_id' => false, 551 571 'hide_sitewide' => false, … … 564 584 * - Receiving props on a commit 565 585 */ 566 private function handle_trac_activity( ) {567 $user = self::get_user( $ _POST['user'] );586 private function handle_trac_activity( array $data ) { 587 $user = self::get_user( $data['user'] ); 568 588 569 589 if ( ! $user ) { 570 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $ _POST['user'] );571 } 572 573 if ( ! empty( $ _POST['description'] ) ) {590 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $data['user'] ); 591 } 592 593 if ( ! empty( $data['description'] ) ) { 574 594 575 595 $args = array( 576 596 'user_id' => $user->ID, 577 'action' => sprintf( 'Created a new ticket in %s Trac', $ _POST['trac'] ),578 'content' => $ _POST['title'],597 'action' => sprintf( 'Created a new ticket in %s Trac', $data['trac'] ), 598 'content' => $data['title'], 579 599 'component' => 'tracs', 580 600 'type' => 'trac_ticket_create', 581 'item_id' => intval( $ _POST['id'] ),601 'item_id' => intval( $data['id'] ), 582 602 'secondary_item_id' => false, 583 603 'hide_sitewide' => false, … … 586 606 return bp_activity_add( $args ); 587 607 588 } elseif ( ! empty( $ _POST['comment'] ) ) {608 } elseif ( ! empty( $data['comment'] ) ) { 589 609 590 610 $args = array( 591 611 'user_id' => $user->ID, 592 'action' => sprintf( 'Posted a reply to <i>%s</i> in %s Trac', $ _POST['title'], $_POST['trac'] ),593 'content' => $ _POST['comment'],612 'action' => sprintf( 'Posted a reply to <i>%s</i> in %s Trac', $data['title'], $data['trac'] ), 613 'content' => $data['comment'], 594 614 'component' => 'tracs', 595 615 'type' => 'trac_comment_create', 596 'item_id' => intval( $ _POST['id'] ),616 'item_id' => intval( $data['id'] ), 597 617 'secondary_item_id' => false, 598 618 'hide_sitewide' => false, … … 606 626 $args = array( 607 627 'user_id' => $user->ID, 608 'action' => sprintf( 'Committed [%s] to %s Trac', $ _POST['changeset'], $_POST['trac'] ),609 'content' => $ _POST['message'],628 'action' => sprintf( 'Committed [%s] to %s Trac', $data['changeset'], $data['trac'] ), 629 'content' => $data['message'], 610 630 'component' => 'tracs', 611 631 'type' => 'trac_commit_create', 612 'item_id' => intval( $ _POST['changeset'] ),632 'item_id' => intval( $data['changeset'] ), 613 633 'secondary_item_id' => false, 614 634 'hide_sitewide' => false, … … 619 639 // Record props for each listed user 620 640 $regex = '/props\s+((?:(?:\w+\b(?<!\bfixes))(?:[,][ ]*)?)+)/i'; 621 preg_match_all( $regex, $ _POST['message'], $matches );641 preg_match_all( $regex, $data['message'], $matches ); 622 642 $usernames = explode( ',', $matches[1][0] ); 623 643 $usernames = array_map( 'trim', $usernames ); … … 630 650 $args = array( 631 651 'user_id' => $user->ID, 632 'action' => sprintf( 'Received props in %s', $ _POST['trac'] ),633 'content' => $ _POST['message'],652 'action' => sprintf( 'Received props in %s', $data['trac'] ), 653 'content' => $data['message'], 634 654 'component' => 'tracs', 635 655 'type' => 'trac_props_mention', 636 'item_id' => intval( $ _POST['changeset'] ),656 'item_id' => intval( $data['changeset'] ), 637 657 'secondary_item_id' => false, 638 658 'hide_sitewide' => false, … … 648 668 * Handles incoming activities for WordCamp. 649 669 */ 650 private function handle_wordcamp_activity( ) {651 $user = self::get_user( $ _POST['user'] );670 private function handle_wordcamp_activity( array $data ) { 671 $user = self::get_user( $data['user'] ); 652 672 $type = ''; 653 673 654 674 if ( ! $user ) { 655 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $ _POST['user'] );656 } 657 658 if ( isset( $ _POST['speaker_id'] ) && ! empty( $_POST['speaker_id'] ) ) {675 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $data['user'] ); 676 } 677 678 if ( isset( $data['speaker_id'] ) && ! empty( $data['speaker_id'] ) ) { 659 679 $type = 'wordcamp_speaker_add'; 660 $item_id = $ _POST['speaker_id'];680 $item_id = $data['speaker_id']; 661 681 662 682 $action = sprintf( 663 683 'Confirmed as a speaker for <a href="%s">%s</a>', 664 esc_url( $ _POST['url'] ),665 $ _POST['wordcamp_name']684 esc_url( $data['url'] ), 685 $data['wordcamp_name'] 666 686 ); 667 687 668 } elseif ( isset( $ _POST['organizer_id'] ) && ! empty( $_POST['organizer_id'] ) ) {688 } elseif ( isset( $data['organizer_id'] ) && ! empty( $data['organizer_id'] ) ) { 669 689 $type = 'wordcamp_organizer_add'; 670 $item_id = $ _POST['organizer_id'];690 $item_id = $data['organizer_id']; 671 691 672 692 $action = sprintf( 673 693 'Joined the organizing team for <a href="%s">%s</a>', 674 esc_url( $ _POST['url'] ),675 $ _POST['wordcamp_name']694 esc_url( $data['url'] ), 695 $data['wordcamp_name'] 676 696 ); 677 697 678 } elseif ( isset( $ _POST['type'] ) && 'mentor_assign' === $_POST['type'] ) {698 } elseif ( isset( $data['type'] ) && 'mentor_assign' === $data['type'] ) { 679 699 $type = 'wordcamp_mentor_assign'; 680 $item_id = absint( $ _POST['wordcamp_id'] );681 $wordcamp_name = sanitize_text_field( $ _POST['wordcamp_name'] );682 683 if ( empty( $ _POST['url'] ) ) {700 $item_id = absint( $data['wordcamp_id'] ); 701 $wordcamp_name = sanitize_text_field( $data['wordcamp_name'] ); 702 703 if ( empty( $data['url'] ) ) { 684 704 $action = 'Started mentoring ' . $wordcamp_name; 685 705 } else { 686 706 $action = sprintf( 687 707 'Started mentoring <a href="%s">%s</a>', 688 sanitize_url( $ _POST['url'] ),708 sanitize_url( $data['url'] ), 689 709 $wordcamp_name 690 710 ); 691 711 } 692 712 693 } elseif ( isset( $ _POST['attendee_id'] ) && ! empty( $_POST['attendee_id'] ) ) {694 $item_id = $ _POST['attendee_id'];695 696 if ( 'attendee_registered' == $ _POST['activity_type'] ) {713 } elseif ( isset( $data['attendee_id'] ) && ! empty( $data['attendee_id'] ) ) { 714 $item_id = $data['attendee_id']; 715 716 if ( 'attendee_registered' == $data['activity_type'] ) { 697 717 $type = 'wordcamp_attendee_add'; 698 718 699 719 $action = sprintf( 700 720 'Registered to attend <a href="%s">%s</a>', 701 esc_url( $ _POST['url'] ),702 $ _POST['wordcamp_name']721 esc_url( $data['url'] ), 722 $data['wordcamp_name'] 703 723 ); 704 724 705 } elseif ( 'attendee_checked_in' == $ _POST['activity_type'] ) {725 } elseif ( 'attendee_checked_in' == $data['activity_type'] ) { 706 726 $type = 'wordcamp_attendee_checked_in'; 707 $order = absint( $ _POST['checked_in_count'] );727 $order = absint( $data['checked_in_count'] ); 708 728 709 729 $action = sprintf( 710 730 'Is the %s person to arrive at <a href="%s">%s</a>', 711 731 $this->append_ordinal_suffix( $order ), 712 esc_url( $ _POST['url'] ),713 $ _POST['wordcamp_name']732 esc_url( $data['url'] ), 733 $data['wordcamp_name'] 714 734 ); 715 735 } … … 724 744 'action' => $action, 725 745 'content' => '', 726 'primary_link' => $ _POST['url'] ?? '',746 'primary_link' => $data['url'] ?? '', 727 747 'component' => 'wordcamp', 728 748 'type' => $type, 729 749 'item_id' => intval( $item_id ), 730 'secondary_item_id' => intval( $ _POST['wordcamp_id'] ),750 'secondary_item_id' => intval( $data['wordcamp_id'] ), 731 751 'hide_sitewide' => false, 732 752 ); … … 767 787 * Handles incoming activities for a WordPress install. 768 788 */ 769 private function handle_wordpress_activity( ) {770 $user = self::get_user( $ _POST['user'] );771 $content = $ _POST['content'];772 $primary_link = sanitize_url( $ _POST['url'] );789 private function handle_wordpress_activity( array $data ) { 790 $user = self::get_user( $data['user'] ); 791 $content = $data['content']; 792 $primary_link = sanitize_url( $data['url'] ); 773 793 774 794 if ( ! $user ) { 775 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $ _POST['user'] );776 } 777 778 if ( isset( $ _POST['comment_id'] ) && ! empty( $_POST['comment_id'] ) ) {795 return '-1 Activity reported for unrecognized user : ' . sanitize_text_field( $data['user'] ); 796 } 797 798 if ( isset( $data['comment_id'] ) && ! empty( $data['comment_id'] ) ) { 779 799 $type = 'blog_comment_create'; 780 $item_id = $ _POST['comment_id'];800 $item_id = $data['comment_id']; 781 801 $action = sprintf( 782 802 'Wrote a <a href="%s">comment</a> on the post <i>%s</i>, on the site %s', 783 esc_url( $ _POST['url'] ),784 $ _POST['title'],785 $ _POST['blog']803 esc_url( $data['url'] ), 804 $data['title'], 805 $data['blog'] 786 806 ); 787 } elseif ( isset( $ _POST['type'] ) && 'new' === $_POST['type'] ) {807 } elseif ( isset( $data['type'] ) && 'new' === $data['type'] ) { 788 808 $type = 'blog_post_create'; 789 $item_id = $ _POST['post_id'];790 791 switch ( $ _POST['post_type'] ) {809 $item_id = $data['post_id']; 810 811 switch ( $data['post_type'] ) { 792 812 case 'wporg_workshop': 793 813 $post_type = 'workshop'; … … 803 823 804 824 case 'handbook': 805 case str_contains( $ _POST['post_type'], '-handbook' ):825 case str_contains( $data['post_type'], '-handbook' ): 806 826 $post_type = 'handbook page'; 807 827 break; … … 814 834 'Wrote a new %s, <i><a href="%s">%s</a></i>, on the site %s', 815 835 $post_type, 816 esc_url( $ _POST['url'] ),817 $ _POST['title'],818 $ _POST['blog']836 esc_url( $data['url'] ), 837 $data['title'], 838 $data['blog'] 819 839 ); 820 } elseif ( isset( $ _POST['type'] ) && 'update' === $_POST['type'] ) {840 } elseif ( isset( $data['type'] ) && 'update' === $data['type'] ) { 821 841 // Handbooks are currently the only post type that send notifications of updates. 822 842 $type = 'blog_handbook_update'; 823 $item_id = $ _POST['post_id'];843 $item_id = $data['post_id']; 824 844 $action = ''; // Will be set by `digest_bump()` 825 845 $content = false; 826 $primary_link = sanitize_url( $ _POST['blog_url'] ); // To group digest entries by site.846 $primary_link = sanitize_url( $data['blog_url'] ); // To group digest entries by site. 827 847 828 848 $singular = sprintf( 829 849 'Updated a handbook page on <a href="%s">%s</a>.', 830 sanitize_url( $ _POST['blog_url'] ),831 sanitize_text_field( $ _POST['blog'] )850 sanitize_url( $data['blog_url'] ), 851 sanitize_text_field( $data['blog'] ) 832 852 ); 833 853 … … 835 855 'Made %s updates to handbook pages on <a href="%s">%s</a>.', 836 856 '%d', 837 sanitize_url( $ _POST['blog_url'] ),838 sanitize_text_field( $ _POST['blog'] )857 sanitize_url( $data['blog_url'] ), 858 sanitize_text_field( $data['blog'] ) 839 859 ); 840 860 } … … 869 889 * @return bool|string `true` if all activities are added, string error message if any of them fail. 870 890 */ 871 protected function handle_slack_activity( ) {872 $activity_type = sanitize_text_field( $ _POST['activity'] );891 protected function handle_slack_activity( array $data ) { 892 $activity_type = sanitize_text_field( $data['activity'] ); 873 893 $user_case_args = array(); 874 894 $errors = ''; … … 882 902 switch ( $activity_type ) { 883 903 case 'props_given': 884 $user_case_args = $this->handle_props_given( $ _POST);904 $user_case_args = $this->handle_props_given( $data ); 885 905 break; 886 906 … … 1091 1111 1092 1112 if ( class_exists( 'WPOrg_Profiles_Activity_Handler' ) ) { 1093 new WPOrg_Profiles_Activity_Handler();1113 WPOrg_Profiles_Activity_Handler::get_instance(); 1094 1114 } 1095 1115
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)