acf-composer
acf-composer copied to clipboard
Invalid json with Widget
Hello,
I am using Sage 10.0.0-beta.2 and I have installed acf-composer. I have followed the documentation by creating an Example Widget:
wp acorn acf:widget Example
When I go to Wordpress Admin to add items in this new Widget, I have an invalid_json error because data returned by _POST wp-json/wp/v2/widget-types/example/encode?locale=user returned the following error:
ErrorException: Undefined index: widget_id in file /app/web/app/themes/aba/vendor/log1x/acf-composer/src/Widget.php on line 122
I must turn off all configuration related to DEBUG and ERROR display (I am using Bedrock) to be able to interact with this Example Widget.
Best Regards,
Not being able to reproduce this. Are you using it as a Legacy Widget with the new block widgets?
Hello,
Actually I don't really think in terms of Legacy Widget, I have just type the command on a fresh install of Bedrock / Sage 10 and the widget generated was not able to be displayed in Appearance > Widgets. Is there specific parameter to pass in the command to decide when using Legacy Widget?
Sorry I am bit lost by your question.
Hey @Log1x,
I can reproduce the problem after creating a widget with acf-composer.
I'm using WordPress 6.0.1 (including the new widget system).
WP_DEBUG = TRUE
When I try to add the widget, I get an error in console (if WP_DEBUG is enabled)
ErrorException: Undefined index: widget_id in file /xxxx/themes/xxxx/vendor/log1x/acf-composer/src/Widget.php on line 122
After the debug, I looked at the content of $args and it does not contain any widget_id but only :
Array
(
[before_widget] => <div class="widget widget_footer-desc">
[after_widget] => </div>
[before_title] => <h2 class="widgettitle">
[after_title] => </h2>
)
WP_DEBUG = FALSE
Array
(
[before_widget] =>
[after_widget] =>
[before_title] =>
[after_title] =>
[widget_id] => 'example-1'
[widget_name] => 'Example'
)
After the debug, I looked at the content of $args and it does not contain any widget_id but only :
That is super weird.
Same issue for me. WP_DEBUG really affects it somehow.
I'm currently adding
/**
* Disable the widgets block editor.
* @link https://developer.wordpress.org/block-editor/how-to-guides/widgets/opting-out/
*/
remove_theme_support('widgets-block-editor');
to after_setup_theme in setup.php to fix this for now in my themes. I'm guessing with the new widget block stuff ACF Composer's widget implementation may end up deprecated at some point.
I haven't tried creating block widgets yet with ACF. Has anyone else tried it?