Skip to content

Instantly share code, notes, and snippets.

@mahfelwp
Last active September 30, 2020 14:33
Show Gist options
  • Save mahfelwp/6d5c985816a510c4cc171e9667d1e57d to your computer and use it in GitHub Desktop.
Save mahfelwp/6d5c985816a510c4cc171e9667d1e57d to your computer and use it in GitHub Desktop.
DELETE NEW AVATAR FROM MEDIA AND ACTIVITY TABLE
<?php
function get_all_activity_ids_type_is_new_avatar(){
global $wpdb, $bp;
// Prepare Sql
$sql = $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = %s AND component = '%s'", 'new_avatar' , 'profile' );
// Get Result
$result = $wpdb->get_results( $sql , ARRAY_A );
$result = wp_list_pluck( $result, 'id' );
return $result;
}
function delete_new_avatar_from_media_and_activity_table(){
global $wpdb, $bp, $Yz_media_table;
$ids = get_all_activity_ids_type_is_new_avatar();
if ( is_array( $ids ) ) {
$ids = implode( ',', array_map( 'absint', $ids ) );
}
// Delete Data From Media Table
$wpdb->query( "DELETE FROM $Yz_media_table where item_id IN ( $ids )" );
// Delete Data From Activity Table
$wpdb->query( "DELETE FROM {$bp->activity->table_name} where id IN ( $ids )" );
}
function excute_delete_new_avatar(){
if( get_all_activity_ids_type_is_new_avatar() ){
add_action('bp_actions','delete_new_avatar_from_media_and_activity_table');
}
}
add_action('bp_init','excute_delete_new_avatar');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment