s2Member + Trellis/Bedrock

I’m so happy to see you back, Cristián. You were the main support in my early days with s2 and you helped me lots over on the old forum and support requests.

I was literally just a few days form migrating to PMP when you showed up.

I could probably come up with hundreds of feature or support requests, but I want to start with this one. I use Trellis to deploy all of my sites except for the ones that use s2Member. I haven’t tested for over a year, so my memory’s foggy, but the s2 code hasn’t changed so here’s the issue.

Trellis/Bedrock move all of the core WP files to the /wp/ directory. So it’s /wp/wp-login.php, etc. That has worked fine with every other plugin except for s2Member which didn’t look for /wp/admin-ajax.php at the new location, which is sort of a problem :wink:.

I didn’t look at the code back then and didn’t now, but I’m wondering if the fix is something as simple as changing the url from something that’s hardcoded to something more dynamic.

Or maybe I missed a setting somewhere?

1 Like

It’s very good to see you, too, Ric! I’m glad I made it in time. :smiley:

Wouldn’t a redirect in .htaccess help with that?

every other plugin except for s2Member which didn’t look for /wp/admin-ajax.php at the new location

I see admin-ajax.php in the JS files for the payment gateways. E.g.

c_ws_plugin__s2member_utils_strings::esc_js_sq(admin_url("/admin-ajax.php"));

It uses WP’s admin_url for the location, so it should be giving the correct one. If it isn’t, then check your WP configuration, or ask your webhost about the output of that function. If it’s correct, then the address for adimn-ajax.php shouldn’t be wrong. https://codex.wordpress.org/Function_Reference/admin_url

I hope that helps! :slight_smile:

Thanks. It might not have been admin-ajax. Like I said, it was some time ago :slight_smile:

Trellis is a composer, ansible, and git-based Wordpress LEMP stack so maybe they had an NGINX configuration that was messing things up.

I’m firing up a Trellis vagrant dev environment now and I’ll let you know if I can recreate the concern.

1 Like

Great. Let me know. :slight_smile:

I think I found it.

I found a similar issue that was fixed here for VVV: https://github.com/wpsharks/s2member/issues/717

I tried to post an image of the JS console complaining about not being able to load the following file, but the forum will only let me post one image so you have to imagine it since the one I’m posting is more helpful :slight_smile:

Here’s the output from http://s2member.test/app/plugins/s2member/s2member-o.php?ws_plugin__s2member_js_w_globals=1&qcABC=1&ver=170722-170722-2145506620

I’d prefer to not have to disable the open_basedir restriction for security reasons

I think I solved it.

The current code travels down the directory path to find the wp directory, but never goes back up, which it would need to do to move from /app to /wp in Trellis.

It keeps going down the path until it reaches outside the open_basedir and causes an error.

It looks like the code will accept a server variable instead of traversing. (utils-s2o.inc.php line 41)

I’d much prefer not to have to set this, but it appears working for now after doing so.

To any others that want to use s2Member with Trellis, the way to set a server variable in Trellis is on this page:

You’ll want to create a child template for wordpress-site.conf.j2 so pay attention to the nginx_wordpress_site_conf subheading on that page.

I created a /trellis/nginx-includes/s2member.test.conf.child file that includes the following:

{% extends 'roles/wordpress-setup/templates/wordpress-site.conf.j2' %}

    {% block fastcgi_basic -%}
    {{ super() }}
    set $wp "/wp";
    fastcgi_param WP_DIR $realpath_root$wp;
    {%- endblock %}

It’s the fastcgi_param that sets the server variable.

My wordpress_sites.yml is the default one for my development site. All I did was change the domain name and add the last line as described in the link above.

wordpress_sites:
  s2member.test:
    site_hosts:
      - canonical: s2member.test
        redirects:
          - www.s2member.test
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    admin_email: admin@example.test
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: self-signed
    cache:
      enabled: false
    nginx_wordpress_site_conf: nginx-includes/s2member.test.conf.child

I hope this helps someone else :slight_smile:

Trellis is the best stack I’ve found for my needs, but it can get quite tech heavy.

2 Likes

Thanks for the update and sharing your solution! I’m sure it’ll help someone else in the future. :smiley: