Support

Account

Home Forums Reply To:

  • Hey guys,

    I would like to use ACF to show whether or not a user with the role ‘advisor’ is online. As of now I have a true/false field set up (inside a group) and I can manually switch between the different statuses for each user and see the update reflected on the frontend. However I would like this to function automatically, and this is where I’m lost.

    This is the function I have produced so far – but it’s not working.

    add_action('wp_loaded', 'itc_assign_advisor_online_status');
    
    function itc_assign_advisor_online_status() {
    	$online_status = get_field('onlinestatus');
    
    	if (is_user_logged_in() && ! current_user_can( 'administrator' )) {
    		$online_status['is_online'] = 1;
    	} else {
    		update_field($online_status['is_online'], 0);
    	}
    }

    Am I using the wrong hook, maybe?

    For the record, this is my graphical interface code:

    <?php
    
    $online_status = get_field('onlinestatus');
    $green_status = 'online';
    $yellow_fill_status = 'busy--filled';
    $red_fill_status = 'offline--filled';
    $yellow_border_status = 'busy';
    $red_border_status = 'offline';
    
            if ($online_status) { ?>
              <div class="card__btn-block">
                <a href="#" class="btn rounded <?php
                  if ($online_status['is_online']) {
                    echo $green_status;
                  }
                  if ($online_status['is_busy']) {
                    echo $yellow_border_status;
                  }
                  if ($online_status['is_offline']) {
                    echo $red_border_status;
                  } ?>"><?php
                  if ($online_status['is_online']) {
                    echo 'Available';
                  }
                  if ($online_status['is_busy']) {
                    echo 'Busy';
                  }
                  if ($online_status['is_offline']) {
                    echo 'Offline';
                  }
                  ?></a>
              </div>
            <?php } ?>

    Any help is highly appreciated!