Advertisement:

Author Topic: Restrict certain Wordpress pages only to logged in SMF users  (Read 5669 times)

Offline palmdoc

  • Semi-Newbie
  • *
  • Posts: 22
Restrict certain Wordpress pages only to logged in SMF users
« 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?

Code: [Select]
<?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
« Last Edit: October 14, 2018, 09:02:42 AM by palmdoc »

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,458
    • StoryBB/StoryBB on GitHub
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #1 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 :(
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 57,224
  • Gender: Male
    • Kindred-999 on GitHub
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #2 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
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline palmdoc

  • Semi-Newbie
  • *
  • Posts: 22
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #3 on: October 14, 2018, 09:37:14 AM »
So it wouldn't be any good if I put

Code: [Select]
<?php require("/home/xxxx/public_html/xxxxx/forum/SSI.php");?>
right at the start of wp-load.php

and

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

in a specific page?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,458
    • StoryBB/StoryBB on GitHub
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #4 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline palmdoc

  • Semi-Newbie
  • *
  • Posts: 22
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #5 on: October 14, 2018, 10:12:09 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

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,458
    • StoryBB/StoryBB on GitHub
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #6 on: October 14, 2018, 10:17:48 AM »
Doing it as a widget doesn’t hide the rest of the page...
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline palmdoc

  • Semi-Newbie
  • *
  • Posts: 22
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #7 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 [nofollow]
protect the page URL with referer only from my domain

2) Link to the page using PHP

Code: [Select]
<?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
 
« Last Edit: October 14, 2018, 04:14:53 PM by palmdoc »

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,458
    • StoryBB/StoryBB on GitHub
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #8 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline drewactual

  • Jr. Member
  • **
  • Posts: 340
    • College Football Fan Site CFB51
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #9 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.....
https://www.cfb51.com is a College Football Fan Site, Store, and Publisher, launched in July of 2017

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 57,224
  • Gender: Male
    • Kindred-999 on GitHub
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #10 on: October 16, 2018, 01:48:57 PM »
except, IIRC, there are actually some collisions between SMF and WordPress variable names
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline drewactual

  • Jr. Member
  • **
  • Posts: 340
    • College Football Fan Site CFB51
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #11 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.
https://www.cfb51.com is a College Football Fan Site, Store, and Publisher, launched in July of 2017

Offline palmdoc

  • Semi-Newbie
  • *
  • Posts: 22
Re: Restrict certain Wordpress pages only to logged in SMF users
« Reply #12 on: October 30, 2018, 06:43:10 PM »
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)