<?php
// Display button where the function is called
function ddisplay_mark_as_read_button() {
if (is_singular(array('member-videos', 'programme', 'challenge')) && is_user_logged_in()) {
$post_id = get_the_ID();
$user_id = get_current_user_id();
$read_posts = (array) get_user_meta($user_id, 'read_posts', true);
$button_text = in_array($post_id, $read_posts) ? 'Workout Completed ✅' : 'Mark as Completed';
$button_markup = '<button class="mark-as-read-button" data-post-id="' . $post_id . '">' . $button_text . '</button>';
echo $button_markup; // Echoing directly within the function
}
}
// Call the function
ddisplay_mark_as_read_button();
?>