Changeset 5306
- Timestamp:
- 04/10/2017 10:36:57 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-moderators.php
r5300 r5306 39 39 40 40 // Handle topic and reply actions. 41 add_filter( 'bbp_get_request', array( $this, 'handle_topic_actions_request' ) ); 42 add_filter( 'bbp_get_request', array( $this, 'handle_reply_actions_request' ) ); 41 43 add_filter( 'bbp_toggle_topic', array( $this, 'handle_topic_actions' ), 10, 3 ); 42 44 add_filter( 'bbp_toggle_reply', array( $this, 'handle_reply_actions' ), 10, 3 ); … … 465 467 466 468 /** 469 * Handle Spam, Unspam, Unapprove, Approve topic actions request. 470 * 471 * @param string $action The requested action. 472 */ 473 public function handle_topic_actions_request( $action = '' ) { 474 // Bail if required GET actions aren't passed 475 if ( empty( $_GET['topic_id'] ) ) { 476 return; 477 } 478 479 // What's the topic id? 480 $topic_id = bbp_get_topic_id( (int) $_GET['topic_id'] ); 481 482 // Get possible topic-handler actions 483 $possible_actions = $this->get_topic_actions( array() ); 484 485 // Bail if action isn't meant for this function 486 if ( ! in_array( $action, $possible_actions ) ) { 487 return; 488 } 489 490 // Make sure topic exists 491 $topic = bbp_get_topic( $topic_id ); 492 if ( empty( $topic ) ) { 493 bbp_add_error( 'bbp_toggle_topic_missing', __( '<strong>ERROR:</strong> This topic could not be found or no longer exists.', 'wporg-forums' ) ); 494 return; 495 } 496 497 // What is the user doing here? 498 if ( ! current_user_can( 'edit_topic', $topic_id ) ) { 499 bbp_add_error( 'bbp_toggle_topic_permission', __( '<strong>ERROR:</strong> You do not have permission to do that.', 'wporg-forums' ) ); 500 return; 501 } 502 503 // Preliminary array 504 $args = array( 505 'id' => $topic_id, 506 'action' => $action, 507 'sub_action' => '', 508 'data' => array( 'ID' => $topic_id ) 509 ); 510 511 // Default return values 512 $retval = array( 513 'status' => 0, 514 'message' => '', 515 'redirect_to' => bbp_get_topic_permalink( $args['id'], bbp_get_redirect_to() ), 516 'view_all' => false 517 ); 518 519 // Do the topic action 520 $retval = $this->handle_topic_actions( $retval, $args, $args ); 521 522 // Redirect back to topic 523 if ( ( false !== $retval['status'] ) && ! is_wp_error( $retval['status'] ) ) { 524 bbp_redirect( $retval['redirect_to'] ); 525 526 // Handle errors 527 } else { 528 bbp_add_error( 'bbp_toggle_topic', $retval['message'] ); 529 } 530 } 531 532 /** 533 * Handle Spam, Unspam, Unapprove, Approve reply actions request. 534 * 535 * @param string $action The requested action. 536 */ 537 public function handle_reply_actions_request( $action = '' ) { 538 // Bail if required GET actions aren't passed 539 if ( empty( $_GET['reply_id'] ) ) { 540 return; 541 } 542 543 // What's the reply id? 544 $reply_id = bbp_get_reply_id( (int) $_GET['reply_id'] ); 545 546 // Get possible reply-handler actions 547 $possible_actions = $this->get_reply_actions( array() ); 548 549 // Bail if action isn't meant for this function 550 if ( ! in_array( $action, $possible_actions ) ) { 551 return; 552 } 553 554 // Make sure reply exists 555 $reply = bbp_get_reply( $reply_id ); 556 if ( empty( $reply ) ) { 557 bbp_add_error( 'bbp_toggle_reply_missing', __( '<strong>ERROR:</strong> This reply could not be found or no longer exists.', 'wporg-forums' ) ); 558 return; 559 } 560 561 // What is the user doing here? 562 if ( ! current_user_can( 'edit_reply', $reply_id ) ) { 563 bbp_add_error( 'bbp_toggle_reply_permission', __( '<strong>ERROR:</strong> You do not have permission to do that.', 'wporg-forums' ) ); 564 return; 565 } 566 567 // Preliminary array 568 $args = array( 569 'id' => $reply_id, 570 'action' => $action, 571 'sub_action' => '', 572 'data' => array( 'ID' => $reply_id ) 573 ); 574 575 // Default return values 576 $retval = array( 577 'status' => 0, 578 'message' => '', 579 'redirect_to' => bbp_get_reply_url( $args['id'], bbp_get_redirect_to() ), 580 'view_all' => false 581 ); 582 583 // Do the reply action 584 $retval = $this->handle_reply_actions( $retval, $args, $args ); 585 586 // Redirect back to reply 587 if ( ( false !== $retval['status'] ) && ! is_wp_error( $retval['status'] ) ) { 588 bbp_redirect( $retval['redirect_to'] ); 589 590 // Handle errors 591 } else { 592 bbp_add_error( 'bbp_toggle_reply', $retval['message'] ); 593 } 594 } 595 596 /** 467 597 * Handle Spam, Unspam, Unapprove, Approve topic actions. 468 598 *
Note: See TracChangeset
for help on using the changeset viewer.