PHPackages                             iniznet/acf-builder-callback - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. iniznet/acf-builder-callback

ActivePackage[Utility &amp; Helpers](/categories/utility)

iniznet/acf-builder-callback
============================

Build fields with ACF builder and sanitize-escape callback

1.1.2(3y ago)83311[1 issues](https://github.com/iniznet/acf-builder-callback/issues)[1 PRs](https://github.com/iniznet/acf-builder-callback/pulls)MITPHPPHP ^7.4|^8.0

Since Jul 31Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/iniznet/acf-builder-callback)[ Packagist](https://packagist.org/packages/iniznet/acf-builder-callback)[ RSS](/packages/iniznet-acf-builder-callback/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (10)Used By (0)

ACF Builder Callback
====================

[](#acf-builder-callback)

A package made for [ACF Builder](https://github.com/stoutlogic/acf-builder) extension to quickly create ACF configuration with callback within builder.

### Simple Example

[](#simple-example)

```
$banner = new StoutLogic\AcfBuilder\FieldsBuilder('banner');
$banner
    ->addText('title', [
        'label' => 'Title',
        'instructions' => 'Enter the title of the banner.',
        'required' => true,
        'maxlength' => 100,
        'placeholder' => 'Enter title',
        'sanitization_cb' => 'sanitize_greater_than_30',
        'escape_cb' => 'escape_greater_than_30',
    ])
    ->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());
});

/**
 * Handle the sanitization of the title field.
 * Ensures that the title is greater than 30 characters or nothing.
 *
 * @param mixed         $value      The value of the title field.
 * @param int|string    $post_id    The post ID.
 * @param array         $field      The field settings.
 *
 * @return mixed                    The sanitized value.
 */
function sanitize_greater_than_30($value, $post_id, $field) {
    if (strlen($value) > 30) {
        return $value;
    }
    return '';
}

/**
* Handle the escaping of the title field.
* Ensures that the title is greater than 30 characters or nothing.
*
* @param mixed         $value      The value of the title field.
* @param int|string    $post_id    The post ID.
* @param array         $field      The field settings.
*
* @return mixed                    The escaped value.
*/
function escape_greater_than_30($value, $post_id, $field) {
    if (strlen($value) > 30) {
        return esc_html($value);
    }
    return '';
}

// Call below somewhere within your application especially during initialization.
iniznet\AcfBuilderCallback\FieldCallback::run();
```

If you're using the [ACF Composer](https://github.com/Log1x/acf-composer)

```
