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!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.