Changeset 13888 for trunk/src/bp-core/classes/class-bp-optout.php
- Timestamp:
- 06/01/2024 10:25:18 PM (2 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-core/classes/class-bp-optout.php (modified) (38 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 * @type string $email_address The hashed email address of the user that wishes to opt out of203 * @type string $email_address The hashed email address of the user that wishes to opt out of 204 204 * communications from this site. 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.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 * being queried. Can be an array of addresses.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 * @type string $fields Which fields to return. Specify 'email_addresses' to522 * fetch a list of opt-out email_addresses.523 * Specify 'user_ids' to524 * fetch a list of opt-out user_ids.525 * Specify 'ids' to fetch a list of opt-out IDs.526 * Default: 'all' (return BP_Optout objects).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 if ( 'email_addresses' === $r['fields'] ) {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 if ( 'email_addresses' === $r['fields'] ) {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 = bp_parse_args(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 return $retval;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 }
Note: See TracChangeset
for help on using the changeset viewer.