htmlburger / carbon-fields

WordPress Custom Fields Library ✨
https://carbonfields.net/
Other
1.37k stars 245 forks source link

carbon-fields.php relies on WP functions #114

Closed EmilEriksen closed 7 years ago

EmilEriksen commented 7 years ago

Since carbon-fields.php is included in files in composer.json carbon-fields.php is immediately loaded when the Composer autoloader is included. This causes issues with setups such as Bedrock where autoload.php is included before WP is booted. Right now it causes a fatal undefined function (trailingslashit()) error.

m1r0 commented 7 years ago

Good point, I agree that the initialization should be looked into and if possible moved to a hook maybe.

chrisgherbert commented 7 years ago

This is a pretty major issue for anyone using Bedrock. Using the wpackagist version works, but you have to manually set it as an mu-plugin to prevent a client/user from deactivating the plugin. I'd rather get it straight from the repo anyway.

nlemoine commented 7 years ago

@chrisgherbert This is where https://github.com/lkwdwrd/wp-muplugin-loader comes handy ;)

atanas-dev commented 7 years ago

Just wanted to give you guys a heads-up that we have our first version of the refactored initialization process in one of our dev branches which resolves issues such as incompatibility with Bedrock. I will update this thread once it gets merged.

romulodl commented 7 years ago

Hello,

Any estimation on the release of this fix? Very very very looking forward to put carbon (and get rid of ACF) in our wordpress installation :)

EmilEriksen commented 7 years ago

After experiencing some issues with other plugins and giving it some consideration I'm beginning to think this is more of an issue with Bedrock rather than Carbon Fields. I posted an issue about it in the Bedrock repo. Would love to hear some opinions! https://github.com/roots/bedrock/issues/310

bjoernhasse commented 7 years ago

From my point of view this is not an issue with bedrock and should rather be fixed within Carbon Fields. The usage of the "autoload files" function prevents many use cases. For example currently its not possible to call phpunit from the "vendor/bin" directory, because phpunit internally calls composer autoload, which breaks because of Carbon Fields. This is not the way it should be.

atanas-dev commented 7 years ago

Just an FYI for 2.0, autoload files have already been removed in favor of a manual method to initialize Carbon Fields which resolves the entire problem and gives more control over when Carbon Fields initialize.

The new method will be something similar to this:

add_action( 'after_setup_theme', 'load_carbon_fields' );
function load_carbon_fields() {
    Carbon_Fields\App::boot();
}

* Class/method names not finalized

EmilEriksen commented 7 years ago

@bjoernhasse That's a great point. I'm convinced. @kalenjohnson also posted a good explanation on the Bedrock issue I opened.

@atanas-angelov-dev Looks good!

atanas-dev commented 7 years ago

2.0.0 has been released which resolves this issue. More info on how to boot the new version here: https://carbonfields.net/docs/carbon-fields-quickstart/?crb_version=2-0-0