Og:url causing issues with Facebook sharing for Private Group

I’m trying to set up social sharing on my site and am having problems with Facebook. Rather than linking to my home page, the og:url is being set to ‘my-membership-options-page’. I am building a free members site for our volunteers and will shortly purchase the paid version to enable me to use the sign-up forms. I want everyone to add content to the website and then use other communication methods to share the post, a prime one being our Private Facebook Group. I therefore don’t want them to be redirected from there to the my-membership-options-page I want them to be redirected to the login page. Is this possible?

Try the code I suggested in this thread.

I’ve created the mu-plugins folder and uploaded the file, I added the php code at the top and changed the link to /wp-login.php. However, when I click on the link I’m getting a page not found error. The link is showing as ‘http://newsite.axescouts.org.uk/0php’?login_redirect_uri=%2F2016%2F06%2F05%2Fcubjam-100%2F’ Cubjam 100 is the post. I get the same using a link in an email and from Facebook. This really is a showstopper, I need to be able to send links to our members to restricted posts by email (currently using mailpoet), by Facebook or possibly even text message. If they aren’t logged in it should present them with the login page and then take them to the post they were trying to view.

Nigel, please don’t write things like showstopper. This is not Pro support. We are just fellow users of WebSharks plugins. We have jobs and lives too.

The reason you’re getting the redirect is that you are apparently trying to access the following URL:
http://newsite.axescouts.org.uk/0/2016/06/05/cubjam-100

I’m guessing you don’t want the 0/ in the URL. That’s nothing to do with s2Member. For whatever reason, something on your site is adding that and so creating URLs that don’t exist.

Tim, please accept my apologies, I incorrectly thought the forum was run by the authors and this is almost the last blocker to me purchasing the pro version or looking for an alternative solution if I can’t find a way to get it working. I am not an expert at all I really do appreciate the help you’re giving me, even more so now.

I don’t experience the issue with:

  1. un-restricted posts, links in both emails and Facebook work
  2. if already logged in, again links in both emails and Facebook work

So it only appears to be an issue where s2Member is changing the link and the user is not logged in, it could be my inexperience but I’m struggling to understand where else to look as logically it points to s2Member being the culprit in some way.

That’s OK, Nigel! Occasionally, Pat D from Pro support drops in, but that depends on how busy she is. (The site is run by the devs, but as a community forum.)

s2Member doesn’t change any URLs at all, so I very much doubt it’s the cause of this problem. The reason the problem doesn’t manifest itself if you stay logged in or logged out is that WordPress uses some quite sophisticated rewrite rules to try to stop posts getting “lost” as URLs get changed or messed up.

But when you try to go from logged out to logged in, you are changing the nature of the game. URLs can’t just be re-written then because that would be a major security risk.

So I’m pretty sure that your problem isn’t s2Member, but stems from something else on your site. For example, have you or your host added anything to your .htaccess file? Do you have a security plugin running? Have you set up some redirects (especially if using a regex)? Have you imported your content from somewhere else?

I’m guessing at the cause here, but it’s something like that. If you can’t identify it, try just deactivating all your other plugins and see if it works then.

I’m getting there! I’m using textedit on a mac to edit the files and it is automatically converting quote marks from ’ to this ‘ which was causing an error when the hack was run!

I am now correctly being presented with the login page when I use either the Facebook link or the mailpoet email link. The login link is appearing as:

http://newsite.axescouts.org.uk/wp-login.php?login_redirect_uri=%2F2016%2F06%2F05%2Fcubjam-100%2F

However, when I login as a user it’s taking me to the login welcome page set up in s2Member rather than the page I was trying to view. Any other ideas to get the next bit working so it takes me to the page I’m trying to view?

Thanks

Good to hear you identified the cause of your original problem!

s2Member is giving you the correct login link. So my guess is that you have a theme or plugin conflict that is interfering with the redirect after you login. Are you running any caching or security plugins, or anything else that relates to logging in.

I don’t believe I’m running any caching plugins. Security wise I have s2Member and Nav Menu Roles. I was using ultimate member but that is deactivated; full list below…assuming deactivated plugins have no impact. I did try with all my plugins, except s2Member deactivated but I still get the same result. Am I looking for something that is stripping out the redirect after login but before it gets to the s2Member redirect to the welcome page? Inexperienced user question…is it possible to debug what’s happening and follow the code through? This is a sub domain, could that have any impact. I’ve paired back the htaccess files so they have the basic wordpress code and the subdomain also has the s2Member code. I’ve also checked the documentation for the theme and can’t see any reference in there to login http://guide.dream-theme.com/the7/. I’ve tried to search the code for functions that could cause the issue but I’m not sure what I’m looking for.

Plugins Loaded on the site

  • Add Meta Tags
  • Akismet
  • Calendarize it! for Wordpress
    * ClientDash – Deactivated
  • Contact Form 7
    * ConvertPlug – Deactivated
    * Display Posts Shortcode – Deactivated
    * Eyes Only: User Access Shortcode – Deactivated
  • Go Pricing – WordPress Responsive Pricing Tables
    * LayerSlider WP – Deactivated
  • MailPoet Newsletters
    * Multiple Roles – Deactivated
  • Nav Menu Roles
    * Recent Tweets Widget – Deactivated
  • Responsieve Styled Google Maps
    * Restrict Categories – Deactivated
  • s2Member Framework
  • Slider Revolution
  • Table Maker
  • Ultimate Addons for Visual Composer
  • Ultimate Member – Deactivated
  • User Role Editor
  • WooCommerce
  • WP Job Manager
  • WP Job Manager – Job Type Colours
  • WP Bakery Visual Composer

Inexperienced user question…is it possible to debug what’s happening and follow the code through?

No idea: you’d need to ask a proper developer that!

The fact that the site is on a subdomain should make no difference. I have a copy of the7 theme myself, and I haven’t found problems with logins, so I think we can rule that out.

The plugin in your list that I’d look at first would be Visual Composer (and its add-ons). It doesn’t play well with s2Member. I’d also check Eyes Only. I know it’s deactivated, but for some plugins that might not be enough.

After that, I’d check your WooCommerce settings and then WP Job Manager and Slider Revolution (the last one because it’s had some major security problems, and they might have reacted by adding something that’s now causing a problem).

Hmm, I’ve just had another thought. Try adding this after the other code in your s2-hacks.php file in your mu-plugins folder:

function s2_redirect($redirect, $vars = array()) {
    if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) {
        $redirect = $_SERVER['HTTP_REFERER'];
        return $redirect;
    }
}
add_filter("ws_plugin__s2member_login_redirect", "s2_redirect", 10, 2); 

Thanks Tim, I’ve added it but still same issue. I’ve assumed I add it on the next line after the ; Will start working through the list in your other reply. Thanks for sticking with me whilst I try and find this.

Hi, so out of curiosity I have create a new sub-domain and loaded a copy of wordpress. Using the default theme I have added the s2Member plugin, added the welcome page and the options page. Added a post and secured it at level 2. Created a user account with level 2 access. Added the original hack to the mu-plugins folder. Logged out and tried to access the secure post, it takes me the login page and shows the correct redirect (in the same way as you confirmed above). I log in with the level 2 user account and it takes me to the welcome page NOT the post…same behaviour as the other site. Which leads me to believe it’s not the plugins as this is a completely clean install with only s2Member added. Any other ideas, I’m completely lost now.

So are you saying that the redirect works for an admin but not an s2Member role, or are you saying that it works first time for an s2Member role, but not the second time?

Just re-read: misunderstood it the first time!

I have several sites where this all works 100%. So my next question is who is your host?

We’re with Krystal, not sure what level but paid for and we have unlimited bandwidth, space etc

Hmm, I’ve never heard of them. I think you need to ask whether they have something set up that could be causing this problem.

Okay will do. It’s a UK hosting company, I’m in South West England. I’ve installed wordpress using their automatic installation, wondering if I should try doing it manually too. Is it only the .htaccess file that deals with redirects, could they be somewhere else in the current main domain? I wasn’t involved in the main site at all but it isn’t great hence me trying to build a simpler site to replace it.

I doubt that the method of installation matters, but I don’t know. The .htaccess rules on the main site may also affect a subdomain, but your host might also have something set up outside of WordPress altogether.

@Nige7119: Better install WP manually, even the host have a tool for that - sometimes hosts support old versions, or shorted/hacked versions, or add some tools/plugins, which cause problems. So if possible - reinstall your site manually.