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

Import Json - Fatal error - [Attempt to assign property "title" on array] #160

Closed tatof closed 9 months ago

tatof commented 9 months ago

Before submitting an issue please check that you’ve completed the following steps:

Describe the bug I import a .json settings file from an other site (same theme, settings and roles) and I get a "fatal error". It looks like the import succeeds but it gives an error.

To Reproduce Steps to reproduce the behavior:

  1. Export Json from development site
  2. Import Json to client site
  3. See error

Additional context I have 30+ site with a custom made theme and all the same settings. All sites give the same error.

[Thu Nov 30 10:37:01.817162 2023] [lsapi:warn] [pid 22392:tid 139880677771008] [client ****personal-ip*****] [host wsvmarne.ontzorg.site] Backend log: PHP Warning: Attempt to read property "title" on array in /home/wsvmarne/domains/wsvmarne.ontzorg.site/public_html/site/plugins/adminimize/inc-options/admin_bar.php on line 87\n, referer: https://wsvmarne.ontzorg.site/wp-admin/options-general.php?page=adminimize-options [Thu Nov 30 10:37:01.817247 2023] [lsapi:error] [pid 22392:tid 139880677771008] [client ****personal-ip*****] [host wsvmarne.ontzorg.site] Backend fatal error: PHP Fatal error: Uncaught Error: Attempt to assign property "title" on array in /home/wsvmarne/domains/wsvmarne.ontzorg.site/public_html/site/plugins/adminimize/inc-options/admin_bar.php:88\nStack trace:\n#0 /home/wsvmarne/domains/wsvmarne.ontzorg.site/public_html/site/plugins/adminimize/adminimize_page.php(172): require_once()\n#1 /home/wsvmarne/domains/wsvmarne.ontzorg.site/public_html/wp-includes/class-wp-hook.php(324): _mw_adminimize_options()\n#2 /home/wsvmarne/domains/wsvmarne.ontzorg.site/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()\n#3 /home/wsvmarne/domains/wsvmarne.ontzorg.site/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()\n#4 /home/wsvmarne/domains/wsvmarne.ontzorg.site/public_html/wp-admin/admin.php(259): do_action()\n#5 /home/wsvmarne/domains/wsvmarne.ontzorg.site/public_html/wp-admin/options-general.php(10): require_once('/home/wsvmarne/...')\n#6 {main}\n thrown in /home/wsvmarne/domains/wsvmarne.ontzorg.site/public_html/site/plugins/adminimize/inc-options/admin_bar.php on line 88\n, referer: https://wsvmarne.ontzorg.site/wp-admin/options-general.php?page=adminimize-options

tatof commented 9 months ago

ps. is there a way to include adminimize settings in my theme?

bueltge commented 9 months ago

@borsodigerii Do you help me in the context of JSON Ex/Import, was issue #155. Would you look at this problem?

borsodigerii commented 9 months ago

@borsodigerii Do you help me in the context of JSON Ex/Import, was issue #155. Would you look at this problem?

I will look into it, but so far I didn't come into this error. @tatof could you send me a sample file of what you used? (Ofc. delete all the sensitive information from it beforehand; just need the file solely for testing)

tatof commented 9 months ago

Don't think there is any sensitive information in the export..?

The export/import file: mw_adminimize-settings-export-11-29-2023.json

Thanks! :)

tatof commented 9 months ago

ps. is there a way to import .json file programmatically? Need to maintain setting through theme updates.

Like this:

$current_version = wp_get_theme()->get('Version');
$old_version = get_option('tf_ontzorg_theme_version');

if ($old_version !== $current_version) {
    if(file_exists('adminimize-import.json')){
         IMPORT SETTINGS FILE ONCE
    }
}
bueltge commented 9 months ago

The function _mw_adminimize_import_json() takes over the import of a JSON file and import as array in the options field in the database. The function has no option for an optional path of the import file; maybe an idea for a feature request.

borsodigerii commented 9 months ago

Tried to reproduce the error, for me the import went well; no clue what could've caused this on your side. Maybe a faulty other plugin conflicts with the hooks somehow?

tatof commented 9 months ago

@bueltge Yes please! Feature request would be nice. Although I could just import the option field myself? I guess the plugin just imports .json -> array -> options field?

I could just do this right?

$path = "my-theme-included-adminimize-export.json"
$settings = json_decode( file_get_contents( $path ), true );
unlink( $path );

_mw_adminimize_update_option( $settings );

@borsodigerii the import worked only got an error... lets just say its a local problem. Thanks for checking it out!

borsodigerii commented 9 months ago

@bueltge Yes please! Feature request would be nice. Although I could just import the option field myself? I guess the plugin just imports .json -> array -> options field?

I could just do this right?


$path = "my-theme-included-adminimize-export.json"

$settings = json_decode( file_get_contents( $path ), true );

unlink( $path );

_mw_adminimize_update_option( $settings );

@borsodigerii the import worked only got an error... lets just say its a local problem. Thanks for checking it out!

Yeah sorry, I meant that I did not get the error after the import😅

bueltge commented 9 months ago

Sure, @borsodigerii. The settings are only in one field of the database, so can use _mw_adminimize_update_option( $settings ) or default WP function to update the item in the table, see https://github.com/wp-media/adminimize/blob/ae8f7b0d75f6d783f2b4572e3f92fca05fb5559b/adminimize.php#L1303C3-L1303C30

tatof commented 9 months ago

@bueltge nice thanks for the info! :) this ticket is resolved.

@borsodigerii i understood 😁

Thanks for the great support. have a nice day