Ticket #8637: 8637.diff
File 8637.diff, 4.3 KB (added by , 22 months ago) |
---|
-
src/bp-notifications/bp-notifications-cache.php
diff --git src/bp-notifications/bp-notifications-cache.php src/bp-notifications/bp-notifications-cache.php index f948daef3..4ab0ca5d7 100644
function bp_notifications_clear_all_for_user_cache_before_update( $update_args, 104 104 } 105 105 } 106 106 add_action( 'bp_notification_before_update', 'bp_notifications_clear_all_for_user_cache_before_update', 10, 2 ); 107 108 /** 109 * Invalidate the 'all_for_user_' cache when deleting notifications by id list. 110 * 111 * @since 10.1.0 112 * 113 * @param string $field The name of the db field of the items to delete. 114 * Possible values are `id` or `item_id`. 115 * @param int[] $items The list of items to delete. 116 * @param array $args The WHERE arguments to use to specify the item IDs to delete. 117 */ 118 function bp_notifications_clear_all_for_user_cache_before_delete_by_id_list( $field, $items, $args ) { 119 $args[ $field ] = $items; 120 121 $notifications = BP_Notifications_Notification::get( $args ); 122 $user_ids = wp_parse_id_list( wp_list_pluck( $notifications, 'user_id' ) ); 123 124 foreach ( $user_ids as $user_id ) { 125 bp_notifications_clear_all_for_user_cache( $user_id ); 126 } 127 } 128 add_action( 'bp_notification_before_delete_by_id_list', 'bp_notifications_clear_all_for_user_cache_before_delete_by_id_list', 10, 3 ); 129 130 /** 131 * Invalidate the 'all_for_user_' cache when updating notifications by id list. 132 * 133 * @since 10.1.0 134 * 135 * @param string $field The name of the db field of the items to update. 136 * Possible values are `id` or `item_id`. 137 * @param int[] $items The list of items to update. 138 * @param array $data Array of notification data to update. 139 * @param array $where The WHERE params to use to specify the item IDs to update. 140 */ 141 function bp_notifications_clear_all_for_user_cache_before_update_id_list( $field, $items, $data, $where ) { 142 $where[ $field ] = $items; 143 144 $notifications = BP_Notifications_Notification::get( $where ); 145 $user_ids = wp_parse_id_list( wp_list_pluck( $notifications, 'user_id' ) ); 146 147 foreach ( $user_ids as $user_id ) { 148 bp_notifications_clear_all_for_user_cache( $user_id ); 149 } 150 } 151 add_action( 'bp_notification_before_update_id_list', 'bp_notifications_clear_all_for_user_cache_before_update_id_list', 10, 4 ); -
src/bp-notifications/classes/class-bp-notifications-notification.php
diff --git src/bp-notifications/classes/class-bp-notifications-notification.php src/bp-notifications/classes/class-bp-notifications-notification.php index 9d5c1ebae..1bfc40555 100644
class BP_Notifications_Notification { 941 941 $values[] = $value; 942 942 } 943 943 944 foreach ( $where_args['data'] as $ field => $value ) {945 $index = array_search( $ field, array_keys( $where_args['data'] ) );944 foreach ( $where_args['data'] as $where_field => $value ) { 945 $index = array_search( $where_field, array_keys( $where_args['data'] ) ); 946 946 $format = $where_args['format'][ $index ]; 947 947 948 $conditions[] = "{$ field} = {$format}";948 $conditions[] = "{$where_field} = {$format}"; 949 949 $values[] = $value; 950 950 } 951 951 … … class BP_Notifications_Notification { 955 955 /** This action is documented in bp-notifications/classes/class-bp-notifications-notification.php */ 956 956 do_action( 'bp_notification_before_update', $update_args, $where_args ); 957 957 958 /** This action is documented in bp-notifications/classes/class-bp-notifications-notification.php */ 959 do_action( 'bp_notification_before_update_id_list', $field, $items, $data, $where, $update_args, $where_args ); 960 958 961 return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->notifications->table_name} SET {$fields} WHERE {$conditions}", $values ) ); 959 962 } 960 963 … … class BP_Notifications_Notification { 1034 1037 /** This action is documented in bp-notifications/classes/class-bp-notifications-notification.php */ 1035 1038 do_action( 'bp_notification_before_delete', $args ); 1036 1039 1040 /** This action is documented in bp-notifications/classes/class-bp-notifications-notification.php */ 1041 do_action( 'bp_notification_before_delete_by_id_list', $field, $items, $args ); 1042 1037 1043 if ( ! $values ) { 1038 1044 return $wpdb->query( "DELETE FROM {$bp->notifications->table_name} WHERE {$conditions}" ); 1039 1045 }