Changeset 13888
- Timestamp:
- 06/01/2024 10:25:18 PM (4 months ago)
- Location:
- trunk/src/bp-core/classes
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-invitation-manager.php
r13500 r13888 26 26 * 27 27 * @since 5.0.0 28 * @access public28 * 29 29 * @var string 30 30 */ … … 35 35 * 36 36 * @since 5.0.0 37 * 38 * @param array|string $args { 39 * } 40 */ 41 public function __construct( $args = array() ) { 37 */ 38 public function __construct() { 42 39 $this->class_name = get_class( $this ); 43 40 } … … 47 44 * 48 45 * @since 5.0.0 49 * @access public46 * 50 47 * @return string 51 48 */ … … 64 61 * @param array $args { 65 62 * Array of arguments describing the invitation. All are optional. 66 * 67 * 68 * 69 * 70 * 71 * 72 * 73 * 74 * 75 * 76 * 77 * 63 * @type int $user_id ID of the invited user. 64 * @type int $inviter_id ID of the user who created the invitation. 65 * @type string $invitee_email Email address of the invited user. 66 * @type int $item_id ID associated with the invitation and class. 67 * @type int $secondary_item_id Secondary ID associated with the 68 * invitation and class. 69 * @type string $type Type of record this is: 'invite' or 'request'. 70 * @type string $content Extra information provided by the requester 71 * or inviter. 72 * @type string $date_modified Date the invitation was last modified. 73 * @type int $send_invite Should the invitation also be sent, or is it a 74 * draft invite? 78 75 * } 79 76 * @return int|bool ID of the newly created invitation on success, false 80 * on failure.77 * on failure. 81 78 */ 82 79 public function add_invitation( $args = array() ) { 83 84 80 $r = bp_parse_args( 85 81 $args, … … 121 117 122 118 // Avoid creating duplicate invitations. 123 $invite_id = $this->invitation_exists( array( 124 'user_id' => $r['user_id'], 125 'invitee_email' => $r['invitee_email'], 126 'inviter_id' => $r['inviter_id'], 127 'item_id' => $r['item_id'], 128 'secondary_item_id' => $r['secondary_item_id'], 129 ) ); 119 $invite_id = $this->invitation_exists( 120 array( 121 'user_id' => $r['user_id'], 122 'invitee_email' => $r['invitee_email'], 123 'inviter_id' => $r['inviter_id'], 124 'item_id' => $r['item_id'], 125 'secondary_item_id' => $r['secondary_item_id'], 126 ) 127 ); 130 128 131 129 if ( ! $invite_id ) { 132 130 // Set up the new invitation as a draft. 133 $invitation = new BP_Invitation ;131 $invitation = new BP_Invitation(); 134 132 $invitation->user_id = $r['user_id']; 135 133 $invitation->inviter_id = $r['inviter_id']; … … 162 160 * 163 161 * @since 5.0.0 164 * @access public165 162 * 166 163 * @param int $invitation_id ID of invitation to send. 167 164 * @param array $args See BP_Invitation::mark_sent(). 168 165 * 169 * @return bool The result of `run_send_action()`.166 * @return bool 170 167 */ 171 168 public function send_invitation_by_id( $invitation_id = 0, $args = array() ) { … … 195 192 'secondary_item_id' => $invitation->secondary_item_id, 196 193 ); 197 $request = $this->request_exists( $request_args );194 $request = $this->request_exists( $request_args ); 198 195 199 196 if ( ! empty( $request ) ) { … … 220 217 * @param array $args { 221 218 * Array of arguments describing the invitation. All are optional. 222 * 223 * 224 * 225 * 226 * 227 * 228 * 229 * 230 * 231 * 232 * 233 * 219 * @type int $user_id ID of the invited user. 220 * @type int $inviter_id ID of the user who created the invitation. 221 * @type string $class Name of the invitations class. 222 * @type int $item_id ID associated with the invitation and class. 223 * @type int $secondary_item_id secondary ID associated with the 224 * invitation and class. 225 * @type string $type Type of record this is: 'invite' or 'request'. 226 * @type string $content Extra information provided by the requester 227 * or inviter. 228 * @type string $date_modified Date the invitation was last modified. 229 * @type int $invite_sent Has the invitation been sent, or is it a 230 * draft invite? 234 231 * } 235 232 * @return int|bool ID of the newly created invitation on success, false 236 * on failure.233 * on failure. 237 234 */ 238 235 public function add_request( $args = array() ) { 239 240 236 $r = bp_parse_args( 241 237 $args, … … 289 285 */ 290 286 $invite_args = array_merge( $base_args, array( 'invite_sent' => 'sent' ) ); 291 $invite = $this->invitation_exists( $invite_args );287 $invite = $this->invitation_exists( $invite_args ); 292 288 293 289 if ( $invite ) { … … 296 292 } else { 297 293 // Set up the new request. 298 $request = new BP_Invitation ;294 $request = new BP_Invitation(); 299 295 $request->user_id = $r['user_id']; 300 296 $request->inviter_id = $r['inviter_id']; … … 344 340 'item_id' => $request->item_id, 345 341 'secondary_item_id' => $request->secondary_item_id, 346 'invite_sent' => 'sent' 347 ); 348 $invites = $this->invitation_exists( $invite_args );342 'invite_sent' => 'sent', 343 ); 344 $invites = $this->invitation_exists( $invite_args ); 349 345 350 346 if ( ! empty( $invites ) ) { … … 451 447 452 448 $args['fields'] = 'ids'; 453 $invites = $this->get_invitations( $args );449 $invites = $this->get_invitations( $args ); 454 450 if ( $invites ) { 455 451 $is_invited = current( $invites ); … … 471 467 472 468 $args['fields'] = 'ids'; 473 $requests = $this->get_requests( $args );469 $requests = $this->get_requests( $args ); 474 470 if ( $requests ) { 475 471 $has_request = current( $requests ); … … 608 604 * @param array $update_args Associative array of fields to update, 609 605 * and the values to update them to. Of the format 610 * array( 'user_id' => 4 ) 606 * array( 'user_id' => 4 ). 611 607 * @param array $where_args Associative array of columns/values, to 612 608 * determine which invitations should be updated. Formatted as 613 * array( 'item_id' => 7 ) 609 * array( 'item_id' => 7 ). 614 610 * @return int|bool Number of rows updated on success, false on failure. 615 611 */ … … 647 643 * Special cases 648 644 * @type string|array $invitee_email Email address of invited users 649 * 645 * being queried. Can be an array of addresses. 650 646 * @type string|array $class Name of the class to 651 647 * filter by. Can be an array of class names. … … 667 663 * @since 5.0.0 668 664 * 669 * @param int $id The ID of the invitation to mark as sent. 670 * @return bool True on success, false on failure. 671 */ 672 abstract public function run_acceptance_action( $type, $r ); 665 * @param string $type The type of record being accepted: 'invite' or 'request'. 666 * @param array $r Associative array of arguments. 667 * @return bool 668 */ 669 abstract public function run_acceptance_action( $type, $r ); 673 670 674 671 /** … … 679 676 * @see BP_Invitation::mark_accepted() 680 677 * for a description of arguments. 681 * @return bool True on success, false on failure. 678 * 679 * @return bool 682 680 */ 683 681 public function mark_accepted_by_id( $id, $args ) { … … 708 706 * 709 707 * @see BP_Invitation::delete for a description of arguments. 708 * 710 709 * @return int|bool Number of rows deleted on success, false on failure. 711 710 */ … … 743 742 */ 744 743 public function delete_all() { 745 return BP_Invitation::delete( array( 746 'class' => $this->class_name, 747 ) ); 744 return BP_Invitation::delete( 745 array( 746 'class' => $this->class_name, 747 ) 748 ); 748 749 } 749 750 … … 772 773 * @since 5.0.0 773 774 * 774 * @param array $args The parameters describing the invitation. 775 * @return bool True if allowed, false to end process. 776 */ 777 public function allow_invitation( $args ) { 775 * @return bool 776 */ 777 public function allow_invitation() { 778 778 return true; 779 779 } … … 785 785 * @since 5.0.0 786 786 * 787 * @param array $args The parameters describing the request. 788 * @return bool True if allowed, false to end process. 789 */ 790 public function allow_request( $args ) { 787 * @return bool 788 */ 789 public function allow_request() { 791 790 return true; 792 791 } 793 794 792 } -
trunk/src/bp-core/classes/class-bp-invitation.php
r13395 r13888 25 25 * 26 26 * @since 5.0.0 27 * @access public27 * 28 28 * @var int 29 29 */ … … 34 34 * 35 35 * @since 5.0.0 36 * @access public36 * 37 37 * @var int 38 38 */ … … 43 43 * 44 44 * @since 5.0.0 45 * @access public45 * 46 46 * @var int 47 47 */ … … 53 53 * 54 54 * @since 5.0.0 55 * @access public55 * 56 56 * @var string 57 57 */ … … 62 62 * 63 63 * @since 5.0.0 64 * @access public64 * 65 65 * @var string 66 66 */ … … 72 72 * 73 73 * @since 5.0.0 74 * @access public74 * 75 75 * @var int 76 76 */ … … 82 82 * 83 83 * @since 5.0.0 84 * @access public85 * @var int 84 * 85 * @var int|null 86 86 */ 87 87 public $secondary_item_id = null; … … 91 91 * 92 92 * @since 5.0.0 93 * @access public93 * 94 94 * @var string 95 95 */ … … 100 100 * 101 101 * @since 5.0.0 102 * @access public102 * 103 103 * @var string 104 104 */ … … 109 109 * 110 110 * @since 5.0.0 111 * @access public111 * 112 112 * @var string 113 113 */ … … 118 118 * 119 119 * @since 5.0.0 120 * @access public120 * 121 121 * @var bool 122 122 */ … … 127 127 * 128 128 * @since 5.0.0 129 * @access public129 * 130 130 * @var bool 131 131 */ … … 136 136 * 137 137 * @since 9.0.0 138 * @access public138 * 139 139 * @var array 140 140 */ … … 151 151 'date_modified', 152 152 'invite_sent', 153 'accepted' 153 'accepted', 154 154 ); 155 155 … … 161 161 * @since 5.0.0 162 162 * 163 * @param int $id Optional. Provide an ID to access an existing 164 * invitation item. 163 * @param int $id Optional. Provide an ID to access an existing invitation item. 165 164 */ 166 165 public function __construct( $id = 0 ) { … … 182 181 public function save() { 183 182 184 // Return value 183 // Return value. 185 184 $retval = false; 186 185 187 // Default data and format 188 $data = array(186 // Default data and format. 187 $data = array( 189 188 'user_id' => $this->user_id, 190 189 'inviter_id' => $this->inviter_id, … … 213 212 if ( ! empty( $this->id ) ) { 214 213 $result = self::_update( $data, array( 'ID' => $this->id ), $data_format, array( '%d' ) ); 215 // Insert.214 // Insert. 216 215 } else { 217 216 $result = self::_insert( $data, $data_format ); … … 258 257 if ( false === $invitation ) { 259 258 $invitation = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$invites_table_name} WHERE id = %d", $this->id ) ); 260 wp_cache_set( $this->id, $invitation, 'bp_invitations' );259 wp_cache_set( $this->id, $invitation, 'bp_invitations' ); 261 260 } 262 261 … … 278 277 $this->invite_sent = (int) $invitation->invite_sent; 279 278 $this->accepted = (int) $invitation->accepted; 280 281 279 } 282 280 … … 287 285 * 288 286 * @since 5.0.0 287 * 288 * @global wpdb $wpdb WordPress database object. 289 289 * 290 290 * @param array $data { 291 291 * Array of invitation data, passed to {@link wpdb::insert()}. 292 * 293 * 294 * 295 * 296 * 297 * 292 * @type int $user_id ID of the invited user. 293 * @type int $inviter_id ID of the user who created the invitation. 294 * @type string $invitee_email Email address of the invited user. 295 * @type string $class Name of the related class. 296 * @type int $item_id ID associated with the invitation and component. 297 * @type int $secondary_item_id Secondary ID associated with the invitation and 298 298 * component. 299 * 300 * 301 * 302 * 299 * @type string $content Extra information provided by the requester 300 * or inviter. 301 * @type string $date_modified Date the invitation was last modified. 302 * @type int $invite_sent Has the invitation been sent, or is it a draft 303 303 * invite? 304 304 * } … … 315 315 * 316 316 * @since 5.0.0 317 * 318 * @global wpdb $wpdb WordPress database object. 317 319 * 318 320 * @see wpdb::update() for further description of paramater formats. … … 338 340 * @since 5.0.0 339 341 * 342 * @global wpdb $wpdb WordPress database object. 343 * 340 344 * @see wpdb::update() for further description of paramater formats. 341 345 * … … 359 363 * @since 5.0.0 360 364 * 365 * @global wpdb $wpdb WordPress database object. 366 * 361 367 * @param array $args See {@link BP_Invitation::get()} for more details. 362 368 * @return string WHERE clause. … … 370 376 // id. 371 377 if ( false !== $args['id'] ) { 372 $id_in = implode( ',', wp_parse_id_list( $args['id'] ) );378 $id_in = implode( ',', wp_parse_id_list( $args['id'] ) ); 373 379 $where_conditions['id'] = "id IN ({$id_in})"; 374 380 } … … 376 382 // user_id. 377 383 if ( ! empty( $args['user_id'] ) ) { 378 $user_id_in = implode( ',', wp_parse_id_list( $args['user_id'] ) );384 $user_id_in = implode( ',', wp_parse_id_list( $args['user_id'] ) ); 379 385 $where_conditions['user_id'] = "user_id IN ({$user_id_in})"; 380 386 } … … 382 388 // inviter_id. 0 can be meaningful, in the case of requests. 383 389 if ( ! empty( $args['inviter_id'] ) || 0 === $args['inviter_id'] ) { 384 $inviter_id_in = implode( ',', wp_parse_id_list( $args['inviter_id'] ) );390 $inviter_id_in = implode( ',', wp_parse_id_list( $args['inviter_id'] ) ); 385 391 $where_conditions['inviter_id'] = "inviter_id IN ({$inviter_id_in})"; 386 392 } … … 399 405 } 400 406 401 $invitee_email_in = implode( ',', $email_clean );407 $invitee_email_in = implode( ',', $email_clean ); 402 408 $where_conditions['invitee_email'] = "invitee_email IN ({$invitee_email_in})"; 403 409 } … … 416 422 } 417 423 418 $cn_in = implode( ',', $cn_clean );424 $cn_in = implode( ',', $cn_clean ); 419 425 $where_conditions['class'] = "class IN ({$cn_in})"; 420 426 } … … 422 428 // item_id. 423 429 if ( ! empty( $args['item_id'] ) ) { 424 $item_id_in = implode( ',', wp_parse_id_list( $args['item_id'] ) );430 $item_id_in = implode( ',', wp_parse_id_list( $args['item_id'] ) ); 425 431 $where_conditions['item_id'] = "item_id IN ({$item_id_in})"; 426 432 } … … 428 434 // secondary_item_id. 429 435 if ( ! empty( $args['secondary_item_id'] ) ) { 430 $secondary_item_id_in = implode( ',', wp_parse_id_list( $args['secondary_item_id'] ) );436 $secondary_item_id_in = implode( ',', wp_parse_id_list( $args['secondary_item_id'] ) ); 431 437 $where_conditions['secondary_item_id'] = "secondary_item_id IN ({$secondary_item_id_in})"; 432 438 } … … 434 440 // Type. 435 441 if ( ! empty( $args['type'] ) && 'all' !== $args['type'] ) { 436 if ( 'invite' == $args['type'] || 'request'== $args['type'] ) {437 $type_clean = $wpdb->prepare( '%s', $args['type'] );442 if ( 'invite' === $args['type'] || 'request' === $args['type'] ) { 443 $type_clean = $wpdb->prepare( '%s', $args['type'] ); 438 444 $where_conditions['type'] = "type = {$type_clean}"; 439 445 } … … 441 447 442 448 /** 443 * invite_sent444 449 * Only create a where statement if something less than "all" has been 445 450 * specifically requested. 446 451 */ 447 452 if ( ! empty( $args['invite_sent'] ) && 'all' !== $args['invite_sent'] ) { 448 if ( $args['invite_sent'] == 'draft' ) {449 $where_conditions['invite_sent'] = "invite_sent = 0";450 } else if ( $args['invite_sent']== 'sent' ) {451 $where_conditions['invite_sent'] = "invite_sent = 1";453 if ( $args['invite_sent'] === 'draft' ) { 454 $where_conditions['invite_sent'] = 'invite_sent = 0'; 455 } elseif ( $args['invite_sent'] === 'sent' ) { 456 $where_conditions['invite_sent'] = 'invite_sent = 1'; 452 457 } 453 458 } … … 455 460 // Accepted. 456 461 if ( ! empty( $args['accepted'] ) && 'all' !== $args['accepted'] ) { 457 if ( $args['accepted'] == 'pending' ) {458 $where_conditions['accepted'] = "accepted = 0";459 } else if ( $args['accepted']== 'accepted' ) {460 $where_conditions['accepted'] = "accepted = 1";462 if ( $args['accepted'] === 'pending' ) { 463 $where_conditions['accepted'] = 'accepted = 0'; 464 } elseif ( $args['accepted'] === 'accepted' ) { 465 $where_conditions['accepted'] = 'accepted = 1'; 461 466 } 462 467 } … … 464 469 // search_terms. 465 470 if ( ! empty( $args['search_terms'] ) ) { 466 $search_terms_like = '%' . bp_esc_like( $args['search_terms'] ) . '%';471 $search_terms_like = '%' . bp_esc_like( $args['search_terms'] ) . '%'; 467 472 $where_conditions['search_terms'] = $wpdb->prepare( '( invitee_email LIKE %s OR content LIKE %s )', $search_terms_like, $search_terms_like ); 468 473 } … … 539 544 // Custom LIMIT. 540 545 if ( ! empty( $args['page'] ) && ! empty( $args['per_page'] ) ) { 541 $page = absint( $args['page'] 546 $page = absint( $args['page'] ); 542 547 $per_page = absint( $args['per_page'] ); 543 548 $offset = $per_page * ( $page - 1 ); 544 $retval = $wpdb->prepare( "LIMIT %d, %d", $offset, $per_page );549 $retval = $wpdb->prepare( 'LIMIT %d, %d', $offset, $per_page ); 545 550 } 546 551 … … 597 602 if ( ! empty( $args['id'] ) ) { 598 603 $where_clauses['data']['id'] = absint( $args['id'] ); 599 $where_clauses['format'][] = '%d';604 $where_clauses['format'][] = '%d'; 600 605 } 601 606 … … 603 608 if ( ! empty( $args['user_id'] ) ) { 604 609 $where_clauses['data']['user_id'] = absint( $args['user_id'] ); 605 $where_clauses['format'][] = '%d';610 $where_clauses['format'][] = '%d'; 606 611 } 607 612 … … 609 614 if ( ! empty( $args['inviter_id'] ) ) { 610 615 $where_clauses['data']['inviter_id'] = absint( $args['inviter_id'] ); 611 $where_clauses['format'][] = '%d';616 $where_clauses['format'][] = '%d'; 612 617 } 613 618 … … 615 620 if ( ! empty( $args['invitee_email'] ) ) { 616 621 $where_clauses['data']['invitee_email'] = $args['invitee_email']; 617 $where_clauses['format'][] = '%s';622 $where_clauses['format'][] = '%s'; 618 623 } 619 624 … … 621 626 if ( ! empty( $args['class'] ) ) { 622 627 $where_clauses['data']['class'] = $args['class']; 623 $where_clauses['format'][] = '%s';628 $where_clauses['format'][] = '%s'; 624 629 } 625 630 … … 627 632 if ( ! empty( $args['item_id'] ) ) { 628 633 $where_clauses['data']['item_id'] = absint( $args['item_id'] ); 629 $where_clauses['format'][] = '%d';634 $where_clauses['format'][] = '%d'; 630 635 } 631 636 … … 633 638 if ( ! empty( $args['secondary_item_id'] ) ) { 634 639 $where_clauses['data']['secondary_item_id'] = absint( $args['secondary_item_id'] ); 635 $where_clauses['format'][] = '%d';640 $where_clauses['format'][] = '%d'; 636 641 } 637 642 638 643 // type. 639 644 if ( ! empty( $args['type'] ) && 'all' !== $args['type'] ) { 640 if ( 'invite' == $args['type'] || 'request'== $args['type'] ) {645 if ( 'invite' === $args['type'] || 'request' === $args['type'] ) { 641 646 $where_clauses['data']['type'] = $args['type']; 642 $where_clauses['format'][] = '%s';647 $where_clauses['format'][] = '%s'; 643 648 } 644 649 } 645 650 646 651 /** 647 * invite_sent648 652 * Only create a where statement if something less than "all" has been 649 653 * specifically requested. 650 654 */ 651 655 if ( isset( $args['invite_sent'] ) && 'all' !== $args['invite_sent'] ) { 652 if ( $args['invite_sent'] == 'draft' ) {656 if ( $args['invite_sent'] === 'draft' ) { 653 657 $where_clauses['data']['invite_sent'] = 0; 654 $where_clauses['format'][] = '%d';655 } else if ( $args['invite_sent']== 'sent' ) {658 $where_clauses['format'][] = '%d'; 659 } elseif ( $args['invite_sent'] === 'sent' ) { 656 660 $where_clauses['data']['invite_sent'] = 1; 657 $where_clauses['format'][] = '%d';661 $where_clauses['format'][] = '%d'; 658 662 } 659 663 } … … 661 665 // accepted. 662 666 if ( ! empty( $args['accepted'] ) && 'all' !== $args['accepted'] ) { 663 if ( $args['accepted'] == 'pending' ) {667 if ( $args['accepted'] === 'pending' ) { 664 668 $where_clauses['data']['accepted'] = 0; 665 $where_clauses['format'][] = '%d';666 } else if ( $args['accepted']== 'accepted' ) {669 $where_clauses['format'][] = '%d'; 670 } elseif ( $args['accepted'] === 'accepted' ) { 667 671 $where_clauses['data']['accepted'] = 1; 668 $where_clauses['format'][] = '%d';669 } 670 } 671 672 // date_modified 672 $where_clauses['format'][] = '%d'; 673 } 674 } 675 676 // date_modified. 673 677 if ( ! empty( $args['date_modified'] ) ) { 674 678 $where_clauses['data']['date_modified'] = $args['date_modified']; 675 $where_clauses['format'][] = '%s';679 $where_clauses['format'][] = '%s'; 676 680 } 677 681 … … 685 689 * 686 690 * @since 5.0.0 691 * 692 * @global wpdb $wpdb WordPress database object. 687 693 * 688 694 * @param array $args { … … 697 703 * invitation. Can be an array of IDs. 698 704 * @type string|array $invitee_email Email address of invited users 699 * 705 * being queried. Can be an array of 700 706 * addresses. 701 707 * @type string|array $class Name of the class to filter by. … … 735 741 * } 736 742 * 737 * @return arrayBP_Invitation objects | IDs of found invite.743 * @return int[]|BP_Invitation[] BP_Invitation objects | IDs of found invite. 738 744 */ 739 745 public static function get( $args = array() ) { … … 766 772 767 773 $sql = array( 768 'select' => "SELECT",774 'select' => 'SELECT', 769 775 'fields' => '', 770 776 'from' => "FROM {$invites_table_name} i", … … 775 781 776 782 if ( 'item_ids' === $r['fields'] ) { 777 $sql['fields'] = "DISTINCT i.item_id";778 } else 779 $sql['fields'] = "DISTINCT i.user_id";780 } else 781 $sql['fields'] = "DISTINCT i.inviter_id";783 $sql['fields'] = 'DISTINCT i.item_id'; 784 } elseif ( 'user_ids' === $r['fields'] ) { 785 $sql['fields'] = 'DISTINCT i.user_id'; 786 } elseif ( 'inviter_ids' === $r['fields'] ) { 787 $sql['fields'] = 'DISTINCT i.inviter_id'; 782 788 } else { 783 789 $sql['fields'] = 'DISTINCT i.id'; … … 785 791 786 792 // WHERE. 787 $sql['where'] = self::get_where_sql( array( 788 'id' => $r['id'], 789 'user_id' => $r['user_id'], 790 'inviter_id' => $r['inviter_id'], 791 'invitee_email' => $r['invitee_email'], 792 'class' => $r['class'], 793 'item_id' => $r['item_id'], 794 'secondary_item_id' => $r['secondary_item_id'], 795 'type' => $r['type'], 796 'invite_sent' => $r['invite_sent'], 797 'accepted' => $r['accepted'], 798 'search_terms' => $r['search_terms'], 799 ) ); 793 $sql['where'] = self::get_where_sql( 794 array( 795 'id' => $r['id'], 796 'user_id' => $r['user_id'], 797 'inviter_id' => $r['inviter_id'], 798 'invitee_email' => $r['invitee_email'], 799 'class' => $r['class'], 800 'item_id' => $r['item_id'], 801 'secondary_item_id' => $r['secondary_item_id'], 802 'type' => $r['type'], 803 'invite_sent' => $r['invite_sent'], 804 'accepted' => $r['accepted'], 805 'search_terms' => $r['search_terms'], 806 ) 807 ); 800 808 801 809 // ORDER BY. 802 $sql['orderby'] = self::get_order_by_sql( array( 803 'order_by' => $r['order_by'], 804 'sort_order' => $r['sort_order'] 805 ) ); 810 $sql['orderby'] = self::get_order_by_sql( 811 array( 812 'order_by' => $r['order_by'], 813 'sort_order' => $r['sort_order'], 814 ) 815 ); 806 816 807 817 // LIMIT %d, %d. 808 $sql['pagination'] = self::get_paged_sql( array( 809 'page' => $r['page'], 810 'per_page' => $r['per_page'], 811 ) ); 818 $sql['pagination'] = self::get_paged_sql( 819 array( 820 'page' => $r['page'], 821 'per_page' => $r['per_page'], 822 ) 823 ); 812 824 813 825 $paged_invites_sql = "{$sql['select']} {$sql['fields']} {$sql['from']} {$sql['where']} {$sql['orderby']} {$sql['pagination']}"; … … 840 852 $uncached_ids = bp_get_non_cached_ids( $paged_invite_ids, 'bp_invitations' ); 841 853 if ( $uncached_ids ) { 842 $ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) );854 $ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) ); 843 855 $data_objects = $wpdb->get_results( "SELECT i.* FROM {$invites_table_name} i WHERE i.id IN ({$ids_sql})" ); 844 856 foreach ( $data_objects as $data_object ) { … … 859 871 * 860 872 * @since 5.0.0 873 * 874 * @global wpdb $wpdb WordPress database object. 861 875 * 862 876 * @see BP_Invitation::get() for a description of … … 893 907 ); 894 908 895 // Build the query 896 $select_sql = "SELECT COUNT(*)";909 // Build the query. 910 $select_sql = 'SELECT COUNT(*)'; 897 911 $from_sql = "FROM {$invites_table_name}"; 898 912 $where_sql = self::get_where_sql( $r ); 899 913 $sql = "{$select_sql} {$from_sql} {$where_sql}"; 900 914 901 // Return the queried results 915 // Return the queried results. 902 916 return $wpdb->get_var( $sql ); 903 917 } … … 921 935 public static function update( $update_args = array(), $where_args = array() ) { 922 936 $update = self::get_query_clauses( $update_args ); 923 $where = self::get_query_clauses( $where_args 937 $where = self::get_query_clauses( $where_args ); 924 938 925 939 /** … … 937 951 938 952 // Clear matching items from the cache. 939 $cache_args = $where_args;953 $cache_args = $where_args; 940 954 $cache_args['fields'] = 'ids'; 941 $maybe_cached_ids = self::get( $cache_args );955 $maybe_cached_ids = self::get( $cache_args ); 942 956 foreach ( $maybe_cached_ids as $invite_id ) { 943 957 wp_cache_delete( $invite_id, 'bp_invitations' ); … … 984 998 985 999 // Clear matching items from the cache. 986 $cache_args = $args;1000 $cache_args = $args; 987 1001 $cache_args['fields'] = 'ids'; 988 $maybe_cached_ids = self::get( $cache_args );1002 $maybe_cached_ids = self::get( $cache_args ); 989 1003 foreach ( $maybe_cached_ids as $invite_id ) { 990 1004 wp_cache_delete( $invite_id, 'bp_invitations' ); … … 1016 1030 * 1017 1031 * @param int $id ID of the invitation item to be deleted. 1018 * @return bool Trueon success, false on failure.1032 * @return bool|int Number of rows deleted on success, false on failure. 1019 1033 */ 1020 1034 public static function delete_by_id( $id ) { 1021 return self::delete( array( 1022 'id' => $id, 1023 ) ); 1035 return self::delete( array( 'id' => $id ) ); 1024 1036 } 1025 1037 … … 1153 1165 return self::update( $update_args, $args ); 1154 1166 } 1155 1156 1167 } -
trunk/src/bp-core/classes/class-bp-members-suggestions.php
r13372 r13888 39 39 ); 40 40 41 42 41 /** 43 42 * Validate and sanitise the parameters for the suggestion service query. … … 58 57 * @param BP_Members_Suggestions $suggestions Current BP_Members_Suggestions instance. 59 58 */ 60 $this->args 59 $this->args = apply_filters( 'bp_members_suggestions_args', $this->args, $this ); 61 60 62 61 // Check for invalid or missing mandatory parameters. … … 113 112 } 114 113 115 116 114 $user_query = new BP_User_Query( $user_query ); 117 115 $results = array(); … … 120 118 $result = new stdClass(); 121 119 $result->ID = $user->user_nicename; 122 $result->image = bp_core_fetch_avatar( array( 'html' => false, 'item_id' => $user->ID ) ); 120 $result->image = bp_core_fetch_avatar( 121 array( 122 'html' => false, 123 'item_id' => $user->ID, 124 ) 125 ); 123 126 $result->name = bp_core_get_user_displayname( $user->ID ); 124 127 $result->user_id = $user->ID; -
trunk/src/bp-core/classes/class-bp-optout.php
r13395 r13888 25 25 * 26 26 * @since 8.0.0 27 * @access public27 * 28 28 * @var int 29 29 */ … … 35 35 * 36 36 * @since 8.0.0 37 * @access public37 * 38 38 * @var string 39 39 */ … … 44 44 * 45 45 * @since 8.0.0 46 * @access public46 * 47 47 * @var int 48 48 */ … … 54 54 * 55 55 * @since 8.0.0 56 * @access public56 * 57 57 * @var string 58 58 */ … … 63 63 * 64 64 * @since 8.0.0 65 * @access public65 * 66 66 * @var string 67 67 */ … … 75 75 * @since 8.0.0 76 76 * 77 * @param int $id Optional. Provide an ID to access an existing 78 * optout item. 77 * @param int $id Optional. Provide an ID to access an existing optout item. 79 78 */ 80 79 public function __construct( $id = 0 ) { … … 89 88 * 90 89 * @since 8.0.0 91 * @access public90 * 92 91 * @return string 93 92 */ … … 103 102 * @global wpdb $wpdb WordPress database object. 104 103 * 105 * @return bool True on success, false on failure.104 * @return bool 106 105 */ 107 106 public function save() { 108 107 109 // Return value 108 // Return value. 110 109 $retval = false; 111 110 112 // Default data and format 113 $data = array(111 // Default data and format. 112 $data = array( 114 113 'email_address_hash' => $this->email_address, 115 114 'user_id' => $this->user_id, … … 131 130 if ( ! empty( $this->id ) ) { 132 131 $result = self::_update( $data, array( 'ID' => $this->id ), $data_format, array( '%d' ) ); 133 // Insert.132 // Insert. 134 133 } else { 135 134 $result = self::_insert( $data, $data_format ); … … 151 150 * @since 8.0.0 152 151 * 153 * @param BP_optout object $thisCharacteristics of the opt-out just saved.152 * @param BP_optout $bp_optout Characteristics of the opt-out just saved. 154 153 */ 155 154 do_action_ref_array( 'bp_optout_after_save', array( &$this ) ); … … 189 188 $this->email_type = sanitize_key( $optout->email_type ); 190 189 $this->date_modified = $optout->date_modified; 191 192 190 } 193 191 … … 198 196 * 199 197 * @since 8.0.0 198 * 199 * @global wpdb $wpdb WordPress database object. 200 200 * 201 201 * @param array $data { 202 202 * Array of optout data, passed to {@link wpdb::insert()}. 203 * 203 * @type string $email_address The hashed email address of the user that wishes to opt out of 204 204 * communications from this site. 205 * 206 * 207 * 205 * @type int $user_id The ID of the user that generated the contact that resulted in the opt-out. 206 * @type string $email_type The type of email contact that resulted in the opt-out. 207 * @type string $date_modified Date the opt-out was last modified. 208 208 * } 209 209 * @param array $data_format See {@link wpdb::insert()}. … … 212 212 protected static function _insert( $data = array(), $data_format = array() ) { 213 213 global $wpdb; 214 214 215 // We must lowercase and hash the email address at insert. 215 216 $email = strtolower( $data['email_address_hash'] ); 216 217 $data['email_address_hash'] = wp_hash( $email ); 217 return $wpdb->insert( BP_Optout::get_table_name(), $data, $data_format );218 return $wpdb->insert( self::get_table_name(), $data, $data_format ); 218 219 } 219 220 … … 222 223 * 223 224 * @since 8.0.0 225 * 226 * @global wpdb $wpdb WordPress database object. 224 227 * 225 228 * @see wpdb::update() for further description of paramater formats. … … 244 247 } 245 248 246 return $wpdb->update( BP_Optout::get_table_name(), $data, $where, $data_format, $where_format );249 return $wpdb->update( self::get_table_name(), $data, $where, $data_format, $where_format ); 247 250 } 248 251 … … 251 254 * 252 255 * @since 8.0.0 256 * 257 * @global wpdb $wpdb WordPress database object. 253 258 * 254 259 * @see wpdb::update() for further description of paramater formats. … … 262 267 protected static function _delete( $where = array(), $where_format = array() ) { 263 268 global $wpdb; 264 return $wpdb->delete( BP_Optout::get_table_name(), $where, $where_format );269 return $wpdb->delete( self::get_table_name(), $where, $where_format ); 265 270 } 266 271 … … 272 277 * 273 278 * @since 8.0.0 279 * 280 * @global wpdb $wpdb WordPress database object. 274 281 * 275 282 * @param array $args See {@link BP_optout::get()} for more details. … … 358 365 */ 359 366 protected static function get_order_by_sql( $args = array() ) { 360 361 367 $conditions = array(); 362 368 $retval = ''; … … 398 404 * @since 8.0.0 399 405 * 406 * @global wpdb $wpdb WordPress database object. 407 * 400 408 * @param array $args See {@link BP_optout::get()} for more details. 401 409 * @return string LIMIT clause. … … 409 417 // Custom LIMIT. 410 418 if ( ! empty( $args['page'] ) && ! empty( $args['per_page'] ) ) { 411 $page = absint( $args['page'] 419 $page = absint( $args['page'] ); 412 420 $per_page = absint( $args['per_page'] ); 413 421 $offset = $per_page * ( $page - 1 ); 414 $retval = $wpdb->prepare( "LIMIT %d, %d", $offset, $per_page );422 $retval = $wpdb->prepare( 'LIMIT %d, %d', $offset, $per_page ); 415 423 } 416 424 … … 498 506 * @since 8.0.0 499 507 * 508 * @global wpdb $wpdb WordPress database object. 509 * 500 510 * @param array $args { 501 511 * Associative array of arguments. All arguments but $page and … … 505 515 * Can be an array of IDs. 506 516 * @type string|array $email_address Email address of users who have opted out 507 * 517 * being queried. Can be an array of addresses. 508 518 * @type int|array $user_id ID of user whose communication prompted the 509 519 * opt-out. Can be an array of IDs. … … 519 529 * Default: false (no pagination, 520 530 * all items). 521 522 523 524 525 526 531 * @type string $fields Which fields to return. Specify 'email_addresses' to 532 * fetch a list of opt-out email_addresses. 533 * Specify 'user_ids' to 534 * fetch a list of opt-out user_ids. 535 * Specify 'ids' to fetch a list of opt-out IDs. 536 * Default: 'all' (return BP_Optout objects). 527 537 * } 528 538 * … … 531 541 public static function get( $args = array() ) { 532 542 global $wpdb; 533 $optouts_table_name = BP_Optout::get_table_name();543 $optouts_table_name = self::get_table_name(); 534 544 535 545 // Parse the arguments. … … 552 562 553 563 $sql = array( 554 'select' => "SELECT",564 'select' => 'SELECT', 555 565 'fields' => '', 556 566 'from' => "FROM {$optouts_table_name} o", … … 561 571 562 572 if ( 'user_ids' === $r['fields'] ) { 563 $sql['fields'] = "DISTINCT o.user_id";564 } else 565 $sql['fields'] = "DISTINCT o.email_address_hash";573 $sql['fields'] = 'DISTINCT o.user_id'; 574 } elseif ( 'email_addresses' === $r['fields'] ) { 575 $sql['fields'] = 'DISTINCT o.email_address_hash'; 566 576 } else { 567 577 $sql['fields'] = 'DISTINCT o.id'; … … 583 593 array( 584 594 'order_by' => $r['order_by'], 585 'sort_order' => $r['sort_order'] 595 'sort_order' => $r['sort_order'], 586 596 ) 587 597 ); … … 620 630 // We only want the field that was found. 621 631 return array_map( 'intval', $paged_optout_ids ); 622 } else 632 } elseif ( 'email_addresses' === $r['fields'] ) { 623 633 return $paged_optout_ids; 624 634 } … … 626 636 $uncached_ids = bp_get_non_cached_ids( $paged_optout_ids, 'bp_optouts' ); 627 637 if ( $uncached_ids ) { 628 $ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) );638 $ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) ); 629 639 $data_objects = $wpdb->get_results( "SELECT o.* FROM {$optouts_table_name} o WHERE o.id IN ({$ids_sql})" ); 630 640 foreach ( $data_objects as $data_object ) { … … 646 656 * @since 8.0.0 647 657 * 658 * @global wpdb $wpdb WordPress database object. 659 * 648 660 * @see BP_optout::get() for a description of 649 661 * arguments. … … 654 666 public static function get_total_count( $args ) { 655 667 global $wpdb; 656 $optouts_table_name = BP_Optout::get_table_name();668 $optouts_table_name = self::get_table_name(); 657 669 658 670 // Parse the arguments. 659 $r 671 $r = bp_parse_args( 660 672 $args, 661 673 array( … … 674 686 ); 675 687 676 // Build the query 677 $select_sql = "SELECT COUNT(*)";688 // Build the query. 689 $select_sql = 'SELECT COUNT(*)'; 678 690 $from_sql = "FROM {$optouts_table_name}"; 679 691 $where_sql = self::get_where_sql( $r ); 680 692 $sql = "{$select_sql} {$from_sql} {$where_sql}"; 681 693 682 // Return the queried results 694 // Return the queried results. 683 695 return $wpdb->get_var( $sql ); 684 696 } … … 702 714 public static function update( $update_args = array(), $where_args = array() ) { 703 715 $update = self::get_query_clauses( $update_args ); 704 $where = self::get_query_clauses( $where_args 716 $where = self::get_query_clauses( $where_args ); 705 717 706 718 /** … … 736 748 do_action( 'bp_optout_after_update', $where_args, $update_args ); 737 749 738 750 return $retval; 739 751 } 740 752 … … 795 807 * @see BP_Optout::get() for a description of accepted parameters. 796 808 * 809 * @param array $args Arguments to pass to BP_optout::get(). 797 810 * @return int|bool ID of first found invitation or false if none found. 798 811 */ … … 801 814 802 815 $args['fields'] = 'ids'; 803 $optouts = BP_Optout::get( $args );816 $optouts = self::get( $args ); 804 817 if ( $optouts ) { 805 818 $exists = current( $optouts ); … … 818 831 * 819 832 * @param int $id ID of the opt-out item to be deleted. 820 * @return bool Trueon success, false on failure.833 * @return bool|int Number of rows deleted on success, false on failure. 821 834 */ 822 835 public static function delete_by_id( $id ) { 823 return self::delete( array( 824 'id' => $id, 825 ) ); 836 return self::delete( array( 'id' => $id ) ); 826 837 } 827 838 } -
trunk/src/bp-core/classes/class-bp-optouts-list-table.php
r13882 r13888 131 131 * @param string $url_base Current URL base for view. 132 132 */ 133 do_action( 'bp_optouts_list_table_get_views', $url_base ); ?> 133 do_action( 'bp_optouts_list_table_get_views', $url_base ); 134 ?> 134 135 </ul> 135 <?php136 <?php 136 137 } 137 138 … … 146 147 * @param array $which Current table nav item. 147 148 */ 148 public function extra_tablenav( $which ) { 149 return; 150 } 149 public function extra_tablenav( $which ) {} 151 150 152 151 /** … … 224 223 $style = ''; 225 224 foreach ( $this->items as $optout ) { 226 $style = 'alt' == $style ? '' : 'alt';225 $style = 'alt' === $style ? '' : 'alt'; 227 226 228 227 // Escapes are made into `self::single_row()`. … … 265 264 */ 266 265 public function column_cb( $optout = null ) { 267 ?>266 ?> 268 267 <label class="screen-reader-text" for="optout_<?php echo intval( $optout->id ); ?>"> 269 268 <?php … … 272 271 ?> 273 272 </label> 274 <input type="checkbox" id="optout_<?php echo intval( $optout->id ) ?>" name="optout_ids[]" value="<?php echo esc_attr( $optout->id )?>" />273 <input type="checkbox" id="optout_<?php echo intval( $optout->id ); ?>" name="optout_ids[]" value="<?php echo esc_attr( $optout->id ); ?>" /> 275 274 <?php 276 275 } … … 281 280 * @since 8.0.0 282 281 * 283 * @param BP_Optout $optout BP_Optout object.282 * @param BP_Optout|null $optout BP_Optout object. 284 283 */ 285 284 public function column_email_address( $optout = null ) { … … 295 294 296 295 // Delete link. 297 $delete_link = add_query_arg(296 $delete_link = add_query_arg( 298 297 array( 299 298 'page' => 'bp-optouts', … … 325 324 * @since 8.0.0 326 325 * 327 * @param BP_Optout $optout BP_Optout object.326 * @param BP_Optout|null $optout BP_Optout object. 328 327 */ 329 328 public function column_username( $optout = null ) { … … 347 346 'height' => true, 348 347 'width' => true, 349 ) 348 ), 350 349 ) 351 350 ); … … 358 357 * @since 8.0.0 359 358 * 360 * @param BP_Optout $optout BP_Optout object.359 * @param BP_Optout|null $optout BP_Optout object. 361 360 */ 362 361 public function column_user_registered( $optout = null ) { … … 367 366 } 368 367 369 echo esc_html( mysql2date( 'Y/m/d g:i:s a', $inviter->user_registered 368 echo esc_html( mysql2date( 'Y/m/d g:i:s a', $inviter->user_registered ) ); 370 369 } 371 370 … … 375 374 * @since 8.0.0 376 375 * 377 * @param BP_Optout $optout BP_Optout object.376 * @param BP_Optout|null $optout BP_Optout object. 378 377 */ 379 378 public function column_email_type( $optout = null ) { … … 386 385 * @since 8.0.0 387 386 * 388 * @param BP_Optout $optout BP_Optout object.387 * @param BP_Optout|null $optout BP_Optout object. 389 388 */ 390 389 public function column_email_type_description( $optout = null ) { … … 394 393 echo esc_html( $type_term->description ); 395 394 } 396 397 395 } 398 396 … … 402 400 * @since 8.0.0 403 401 * 404 * @param BP_Optout $optout BP_Optout object.402 * @param BP_Optout|null $optout BP_Optout object. 405 403 */ 406 404 public function column_optout_date_modified( $optout = null ) { … … 413 411 * @since 8.0.0 414 412 * 415 * @param BP_Optout $optout BP_Optout object.416 * @param string $column_name The column name.413 * @param BP_Optout|null $optout BP_Optout object. 414 * @param string $column_name The column name. 417 415 * @return string 418 416 */ 419 function column_default( $optout = null, $column_name = '' ) {417 public function column_default( $optout = null, $column_name = '' ) { 420 418 421 419 /** … … 424 422 * @since 8.0.0 425 423 * 426 * @param string $column_name The column name.427 * @param BP_Optout $optout BP_Optout object.424 * @param string $column_name The column name. 425 * @param BP_Optout|null $optout BP_Optout object or null. 428 426 */ 429 427 return apply_filters( 'bp_optouts_management_custom_column', '', $column_name, $optout ); -
trunk/src/bp-core/classes/class-bp-phpmailer.php
r13297 r13888 69 69 */ 70 70 $phpmailer->Subject = $email->get_subject( 'replace-tokens' ); 71 $content_plaintext = PHPMailer\PHPMailer\PHPMailer::normalizeBreaks( $email->get_content_plaintext( 'replace-tokens' ) );71 $content_plaintext = PHPMailer\PHPMailer\PHPMailer::normalizeBreaks( $email->get_content_plaintext( 'replace-tokens' ) ); 72 72 73 73 if ( $email->get( 'content_type' ) === 'html' ) { … … 140 140 } 141 141 142 /*143 * Utility/helper functions.144 */145 146 142 /** 147 143 * Get an appropriate hostname for the email. Varies depending on site configuration. -
trunk/src/bp-core/classes/class-bp-recursive-query.php
r13887 r13888 22 22 * 23 23 * @since 2.2.0 24 * 24 25 * @var array 25 26 */
Note: See TracChangeset
for help on using the changeset viewer.