Changeset 13991 for trunk/src/bp-core/classes/class-bp-optout.php
- Timestamp:
- 07/27/2024 08:16:17 PM (19 months ago)
- File:
-
- 1 edited
-
trunk/src/bp-core/classes/class-bp-optout.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-optout.php
r13888 r13991 102 102 * @global wpdb $wpdb WordPress database object. 103 103 * 104 * @return bool104 * @return false|int 105 105 */ 106 106 public function save() { 107 global $wpdb; 107 108 108 109 // Return value. … … 110 111 111 112 // Default data and format. 112 $data = array(113 $data = array( 113 114 'email_address_hash' => $this->email_address, 114 115 'user_id' => $this->user_id, … … 116 117 'date_modified' => $this->date_modified, 117 118 ); 119 118 120 $data_format = array( '%s', '%d', '%s', '%s' ); 119 121 … … 123 125 * @since 8.0.0 124 126 * 125 * @param BP_Optout object $thisCharacteristics of the opt-out to be saved.127 * @param BP_Optout $bp_optout Characteristics of the opt-out to be saved. 126 128 */ 127 129 do_action_ref_array( 'bp_optout_before_save', array( &$this ) ); … … 137 139 // Set the opt-out ID if successful. 138 140 if ( ! empty( $result ) && ! is_wp_error( $result ) ) { 139 global $wpdb;140 141 141 $this->id = $wpdb->insert_id; 142 142 $retval = $wpdb->insert_id; … … 505 505 * 506 506 * @since 8.0.0 507 * @since 15.0.0 Introduced the `cache_results` parameter. 507 508 * 508 509 * @global wpdb $wpdb WordPress database object. … … 526 527 * Default: false (no pagination, 527 528 * all items). 529 * @type bool $cache_results Optional. Whether to cache the optout information. Default: true. 528 530 * @type int $per_page Number of items to show per page. 529 531 * Default: false (no pagination, … … 541 543 public static function get( $args = array() ) { 542 544 global $wpdb; 545 543 546 $optouts_table_name = self::get_table_name(); 544 547 … … 556 559 'page' => false, 557 560 'per_page' => false, 561 'cache_results' => true, 558 562 'fields' => 'all', 559 563 ), … … 562 566 563 567 $sql = array( 564 'select' => 'SELECT', 565 'fields' => '', 566 'from' => "FROM {$optouts_table_name} o", 567 'where' => '', 568 'orderby' => '', 569 'pagination' => '', 568 'select' => 'SELECT', 569 'from' => "FROM {$optouts_table_name} o", 570 570 ); 571 571 … … 612 612 * @since 8.0.0 613 613 * 614 * @param string $ valueConcatenated SQL statement.615 * @param array $sql Array of SQL parts before concatenation.616 * @param array $r Array of parsed arguments for the get method.614 * @param string $paged_optouts_sql Concatenated SQL statement. 615 * @param array $sql Array of SQL parts before concatenation. 616 * @param array $r Array of parsed arguments for the get method. 617 617 */ 618 618 $paged_optouts_sql = apply_filters( 'bp_optouts_get_paged_optouts_sql', $paged_optouts_sql, $sql, $r ); 619 619 620 $cached = bp_core_get_incremented_cache( $paged_optouts_sql, 'bp_optouts' ); 621 if ( false === $cached ) { 620 if ( $r['cache_results'] ) { 621 $cached = bp_core_get_incremented_cache( $paged_optouts_sql, 'bp_optouts' ); 622 if ( false === $cached ) { 623 $paged_optout_ids = $wpdb->get_col( $paged_optouts_sql ); 624 bp_core_set_incremented_cache( $paged_optouts_sql, 'bp_optouts', $paged_optout_ids ); 625 } else { 626 $paged_optout_ids = $cached; 627 } 628 } else { 622 629 $paged_optout_ids = $wpdb->get_col( $paged_optouts_sql ); 623 bp_core_set_incremented_cache( $paged_optouts_sql, 'bp_optouts', $paged_optout_ids );624 } else {625 $paged_optout_ids = $cached;626 630 } 627 631 … … 634 638 } 635 639 636 $uncached_ids = bp_get_non_cached_ids( $paged_optout_ids, 'bp_optouts' ); 637 if ( $uncached_ids ) { 638 $ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) ); 639 $data_objects = $wpdb->get_results( "SELECT o.* FROM {$optouts_table_name} o WHERE o.id IN ({$ids_sql})" ); 640 foreach ( $data_objects as $data_object ) { 641 wp_cache_set( $data_object->id, $data_object, 'bp_optouts' ); 640 if ( $r['cache_results'] ) { 641 $uncached_ids = bp_get_non_cached_ids( $paged_optout_ids, 'bp_optouts' ); 642 if ( $uncached_ids ) { 643 $ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) ); 644 $data_objects = $wpdb->get_results( "SELECT o.* FROM {$optouts_table_name} o WHERE o.id IN ({$ids_sql})" ); 645 foreach ( $data_objects as $data_object ) { 646 wp_cache_set( $data_object->id, $data_object, 'bp_optouts' ); 647 } 642 648 } 643 649 }
Note: See TracChangeset
for help on using the changeset viewer.