Changeset 13990 for trunk/src/bp-core/classes/class-bp-invitation.php
- Timestamp:
- 07/27/2024 08:14:28 PM (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-invitation.php
r13890 r13990 358 358 * Assemble the WHERE clause of a get() SQL statement. 359 359 * 360 * Used by BP_Invitation::get() to create its WHERE361 * clause.362 *363 360 * @since 5.0.0 364 361 * … … 439 436 440 437 // Type. 441 if ( ! empty( $args['type'] ) && 'all' !== $args['type'] ) { 442 if ( 'invite' === $args['type'] || 'request' === $args['type'] ) { 443 $type_clean = $wpdb->prepare( '%s', $args['type'] ); 444 $where_conditions['type'] = "type = {$type_clean}"; 445 } 438 if ( ! empty( $args['type'] ) && ( 'invite' === $args['type'] || 'request' === $args['type'] ) ) { 439 $type_clean = $wpdb->prepare( '%s', $args['type'] ); 440 $where_conditions['type'] = "type = {$type_clean}"; 446 441 } 447 442 … … 689 684 * 690 685 * @since 5.0.0 686 * @since 15.0.0 Introduced the `cache_results` parameter. 691 687 * 692 688 * @global wpdb $wpdb WordPress database object. … … 730 726 * @type string $order_by Field to order results by. 731 727 * @type string $sort_order ASC or DESC. 728 * @type bool $cache_results Optional. Whether to cache invitation information. Default true. 732 729 * @type int $page Number of the current page of results. 733 730 * Default: false (no pagination, … … 745 742 public static function get( $args = array() ) { 746 743 global $wpdb; 744 747 745 $invites_table_name = BP_Invitation_Manager::get_table_name(); 748 746 … … 764 762 'order_by' => false, 765 763 'sort_order' => false, 764 'cache_results' => true, 766 765 'page' => false, 767 766 'per_page' => false, … … 772 771 773 772 $sql = array( 774 'select' => 'SELECT', 775 'fields' => '', 776 'from' => "FROM {$invites_table_name} i", 777 'where' => '', 778 'orderby' => '', 779 'pagination' => '', 773 'select' => 'SELECT', 774 'from' => "FROM {$invites_table_name} i", 775 'fields' => 'DISTINCT i.id', 780 776 ); 781 777 … … 786 782 } elseif ( 'inviter_ids' === $r['fields'] ) { 787 783 $sql['fields'] = 'DISTINCT i.inviter_id'; 788 } else {789 $sql['fields'] = 'DISTINCT i.id';790 784 } 791 785 … … 830 824 * @since 5.0.0 831 825 * 832 * @param string $ valueConcatenated SQL statement.833 * @param array $sql Array of SQL parts before concatenation.834 * @param array $r Array of parsed arguments for the get method.826 * @param string $paged_invites_sql Concatenated SQL statement. 827 * @param array $sql Array of SQL parts before concatenation. 828 * @param array $r Array of parsed arguments for the get method. 835 829 */ 836 830 $paged_invites_sql = apply_filters( 'bp_invitations_get_paged_invitations_sql', $paged_invites_sql, $sql, $r ); 837 831 838 $cached = bp_core_get_incremented_cache( $paged_invites_sql, 'bp_invitations' ); 839 if ( false === $cached ) { 832 if ( $r['cache_results'] ) { 833 $cached = bp_core_get_incremented_cache( $paged_invites_sql, 'bp_invitations' ); 834 if ( false === $cached ) { 835 $paged_invite_ids = $wpdb->get_col( $paged_invites_sql ); 836 bp_core_set_incremented_cache( $paged_invites_sql, 'bp_invitations', $paged_invite_ids ); 837 } else { 838 $paged_invite_ids = $cached; 839 } 840 } else { 840 841 $paged_invite_ids = $wpdb->get_col( $paged_invites_sql ); 841 bp_core_set_incremented_cache( $paged_invites_sql, 'bp_invitations', $paged_invite_ids );842 } else {843 $paged_invite_ids = $cached;844 842 } 845 843 … … 850 848 } 851 849 852 $uncached_ids = bp_get_non_cached_ids( $paged_invite_ids, 'bp_invitations' ); 853 if ( $uncached_ids ) { 854 $ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) ); 855 $data_objects = $wpdb->get_results( "SELECT i.* FROM {$invites_table_name} i WHERE i.id IN ({$ids_sql})" ); 856 foreach ( $data_objects as $data_object ) { 857 wp_cache_set( $data_object->id, $data_object, 'bp_invitations' ); 850 if ( $r['cache_results'] ) { 851 $uncached_ids = bp_get_non_cached_ids( $paged_invite_ids, 'bp_invitations' ); 852 if ( $uncached_ids ) { 853 $ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) ); 854 $data_objects = $wpdb->get_results( "SELECT i.* FROM {$invites_table_name} i WHERE i.id IN ({$ids_sql})" ); 855 foreach ( $data_objects as $data_object ) { 856 wp_cache_set( $data_object->id, $data_object, 'bp_invitations' ); 857 } 858 858 } 859 859 } … … 882 882 public static function get_total_count( $args ) { 883 883 global $wpdb; 884 884 885 $invites_table_name = BP_Invitation_Manager::get_table_name(); 885 886 … … 914 915 915 916 // Return the queried results. 916 return $wpdb->get_var( $sql );917 return (int) $wpdb->get_var( $sql ); 917 918 } 918 919
Note: See TracChangeset
for help on using the changeset viewer.