s2member icon indicating copy to clipboard operation
s2member copied to clipboard

s2Member unable to locate WordPress directory when WP in own directory

Open ethanclevenger91 opened this issue 4 years ago • 5 comments

EXPLANATION OF THE ISSUE

When WordPress is installed in its own directory, the wp_dir static function can't find it and the title error is thrown for assets like plugins/s2member/s2member-o.php?ws_plugin__s2member_js_w_globals=1&qcABC=1&ver=191022-3535278483.

Similar to #717, but without symlinks.

Most similar to this legacy forum issue which never got an actual fix.

STEPS TO REPRODUCE THE ISSUE

  1. Setup WordPress using a framework like Bedrock or otherwise move wp-content out from under the wp core directory.
  2. Install s2Member
  3. Configure and navigate to a page that will load the above JS
  4. See console error about MIME types for that script (in Firefox)
  5. Open script URL for title error message.

BEHAVIOR THAT I EXPECTED

Scripts load successfully

PROPOSED SOLUTIONS

  • Use the ABSPATH constant that should already be defined
  • Add a filter to the result of the wp_dir function so we can point the plugin in the right direction.

ethanclevenger91 avatar Nov 20 '19 17:11 ethanclevenger91

I think your issue is solved by now but I've seen the question more often.

I think your issue (and that of others) can be fixed by saving the code below to a file name s2-hacks.php and save it to the mu-plugins folder.

function s2_hacks() {
    $GLOBALS[ 'WS_PLUGIN__' ][ 's2member' ][ 'c' ][ 's2o_url' ] = site_url( '/' );
}
add_action( 'ws_plugin__s2member_after_loaded', 's2_hacks' );

Some more info about S2 MU plugins here.

Beee4life avatar May 09 '20 18:05 Beee4life

I think this is the issue causing errors on an installation I have. I migrated a site to Flywheel for hosting and now when I try to register a user with one of the S2 member types, it gives an error, "Error submitting form! Please make sure both javascript and cookies are enabled in your browser. Use the back button to try again...

(Note: if this still doesn't help, then refreshing your cache might)"

Flywheel tech support said they believe it is because on their servers the WordPress files aren't in the standard file location. The absolute path is /www/wp-content/plugins/s2member.

Have others come across this? If so, do you have a fix?

danbwhiting avatar Aug 06 '22 14:08 danbwhiting

IMHO: The first fix would be, ditch Flywheel. I've experienced their hosting with a company I used to work for and I've never seen a more horrible host.

If you run a multisite, I might have a solution, but not sure... If so add this to wp-config.php

Config::define('ADMIN_COOKIE_PATH', '/');
Config::define('COOKIE_DOMAIN', '');
Config::define('COOKIEPATH', '');
Config::define('SITECOOKIEPATH', '');

Beee4life avatar Aug 07 '22 18:08 Beee4life

Thanks @Beee4life. It is just a single site.

For the record, it turned out it to be the Anti-Captcha plugin causing the error.

danbwhiting avatar Aug 08 '22 15:08 danbwhiting

The fix listed above (the mu-plugin) didn't work for us. I don't think it worked because s2member-o.php is dying because it can't load wordpress core. If it can't load wp core then it can't load a mu-plugin either. Within s2member-o.php it loads a helper class utils-s2o.inc.php, and within that file a $_SERVER['WP_DIR'] var is checked for the path to WP.

A fix that worked for us was to setup this variable with the correct path in an .htaccess using SetEnv:

SetEnv WP_DIR /home/username/www/path/to/wp

Of course you need the apache module mod_env installed for this to work.

2gen avatar Aug 22 '22 20:08 2gen