PHP code example of devgeniem / acf-codifier

1. Go to this page and download the library: Download devgeniem/acf-codifier 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/ */

    

devgeniem / acf-codifier example snippets


$field_group = new Group( 'Field Group' );

$field_group->set_key( 'new_key' );

$field_group->set_position( 'side' )         // Set the field group to be shown in the side bar of the edit screen.
            ->set_style( 'seamless' )        // Set the field group to show as seamless.
            ->hide_element( 'the_content' ); // Hide the native WP content field.

$rule_group = new RuleGroup();
$rule_group->add_rule( 'post_type', '==', 'page' );

$field_group->add_rule_group( $rule_group );

$field_group->register();

$text = new Field\Text( 'Text field' );

$text->set_placeholder( 'Placeholder text' ) // Set a placeholder text.
     ->set_append( 'Appendable' )            // Set an appending text.
     ->set_maxlength( 30 );                  // Set the maxlength.

$conditional_logic = new ConditionalLogicGroup();
$conditional_logic->add_rule( 'another_field', '==', true );

$text->add_conditional_logic( $conditional_logic );

$field_group->add_field( $text );

$field_group->add_field( $text, 'first' );

$field_group->add_field_before( $text, 'target_field_key' );
$field_group->add_field_after( $text, $target_field_object );

$field_group->add_fields_from( $repeater );

$group = new Field\Group( 'Field name' );

$group->set_layout( 'table' )
      ->add_field( $some_field )
      ->add_field( $another_field );

$field_group->add_field( $group );

$flexible_content = new Field\FlexibleContent( 'Flexible field' );

$layout = new Field\Flexible\Layout( 'Layout label' );

$layout->set_display_mode( 'row' )
       ->add_field( $some_field )
       ->add_field( $another_field );

$flexible_content->add_layout( $layout );

$clone = new Field\CloneField( 'Clone' );

$clone->set_label_prefix()        // Set label prefix setting as true
      ->add_clone( $some_field )  // Add a field object
      ->add_clone( $some_group )  // Add a field group object.
      ->add_clone( 'field-key' ); // Add a field by its key

$field_group->add_field( $clone );

$tab = new Field\Tab( 'My Very First Tab' );

$tab->set_placement( 'left' )
    ->set_endpoint()
    ->add_field( $some_field )
    ->add_field( $another_field );

$field_group->add_field( $tab );

$pseudo = new Field\Pseudo( 'pseudo-group' );

$pseudo->add_field( $some_field )
       ->add_field( $another_field );

$field->set_bidirectional()
      ->set_bidirectional_targets( [ 'field_name_or_key' ] );

$block = new \Geniem\ACF\Block( 'Some block', 'some_block' );
$block->set_category( 'common' );
$block->add_post_type( 'post' );
$block->set_mode( 'edit' );

$renderer = new \Geniem\ACF\Renderer\CallableRenderer( function( $data ) {
  return print_r( $data, true );
});

$block->set_renderer( $renderer );

$block->register();

$layout->exclude_post_type( 'post' );

$layout->exclude_template( 'page-frontpage.php' );

$field->hide_label();

$php = new Field\PHP( __( 'My PHP field' ) );
$php->run( function() {
    global $post;

    echo '<pre>';
    print_r( $post );
    echo '</pre>';
});

$ms_relationship = new Field\MultisiteRelationship( __( 'My Multisite Relationship field', 'multisite_relationship', 'multisite_relationship' ) );
$ms_relationship->set_blog_id( 2 );

$categories_and_tags = new Field\Multitaxonomy( __( 'Select a category or a tag', 'multitaxonomy_test', 'multitaxonomy_test' ) );
$categories_and_tags->set_taxonomies( [ 'category', 'post_tag' ] );

$categories_and_tags->set_field_type( 'multi_select' );

$multisite_taxonomy = new Field\MultisiteTaxonomy( __( 'Select a category or a tag from blog 2', 'multisite_tax', 'multisite_tax' ) );
$multisite_taxonomy->set_taxonomies( [ 'category', 'post_tag' ] );
$multisite_taxonomy->set_blog_id( 2 );

$extended_wysiwyg = new Field\ExtendedWysiwyg( __( 'Extended Wysiwyg', 'extended_wysiwyg', 'extended_wysiwyg' ) );
$extended_wysiwyg->set_height( 150 );

$ms_object = new Field\MultisitePostObject( __( 'My Multisite Post Object field', 'multisite_object', 'multisite_object' ) );
$ms_object->set_blog_id( 2 );