Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoloader cache error on WPEngine #181

Closed
frebro opened this issue May 23, 2015 · 12 comments
Closed

Autoloader cache error on WPEngine #181

frebro opened this issue May 23, 2015 · 12 comments

Comments

@frebro
Copy link

frebro commented May 23, 2015

Getting the following error when installing bedrock-autoloader.php into mu-plugins on WPEngine:

Fatal error: Cannot redeclare wp_cache_add() (previously declared in /nas/wp/www/staging/.../wp-includes/cache.php:24) in /nas/wp/www/staging/.../wp-content/mu-plugins/wpengine-common/object-cache-new.php on line 18

Looks like a conflict between autoloader and the included object-cache-new.php. I lack the skill to hunt down the exact problem, but maybe you guys could help? If it's a fixable problem I'd appreciate a patch.

@retlehs
Copy link
Member

retlehs commented May 23, 2015

how are you even using bedrock with wp engine?

@frebro
Copy link
Author

frebro commented May 23, 2015

😬

Well, I'm running Bedrock locally for development but ended up with deploying to WPEngine using a shell script. So I'm not actually using Bedrock on WPEngine, but would like to use the autoloader for some plugins.

@retlehs
Copy link
Member

retlehs commented May 23, 2015

closing since this isn't an issue with bedrock. you could try posting on our discourse, but we aren't going to provide support for running the bedrock autoloader on a non-bedrock setup.

@retlehs retlehs closed this as completed May 23, 2015
@swalkinshaw
Copy link
Member

Also there's nothing to do with wp_cache in the autoloader plugin. The autoloader will work perfectly fine on a "normal" WP server/host. WPEngine does some non-standard things to make their "magic" happen and they don't really explain too much about what's going on in that process. Something is obviously conflicting with this but that's on their end.

@frebro
Copy link
Author

frebro commented May 23, 2015

Sure! I'll take it up with their support and see if there's a fix.
Otherwise I'll work around the issue. Thanks guys.
lör 23 maj 2015 kl. 21:25 skrev Scott Walkinshaw notifications@github.com:

Also there's nothing to do with wp_cache in the autoloader plugin. The
autoloader will work perfectly fine on a "normal" WP server/host. WPEngine
does some non-standard things to make their "magic" happen and they don't
really explain too much about what's going on in that process. Something is
obviously conflicting with this but that's on their end.


Reply to this email directly or view it on GitHub
#181 (comment).

@mAAdhaTTah
Copy link

It kinda looks like the bedrock autoloader is double loading the cache plugin. I don't know WPEngine and their setup, but that's where I'd look.

@Foxaii
Copy link
Contributor

Foxaii commented May 24, 2015

Yeah, it's definitely double loading. The object cache plugin needs to live outside the mu-plugins folder, in the wp-content folder (or the app folder if you're using Bedrock) so it really shouldn't be loaded as a mu-plugin anyway.

It's easy to resolve if WP Engine wrap their code in a conditional to see if the functions already exist but there's not a fix we can easily offer.

@frebro
Copy link
Author

frebro commented May 25, 2015

Ok, thanks guys! I appreciate you took the time. This plugins is must-use and non-optional on WPEngine, so unless they do a fix the autoloader can't be used with them.

@hello-jason
Copy link

hello-jason commented Dec 29, 2016

FYI, I am no longer seeing this error message on WP Engine.

Edit: I believe I mispoke, and there is an issue on my end.

@jamiechong
Copy link

I managed to make bedrock autoloader and WPEngine work together by modifying a few files:

  1. composer.json
    • change "web/app/mu-plugins/{$name}/" to "web/app/mu-plugins/bedrock/{$name}/"
  2. bedrock-autoloader.php
    • change self::$relative_path = '/../' . basename(__DIR__); to self::$relative_path = '/../' . basename(__DIR__) . '/bedrock';
    • change all instances of WPMU_PLUGIN_DIR to WPMU_PLUGIN_DIR . '/bedrock/'

You will then need to run composer update and likely delete the plugins within mu-plugins that are leftover and now within the bedrock subfolder (they weren't auto removed for me).

I literally just got this working, so will report back if it fails, but so far so good.

@lvampa
Copy link

lvampa commented Apr 25, 2017

I too just ran into this issue with WPEngine. Since I prefer using Bedrock and Trellis for my development environment, but WPEngine is picky about structure, I set up my app directory as a submodule that I push to WPEngine for deploys.

To solve the issue, I added bedrock-autoloader.php to the .gitignore, moved the file to an archive directory, then used a composer post-install script to move the file in on a composer install.

My composer.json

"scripts": {
    "test": [
      "vendor/bin/phpcs"
    ],
    "post-install-cmd": [
      "./install.sh"
    ]
  }

and install.sh looks like

#!/usr/bin/env bash

PLUGIN_DIR=./web/app/mu-plugins
SOURCE_DIR=./archive/

# Copy bedrock plugins into correct folder
rsync -a --include='*.php' $SOURCE_DIR $PLUGIN_DIR

This solution is far from perfect, but it leverages composer, and also means I don't have to edit a core Bedrock file so if there are updates to that file in the future, it will be easier for me to pull in the changes. I can use composer to get the files I need for local development, and since they are not tracked in the mu-plugins directory, WPEngine doesn't have a problem.

@y2keeper
Copy link

I can confirm that your solution works for me too @jamiechong - with the small addition that I had to modify the default bedrock .gitignore file to have the bedrock/ dir recognised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants