ACF Builder / Sage 10 options page not working

Hi guys,

I’m working on my first Sage 10 site and using the awesome ACF Builder (which I know isn’t strictly Sage but I’m sure a lot of people here use it in conjunction!).

I’m trying to add an options page and add a field to it, this is my options.php:


use StoutLogic\AcfBuilder\FieldsBuilder;

acf_add_options_page([
    'page_title' => 'Theme Options',
    'menu_title' => 'Theme options',
    'menu_slug'  => 'theme_options',
    'capability' => 'edit_theme_options',
    'position'   => '99',
    'autoload'   => true
]);

$theme_options = new FieldsBuilder('theme_options');

$theme_options
    ->setLocation('options_page', '==', 'theme_options');

$theme_options
    ->addWysiwyg('footer_content');

return $theme_options;

The options page appears in the admin area, but when I click through to the page, the field isn’t there - this is the same method I used in Sage 9 and that worked fine… any idea what I might be missing or what I might need to do differently?

Thanks!

For Stoutlogic\AcfBuilder\FieldsBuilder, you need to actually initialize the fields after you configure them. This usually looks like an action hooking into the acf/init hook, using the $builder->build(); function.

So, for your code, what you would probably do something like this:

#some other code
$theme_options
    ->addWysiwyg('footer_content');

//now we want to initialize the fields:
add_action('acf/init', function use ($theme_options) {
    acf_add_local_field_group($theme_options->build());
});

// return $theme_options; //Unnecessary unless you're using the builder somewhere else.

You could also abstract this into an array of all your builders you initialize all at once, or any other way to add to that acf/init hook.

Hmmm, thanks I gave this a go but it didn’t seem to work - getting a PHP error now:

Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /Users/tom/Websites/front-of-mind/wp-content/plugins/acorn/vendor/illuminate/container/Container.php:1089 Stack trace: #0 /Users/tom/Websites/front-of-mind/wp-content/plugins/acorn/vendor/illuminate/container/Container.php(886): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...') #1 /Users/tom/Websites/front-of-mind/wp-content/plugins/acorn/vendor/illuminate/container/Container.php(758): Illuminate\Container\Container->build('Illuminate\\Cont...') #2 /Users/tom/Websites/front-of-mind/wp-content/plugins/acorn/src/Illuminate/Foundation/Application.php(851): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array, true) #3 /Users/tom/Websites/front-of-mind/wp-content/plugins/acorn/vendor/illuminate/container/Container.php(694): Illuminate\Foundation\Application->resolve('Illuminate\\Cont...', Array) #4 /Users/tom/Websites/front-of-mind/wp in /Users/tom/Websites/front-of-mind/wp-content/plugins/acorn/vendor/illuminate/container/Container.php on line 1089