Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Widget ID #36

Closed
mike-sheppard opened this issue Aug 4, 2020 · 5 comments
Closed

Duplicate Widget ID #36

mike-sheppard opened this issue Aug 4, 2020 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@mike-sheppard
Copy link
Contributor

Hey @Log1x thanks for fixing up those other bits, much appreciated. Just run into this weird one today - not sure if it's the way I'm calling get_field() maybe? But trying out the Example widget it appears to have the same issue.

Summary

Multiple widgets return the same widget_id so ACF data returned is always the last widget added (of the same type).

Example

  1. wp acorn acf:widget Example
  2. Add 2 or more Example widgets with a few unique list items Screenshot 2020-08-04 at 16 11 39
  3. Identical fields will be shown in the view (last added widget) Screenshot 2020-08-04 at 16 07 07
@Log1x
Copy link
Owner

Log1x commented Aug 4, 2020

If you change https://github.com/Log1x/acf-composer/blob/master/src/Providers/AcfComposerServiceProvider.php#L39 to $this->app->bind – does it work?

@mike-sheppard
Copy link
Contributor Author

mike-sheppard commented Aug 4, 2020

Thanks for looking into it. Looks like the result is the same as before with this change:

$this->app->bind('AcfComposer', function () {
    return $this->compose();
});

@Log1x Log1x self-assigned this Aug 4, 2020
@mike-sheppard
Copy link
Contributor Author

mike-sheppard commented Aug 4, 2020

My guess was something to do with the passed $instance - https://github.com/Log1x/acf-composer/blob/master/src/Widget.php#L125 but haven't dived in too deep yet, should be able to spend some time on it this eve.

@Log1x Log1x added the bug Something isn't working label Aug 4, 2020
@Log1x
Copy link
Owner

Log1x commented Aug 5, 2020

man I'm a little stumped on this. it has something to do with the proper variables not passing when initializing the anonymous class. there has to be a way to make it properly work

@mike-sheppard
Copy link
Contributor Author

So got a hacky 'fix'..

Setting the id from the instance/args seems to fix it? https://github.com/Log1x/acf-composer/blob/master/src/Widget.php#L125

public function widget($args, $instance)
{
+   $this->widget->widget->id  = "widget_{$args['widget_id']}";
    echo Arr::get($args, 'before_widget');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants