wp-media / adminimize

Adminimize is a WordPress plugin that lets you hide 'unnecessary' items from the WordPress backend.
https://wordpress.org/plugins/adminimize/
GNU General Public License v2.0
100 stars 31 forks source link

[Bug]: Fatal error in '/inc-options/admin_bar_frontend.php' when options are imported #155

Closed ControlZetaDigital closed 1 year ago

ControlZetaDigital commented 1 year ago

Description of the bug

Hi

When you import a JSON file with options exported from another website, even if the websites are exactly the same, the plugin throws a fatal error on line 87 of the file '/inc-options/admin_bar_frontend.php'.

I have detected the problem here: Line 81: foreach ( $admin_bar_frontend_items as $key => $value ) {

I don't know why it happens, but when you import a json file with options, the variable $value is no longer an object, but an array.

I've solve the problem adding this line of code just after the foreach line: $value = (is_object($value)) ? $value : (object) $value;

If this is a common bug, I hope this can help to solve it.

Cheers

Reproduction instructions

  1. Go to Import / Export options
  2. Import a JSON file previously exported
  3. Update the changes and the fatal error will be thrown

Expected behavior

Don't get a fatal error when importing options

Environment info

Relevant log output

No response

Additional context

No response

Code of Conduct

bueltge commented 1 year ago

Thanks for the note. Why not send a PR for this bug?

borsodigerii commented 1 year ago

The bug appears here as well. Same has been done, imported a .json file with settings, and since then (I'm using multisite) I cannot edit any settings on any sites in adminize, because it always throws an error (but only on the frontend, so it does work, when some settings has to be hidden, fortunately). Going on Adminize 1.11.8 with WordPredd 6.1.1

ControlZetaDigital commented 1 year ago

Hi all, sorry I've just read your response @bueltge

@borsodigerii thanks for sending PR of the fix that I suggested, I was about to send it right now but you were faster

bueltge commented 1 year ago

Thanks a lot for the feedback and the PR. The new version should be public in view minutes on wp.org.