Buddypress函数is_user_logged_in()注销用户

I need to edit a field in buddypress profile and i kind of found a way to do it (the field is updated every time i run the code). But i put the code in bp-custom.php and every time I let this file on the hosting, the code logs out users.

<?php

  function is_user_logged_in() {

    $current_user = wp_get_current_user();

    $date = '2018/08/01';

    xprofile_set_field_data('292', $current_user->ID,  $date);
  }
?>

I can't find something wrong with this code, but also, i don't know php very well..

is_user_logged_in() is already a WordPress function, so you wouldn't be able to redefine that for your own use. Try renaming your function to make it unique to you, eg tavi_is_user_logged_in.

Thank you @Peter HvD, I finally understood about 'hooking' and i made this (it works fine):

add_action('loop_start', 'my_function');
function my_function() {
  if (is_user_logged_in()) {
    echo 'logged in';
  } else {
    echo 'not logged in';   
}
}

The problem was I used add_action(init, 'my_function'); when i tried this way, didn't know that I have to change 'init' to something.

As for what the question was about, you already gave the answer. Thank you!