-2

I like ACF PRO. It's very good and power WP plugin. But...

I read the documentations ACF PRO, but the approach isn't OOP and it looks a bit multi-line-redundant (I mean it isn't convenient to use it).

Are there any other methods to create ACF PRO fields? Maybe some good 3-rd party OOP wrapper library?

  • Have you tried make your own? Define "isn't convenient". ACF provides functions/methods and a very, very comprehensive visual interface so I'm not sure what you mean by this question. – ggdx Feb 12 '18 at 09:23
  • @ggdx I didn't say that ACF PRO is bad. And my question isn't about "visual interface" which is really good. I hope to find the answer and will show you later. – Kostiantyn Petlia Feb 12 '18 at 10:47

3 Answers3

1

So, I have found and tried use this ACF Builder.

It's just ACF configuration builder but it looks good. I can define and create a new fields group programmatically. Important note, the result code is short and easy reading and we can reuse it. It exactly more short than default method:

<code>
$banner = new StoutLogic\AcfBuilder\FieldsBuilder('banner');
$banner
    ->addText('title')
    ->addWysiwyg('content')
    ->addImage('background_image')
    ->setLocation('post_type', '==', 'page')
        ->or('post_type', '==', 'post');

add_action('acf/init', function() use ($banner) {
    acf_add_local_field_group($banner->build());
});

0

If you wanna use OOP fields creating you can use another library instead ACF Pro. I can recommend to you Carbon Fields. The same field types, locations and other. Also reed this article. you can find same list of PHP instruments for meta fields.

And you can create self classes for using ACF Pro via PHP with OOP.

Maxim Sarandi
  • 643
  • 5
  • 10
0

A while ago I created ACF Code Helper for situations like this.

Upsides, compared to directly using ACF functions

  • The helper takes care of field keys, which not only makes the syntax shorter, but doesn't require much copy-pasting for conditional logic.
  • There isn't that much overhead, because for the major portion of code (the fields) the syntax follows ACF, so you can use the ACF docs instead of an additional wiki.

Downsides

  • Although the syntax is a bit shortened, it is still mostly array-based.
  • You need to keep an extra plugin activated. Not much of an issue if you clone the helper within your theme and include it.