Simple Machines Community Forum

Customizing SMF => Bridges and Integrations => Topic started by: palmdoc on October 14, 2018, 08:03:30 AM

Title: Restrict certain Wordpress pages only to logged in SMF users
Post by: palmdoc on October 14, 2018, 08:03:30 AM
Greetings awesome SMF gurus

I am quite new to SMF and have been getting very giddy trying to read up on this topic.
I am not looking for a bridge login integration between Wordpress and SMF as I want my user base to be only registered in SMF

Basically what I require is that only certain pages in my Wordpress site are restricted to logged in SMF users.
SMF is in a /forum subdirectory of the same domain where Wordpress is installed

If I use SSI.php how does one use it when loading only certain pages?
Do please help a noob with a step by step guide


Where does one put this code?

<?php
if ($context['user']['is_guest'])
{
ssi_login();
}
else
{
ssi_logout();
}
?>



How does one do it only for specific pages?

Thank you in advance.

I am not sure which thread is relevant but I'm pasting some here for my reference
http://www.simplemachines.org/community/index.php?topic=12936.0
https://www.simplemachines.org/community/index.php?topic=387713.0
https://wiki.simplemachines.org/smf/How_to_use_the_SMF_user_system_outside_of_SMF
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: Arantor on October 14, 2018, 08:23:54 AM
You basically can't without rewriting SSI, it just doesn't play nice inside WordPress, never has, probably never will... but like SMF, WodPress funnels everything into one place, you can't just edit individual files to adjust individual pages :(
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: Kindred on October 14, 2018, 08:31:39 AM
Well, there is logic within WordPress to factor the page
In my wordpress installation, I use it to display a widget only on the classifieds page.

In theory, you could do it within a widget...

However, the point about SSI not playing well inside WordPress is still a factor
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: palmdoc on October 14, 2018, 09:37:14 AM
So it wouldn't be any good if I put

<?php require("/home/xxxx/public_html/xxxxx/forum/SSI.php");?>

right at the start of wp-load.php

and

<?php
if ($context['user']['is_guest'])
{
ssi_login();
}
else
{
ssi_logout();
}
?>


in a specific page?
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: Arantor on October 14, 2018, 10:10:02 AM
Not really, no, because every single post (and page) still flows back under the hood to index.php, meaning that doing so becomes all or nothing, rather than page by page.
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: palmdoc on October 14, 2018, 10:12:09 AM
Quote from: Kindred on October 14, 2018, 08:31:39 AM
Well, there is logic within WordPress to factor the page
In my wordpress installation, I use it to display a widget only on the classifieds page.

In theory, you could do it within a widget...

However, the point about SSI not playing well inside WordPress is still a factor

How is that done?
Thanks
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: Arantor on October 14, 2018, 10:17:48 AM
Doing it as a widget doesn't hide the rest of the page...
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: palmdoc on October 14, 2018, 03:33:24 PM
OK basically I don't want someone coming to a specific page on my Wordpress site without login to SMF first.

So I tried this workaround

1) Install ASPS Check Referer  plugin
http://www.artistscope.com/asps_check_referrer.asp
protect the page URL with referer only from my domain

2) Link to the page using PHP

<?php require("/home/xxx/public_html/xxx/forum/SSI.php");?>
<?php
if ($context['user']['is_guest'])
{
header("HTTP/1.1 301 Redirecting");
header("Location:https://xxx/forum/index.php?action=login
"
);

}
else
{
header("HTTP/1.1 301 Redirecting");
header("Location:https:/xxx/test-page/");
exit();
}
?>


So if one goes directly to https:/xxx//test-page/ or linked from some other domain, it will present a Direct Access not permitted
Only thing is how to pass the Referer from the PHP redirect
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: Arantor on October 14, 2018, 06:14:33 PM
Given that plenty of security software, and browsers going forward, often don't reveal the referer, and that it's utterly unreliable since it's not hard to spoof it anyway...

Honestly, this is a huge problem, mostly because WordPress has no concept of restricted posts beyond future/draft posts, and the only way to really fix this is a really dirty change inside the Loop (which will be removed next update!), or not putting that content inside WordPress and instead putting it in SMF with one of the mods that can add pages. Or even SSI powered pages, nothing says that content has to actually be in WordPress and if you genuinely need it restricted.
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: drewactual on October 16, 2018, 09:50:08 AM
one way to pull it off is to use php include of a file that has the WP output you want to share to users, but also requires users to be logged using SMF logic... it becomes an If/Then situation, and uses call to whatever specific WP category posts from 'outside the loop'...

Using CSS file in both WP and SMF, you can display:none the div the WP post shows up in a specific category, only to inline css the same div on the php included file and showing it if users pass the 'user' challenge (they're logged in). 

it's a slippery slope to use trickery, but if you're in a pinch.....
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: Kindred on October 16, 2018, 01:48:57 PM
except, IIRC, there are actually some collisions between SMF and WordPress variable names
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: drewactual on October 16, 2018, 05:26:02 PM
As sloppy as WP is, I've little problems doing what ive described less using css as a controller whether someone (user/guest) sees it.... Thats the tricky part, but I see no reason it wont work so long as the css that reveals it is inline. There are many different ways to get stuff out of WP outside the loop, and so long as those items are presented (appearingly) inside SMF via pho includes and not hard coded into it, it's not bothered my page at all.
Title: Re: Restrict certain Wordpress pages only to logged in SMF users
Post by: palmdoc on October 30, 2018, 06:43:10 PM
Quote from: drewactual on October 16, 2018, 09:50:08 AM
one way to pull it off is to use php include of a file that has the WP output you want to share to users, but also requires users to be logged using SMF logic... it becomes an If/Then situation, and uses call to whatever specific WP category posts from 'outside the loop'...

Using CSS file in both WP and SMF, you can display:none the div the WP post shows up in a specific category, only to inline css the same div on the php included file and showing it if users pass the 'user' challenge (they're logged in). 

it's a slippery slope to use trickery, but if you're in a pinch.....

Some example code for a noob would be much appreciated  8)