WPBP / WordPress-Plugin-Boilerplate-Powered

Wordpress Plugin Boilerplate but Powered with examples and a generator!
https://wpbp.github.io/
GNU General Public License v3.0
791 stars 114 forks source link

[BUG] Settings import does not work #237

Closed reklamasieciowa closed 1 year ago

reklamasieciowa commented 1 year ago

Backend/ImpExp.php update_option never got called because of if ( !$settings_file ).

To Reproduce Steps to reproduce the behavior:

  1. Export settings.
  2. Change something.
  3. Import settings.
  4. See the "Updated Messages" with no updates.
Mte90 commented 1 year ago

So you mean that the line https://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/blob/master/plugin-name/backend/ImpExp.php#L112 is not valid? For php https://www.php.net/manual/en/function.file-get-contents.php that method return false if the file is not found.

Also the updated messages is just a dummy notice like the others is not involved in this. Also if it is failing you get an alert "Failed to import the settings." otherwise there is a redirect, can you explain better what is happening in your case?

reklamasieciowa commented 1 year ago

This line is ok. $setting_file get the data and it is NOT empty. https://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/blob/master/plugin-name/backend/ImpExp.php#LL114C3-L114C3 check if it is empty.

Try to add: if ( !$settings_file ) { \wp_die($settings_file);

wp_die() will not run, because if ( !$settings_file ) return false.

I've setup blank project with wpbp-generator, exported settings and import does not work. :)

Mte90 commented 1 year ago

So the file is not found, I will do some tests.

Mte90 commented 1 year ago

You are right, I did a tiny patch in a commit but before to do a new release I will wait some weeks for other stuff.

https://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/commit/0274d53911c16fffdc2386b2ad3492669607c467

reklamasieciowa commented 1 year ago

Hi, I've found the real issue with import settings. The form file field name is not updated during code generation: https://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/blob/master/plugin-name/backend/ImpExp.php#L94

My code from generator: 94-96: if ( !isset( $_FILES[ 'pn_import_file' ][ 'name' ] ) ) { return; } The form field name is _lmc_importfile in my case. 97: file_name_parts = \explode( '.', $_FILES['lmc_import_file']['name'] );

Mte90 commented 1 year ago

I will check in the generator, thanks for investigating

Mte90 commented 1 year ago

I tested the altest generator version with the latest boilerplate version and this issue is not happening. Are you using the latest version for the generator?

reklamasieciowa commented 1 year ago

Hmm. There is no --v option. ;) Last download 18.05.2023. If there is no issue now, just close this topic. ;)