BP_Notification_Export
Class BP_Notification_Export
Description
Source
File: bp-core/gdpr/class-bp-notification-export.php
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | final class BP_Notification_Export extends BP_Export { /** * Get the instance of this class. * * @return Controller|null */ public static function instance() { static $instance = null; if ( null === $instance ) { $instance = new BP_Notification_Export(); $instance ->setup( "bp_notification" , __( "Notifications" , 'buddyboss' ) ); } return $instance ; } /** * Export member notifications. * * @param $user * @param $page * @param bool $email_address * * @since BuddyBoss 1.0.0 * * @return array */ function process_data( $user , $page , $email_address = false ) { if ( ! $user || is_wp_error( $user ) ) { return $this ->response( array (), true ); } $export_items = array (); $data_items = $this ->get_data( $user , $page ); foreach ( $data_items [ "items" ] as $item ) { $group_id = "bp_notifications" ; $group_label = __( "Notifications" , 'buddyboss' ); $item_id = "{$this->exporter_name}-{$group_id}-{$item->id}" ; $notification = bp_notifications_get_notification( $item ->id ); $action = $this ->bp_get_the_notification_description( $notification ); $action = wp_strip_all_tags( $action ); $action = apply_filters( 'buddyboss_bp_gdpr_bp_notification_item_action' , $action , $item , $data_items ); $mark_as_read = __( 'No' , 'buddyboss' ); if ( '0' === $item ->is_new ) { $mark_as_read = __( 'Yes' , 'buddyboss' ); } $data = array ( array ( 'name' => __( 'Notification Action' , 'buddyboss' ), 'value' => $action , ), array ( 'name' => __( 'Notified Date (GMT)' , 'buddyboss' ), 'value' => $item ->date_notified, ), array ( 'name' => __( 'Mark as Read' , 'buddyboss' ), 'value' => $mark_as_read , ), ); $data = apply_filters( 'buddyboss_bp_gdpr_notification_after_data_prepare' , $data , $item , $notification , $data_items ); $export_items [] = array ( 'group_id' => $group_id , 'group_label' => $group_label , 'item_id' => $item_id , 'data' => $data , ); } $done = $data_items [ 'total' ] < $data_items [ 'offset' ]; return $this ->response( $export_items , $done ); } /** * Delete member notifications. * * @param $user * @param $page * @param bool $email_address * * @since BuddyBoss 1.0.0 * * @return array */ function process_erase( $user , $page , $email_address ) { global $wpdb ; if ( ! $user || is_wp_error( $user ) ) { return $this ->response_erase( array (), true ); } $items_removed = true; $items_retained = false; /** * Make use of buddypress default data remover. */ bp_notifications_delete_notifications_on_user_delete( $user ->ID ); $done = true; return $this ->response_erase( $items_removed , $done , array (), $items_retained ); } /** * Returns the data & count of notifications by page and user. * * @param $user * @param $page * * @since BuddyBoss 1.0.0 * * @return array */ function get_data( $user , $page ) { global $wpdb ; $wpdb ->show_errors( false ); $table = "{$wpdb->prefix}bp_notifications item" ; $query_select = "item.*" ; $query_select_count = "COUNT(item.id)" ; $query_where = "item.user_id=%d" ; $offset = ( $page - 1 ) * $this ->items_per_batch; $limit = "LIMIT {$this->items_per_batch} OFFSET {$offset}" ; $query = "SELECT {$query_select} FROM {$table} WHERE {$query_where} {$limit}" ; $query = $wpdb ->prepare( $query , $user ->ID ); $query_count = "SELECT {$query_select_count} FROM {$table} WHERE {$query_where}" ; $query_count = $wpdb ->prepare( $query_count , $user ->ID ); $count = (int) $wpdb ->get_var( $query_count ); $items = $wpdb ->get_results( $query ); return array ( 'total' => $count , 'offset' => $offset , 'items' => $items , ); } /** * Get full-text description for a specific notification. * * @param $notification * * @since BuddyBoss 1.0.0 * * @return mixed|void */ function bp_get_the_notification_description( $notification ) { $bp = buddypress(); // Callback function exists. if ( isset( $bp ->{ $notification ->component_name}->notification_callback ) && is_callable ( $bp ->{ $notification ->component_name}->notification_callback ) ) { $description = call_user_func( $bp ->{ $notification ->component_name}->notification_callback, $notification ->component_action, $notification ->item_id, $notification ->secondary_item_id, 1, 'string' , $notification ->id ); // @deprecated format_notification_function - 1.5 } elseif ( isset( $bp ->{ $notification ->component_name}->format_notification_function ) && function_exists( $bp ->{ $notification ->component_name}->format_notification_function ) ) { $description = call_user_func( $bp ->{ $notification ->component_name}->format_notification_function, $notification ->component_action, $notification ->item_id, $notification ->secondary_item_id, 1 ); // Allow non BuddyPress components to hook in. } else { /** This filter is documented in bp-notifications/bp-notifications-functions.php */ $description = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user' , array ( $notification ->component_action, $notification ->item_id, $notification ->secondary_item_id, 1, 'string' , $notification ->component_action, $notification ->component_name, $notification ->id ) ); } /** * Filters the full-text description for a specific notification. * * @since BuddyPress 1.9.0 * @since BuddyPress 2.3.0 Added the `$notification` parameter. * * @param string $description Full-text description for a specific notification. * @param object $notification Notification object. */ return apply_filters( 'bp_get_the_notification_description' , $description , $notification ); } } |
Methods
- bp_get_the_notification_description — Get full-text description for a specific notification.
- get_data — Returns the data & count of notifications by page and user.
- instance — Get the instance of this class.
- process_data — Export member notifications.
- process_erase — Delete member notifications.
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.