Checking if can access post – help requested
-
I am using UAM to restrict access to some bbPress forums to only logged-on users.
I send an email notification of new topics or replies, which includes a link to the topic or reply. Snag is, if the user follows the link to a restricted topic when they are not logged on, they get a 404 (correctly). I want, instead, to invite them to log in and then send them on to the topic.I have the following code:
function ovni_force_login() { // force login if trying to access something requiring user to be logged in. global $post; echo 'Posts: $post ID ' . $post->ID . ' Type: ' . $post->post_type . ' access: ' . checkObjectAccess($post->post_type, $post->ID); return; // just during debug if (!is_user_logged_in() && checkObjectAccess($post->post_type, $post->ID)){ auth_redirect(); // invites login and then takes them to the page } } add_action('get_header', 'ovni_force_login');
The echo statement is for debugging. Before I added the checkObjectAccess bit, it was displaying the post ID and post type correctly, for the page I am landing on.
I have now added the call to checkObjectAccess, which is a public function within UAM, in an attempt to check whether the page is accessible. If user is not logged in and the page is not accessible, I would use auth_direct() to get them to log on and then take them to the page.
This code gives Fatal error: Call to undefined function checkObjectAccess().
My research suggests I may need to call this as a method of an object?
$this->checkObjectAccess() or some such. But I am not up to speed on OOP and classes.Can SKS help me out here please? I think I am close to a solution to my problem after days of working on it. Thanks.
- The topic ‘Checking if can access post – help requested’ is closed to new replies.