|
sacf
|
SACF stands for Scripted Advanced Custom Fields. Building upon the Advanced Custom Fields plugin by Elliot Condon this plugin adds OOP API Code for Developers. Now it's possible for versioning your fields and no need for DB-Migrations. Supporting field groups, all pro fields, options pages, the new Gutenberg blocks, third party field plugins and adds some useful functions for templating.
You still need a license for the official ACF plugin to use SACF!
Be aware that we are creating the field IDs using their slugs.
We're using a fluent interface to chain methods together. Start creating your desired fields and add them to a field group. You'll find additional examples in the ACF Admin Interface.
If you're stuck, use the help() function on any group of field class to show a popup window for all available methods within the Wordpress admin interface.
$field_text = (new text('Text', 'field_text'))->readonly()->append('test');
$field_textarea = (new textarea('Textarea', 'field_textarea'));
$field_fc = (new flexcontent('Flex Content', 'field_fc'))
->add_layout('One', 'field_fc_layout_1')
->add((new text('Text', 'text')), 'field_fc_layout_1')
->add((new image('Image', 'text')), 'field_fc_layout_1')
$custom_group = (new \sacf\group('A custom field group', 'custom_group'))
->on_front_page()
->add($field_text)
->add($field_textarea)
->add($field_fc)
->register();
(new block('An example block', 'example_1'))->register();
$group_block_example = (new group('ACF Gutenberg Block', 'group_block_example'))
->on_block('example_1')
->add((new field\text('Text', 'block_text')))
->register();
Just use this function to automatically render the layout partials of Flex Content fields.
sacf_get_template_part('field_fc');
Docblock documentation will come soon. Stay tuned...
We primarily created this plugin for our own purposes with more experienced developers in the back of our minds. So if you have something to contribute or found an issue, feel free to open a github issue.
add_filter('sacf/admin_menu', '__return_false');
add_filter('sacf/defaults', function($defaults) {
$defaults['fields']['tab']['placement'] = 'left';
return $defaults;
});
add_filter('sacf/paths', function($paths) {
$paths['parts-layouts'] = '/template-parts/acf-layouts/';
return $paths;
});