Please as I can integrate in my theme without composer so you can create custom fields without having to activate the plug in thanks.
Carbon Fields 2.0 can only be installed/setup using composer at this time.
This is what I have, if it helps anyone. I haven't used it yet in a custom theme (I use Xbox for that because it has eye candy, though not nearly as actively developed as CF - it's also not free, has Draconian licensing, and other digressions), but I use Carbon Fields _all the time_ for custom plugins that I create for clients. I love it.
"require": {
"php": ">=5.3.2",
"mnsami/composer-custom-directory-installer": "~1.1.0",
"htmlburger/carbon-fields": "~2.0.1",
"composer/installers": "^1.3.0"
},
"extra": {
"installer-paths": {
"./vendor/htmlburger/carbon-fields": ["htmlburger/carbon-fields"]
}
}
mnsami/composer-custom-directory-installer puts it in ./vendor/htmlburger/carbon-fields rather than ./wp-content/plugins/... or whatever.
Don't forget that CF 2.0 apparently requires that you \Carbon_Fields\Carbon_Fields::boot(); now if loaded via PSR-4.
If you embed CF in a plugin, you're going to want to version check CF. Say, for example, that your theme/plugin uses CF 2.0.1 but either an older version of the CF plugin loaded (for example, 1.5 or 1.6) or some other plugin has an older version embedded. WordPress will fail spectacularly when the newer classes are initialized. Then you have to rename the plugin folder because you can no longer disable it via WP Admin. That is unpleasant.
This probably has typos, and obviously some of it doesn't make sense. I just threw it together.
if($this->verify_dependencies(['carbon_fields' => '2.0.0'])) {
// Execute my super-awesome plugin logic
}
...
private function verify_dependencies( $deps ) {
// Check if outdated version of Carbon Fields loaded
$error = false;
if(!defined('\\Carbon_Fields\\VERSION')) {
$error = '<strong>' . self::$settings['data']['Name'] . ':</strong> ' . __('A fatal error occurred while trying to load dependencies.');
} else if( version_compare( \Carbon_Fields\VERSION, $deps['carbon_fields'], '<' ) ) {
$error = '<strong>' . self::$settings['data']['Name'] . ':</strong> ' . __('Danger, Will Robinson! An outdated version of Carbon Fields has been loaded: ' . \Carbon_Fields\VERSION) . ' (>= ' . $deps['carbon_fields'] . ' ' . __('required') . ')';
}
if($error) Utils::show_notice($error, 'error', false);
return !$error;
}
If your plugin/theme is checked into git (why wouldn't be?), I usually add this so that it doesn't mess with my soul:
"scripts": {
"pre-autoload-dump": [
"find ./vendor -name '.git*' -exec rm -rf {} +"
]
}
Not ideal because Composer will complain every time you update, but if someone else has a better solution, HMU!
Pro-tip: Never trust someone on the Internet that tells you to run a command that contains rm -rf unless you look up and understand what the impact will be.
I am not a developer for Carbon Fields. I use it regularly (read: daily), but I am also not an expert at... literally anything, so feel free to offer tweaks and advice.
_PS: THANK YOU for set_attribute() and set_classes() and set_header_template() and... everything else._
Thank you for your attention.
The version checking is very important, because if you're using the latest release (2.0.1) and somebody has the old plugin from wordpress.org still installed (1.6), there will be trouble.
Please can you explain me with more detail on how to install because I have tried and it does not work
thanks for your help.
Please follow the updated Quickstart here:
https://carbonfields.net/docs/carbon-fields-quickstart/?crb_version=2-0-0
If you want to load it via plugin, I created a quick-and-dirty* loader for 2.0.3: Carbon Fields Loader
If you want to load via Composer, you can see the composer.json for an example. Just delete the ./vendor directory and run composer install.
It's not on the wordpress.org repo because it would be dumb, but you can use GitHub Updater if desired.
*No laughing. I threw it together for a client project where I had a few plugins loading it and used this so that it only loaded once. There are probably typos, but it is working for me on 4.8. It hasn't been tested much but has worked for me on WordPress 4.8 under PHP 5.3 and 7.0. Caveat emptor.
We actually released an official plugin loader as a separate package along with 2.0.3:
https://carbonfields.net/docs/carbon-fields-plugin-quickstart/?crb_version=2-0-0
Doh! When was that released? I must have missed it. I wish I would have seen that sooner. 馃槃 The link is directly above New Features, too! 馃憛
Most helpful comment
This is what I have, if it helps anyone. I haven't used it yet in a custom theme (I use Xbox for that because it has eye candy, though not nearly as actively developed as CF - it's also not free, has Draconian licensing, and other digressions), but I use Carbon Fields _all the time_ for custom plugins that I create for clients. I love it.
mnsami/composer-custom-directory-installer puts it in
./vendor/htmlburger/carbon-fieldsrather than./wp-content/plugins/...or whatever.Other Notes
Init
Don't forget that CF 2.0 apparently requires that you
\Carbon_Fields\Carbon_Fields::boot();now if loaded via PSR-4.Version Checking
If you embed CF in a plugin, you're going to want to version check CF. Say, for example, that your theme/plugin uses CF 2.0.1 but either an older version of the CF plugin loaded (for example, 1.5 or 1.6) or some other plugin has an older version embedded. WordPress will fail spectacularly when the newer classes are initialized. Then you have to rename the plugin folder because you can no longer disable it via WP Admin. That is unpleasant.
This probably has typos, and obviously some of it doesn't make sense. I just threw it together.
...
Checking Into Git
If your plugin/theme is checked into git (why wouldn't be?), I usually add this so that it doesn't mess with my soul:
Not ideal because Composer will complain every time you update, but if someone else has a better solution, HMU!
Pro-tip: Never trust someone on the Internet that tells you to run a command that contains
rm -rfunless you look up and understand what the impact will be.Disclaimer
I am not a developer for Carbon Fields. I use it regularly (read: daily), but I am also not an expert at... literally anything, so feel free to offer tweaks and advice.
_PS: THANK YOU for
set_attribute()andset_classes()andset_header_template()and... everything else._