I got it:
function custom_get_count_before_delete() {
global $bp, $wpdb;
$user_id = $bp->loggedin_user->id;
return $wpdb->get_var( $wpdb->prepare( "
SELECT COUNT(DISTINCT p.ID)
FROM $wpdb->posts p
WHERE p.post_author = %d
AND p.post_status="inherit"
AND p.post_type="attachment"", $user_id
) );
}
function custom_check_delete_account() {
global $bp;
if ( $bp->current_component == 'settings' && $bp->current_action == 'delete-account' ) {
if ( $count = custom_get_count_before_delete() ) {
$message="please_delete_your_media_before_delete_your_account";
wp_redirect('http://www.mysite.lh/wp-admin/upload.php?message=" . $message, 301 );
exit;
}
}
}
add_action("init', 'custom_check_delete_account', 11);
function custom_upload_notice() {
echo '<div id="message" class="updated below-h2">
<h2>Primer paso:</h2><p>Para borrar su cuenta, por favor borre todos sus Chaines primero.</p>
</div>';
remove_action('admin_notices', 'custom_upload_notice');
}
function custom_check_delete_account_upload() {
global $pagenow;
if ( !isset($_REQUEST['deleted']) ) {
if ( 'please_delete_your_media_before_delete_your_account' == $_REQUEST['message'] && 'upload.php' == $pagenow ) {
add_action('admin_notices', 'custom_upload_notice');
}
}
}
add_action('admin_init', 'custom_check_delete_account_upload', 11);
Please let me know what you think or if there exist a better way to do it.