PHP code example of iniznet / acf-builder-callback
1. Go to this page and download the library: Download iniznet/acf-builder-callback library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iniznet / acf-builder-callback example snippets
$banner = new StoutLogic\AcfBuilder\FieldsBuilder('banner');
$banner
->addText('title', [
'label' => 'Title',
'instructions' => 'Enter the title of the banner.',
'Wysiwyg('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();
namespace App\Fields;
use Log1x\AcfComposer\Field;
use StoutLogic\AcfBuilder\FieldsBuilder;
class Example extends Field
{
/**
* The field group.
*
* @return array
*/
public function fields()
{
$example = new FieldsBuilder('example');
$example
->setLocation('post_type', '==', 'post');
$example
->addRepeater('items')
->addText('item', [
'label' => 'Item',
'instructions' => 'Enter the item.',
'ization.
iniznet\AcfBuilderCallback\FieldCallback::run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.