YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.
MIT License
2.21k stars 403 forks source link

Fix the remote source folder structure if necessary. #574

Closed MehbubRashid closed 1 month ago

MehbubRashid commented 1 month ago

The Problem/Issue

Many developers including the owner of this repository are well aware of the folder structure issue. Mostly it happens to MacOs users. When compressing the plugin folder to make a zip archive in Mac, it makes the zip structure like this:-

- my-plugin.zip
    - my-plugin.php
    - other-plugin-files.php

But it used to throw an error because WP requires the structure to be like:-

- my-plugin.zip
    - my-plugin 
        - my-plugin.php
        - other-plugin-files.php

that means The update archive should contain a single directory that contains the rest of plugin/theme files. Till today, the solution for mac users was to use a different archiver software. Issue reference: #210 #482 #456 #159 #382 #62 Using different archiver tool does solve the problem, but thats not the best solution. Because it should work regardless the user is on mac or windows. I should not take extra steps just because I am a mac user. A developer in mac encounters this error first, and has to visit this repository to search for a solution. Thats not really a good experience.

Moreover, we should not maintain two zip file sources (One for downloading and another for update). Because, the default plugin uploader page of WordPress allows both type of zip file structure to install the plugin. It doesn't require a specific structure. Currently the same zip that works for plugin uploading, doesn't work for plugin update. Thats really a problem.

What's done and what's the benefit?

After extracting the remote zip, It re-structures and corrects the folder/zip structure - if not correct already. Now regardless of the zip structure, both mac and windows zip update works. Mac users doesn't have to face this issue and search for solutions.

Let me know your thoughts and I am open to make any changes if necessary. Thanks for this awesome package.

YahnisElsts commented 1 month ago

Looks good at a glance. Can you tell me how much testing you've done with this? Does WordPress successfully clean up everything in /wp-content/upgrade and /wp-content/upgrade-temp-backup after installing an update like this?

MehbubRashid commented 1 month ago

@YahnisElsts Thanks. Yes, I have checked and debugged line by line and saw WordPress deletes the folders from upgrade & upgrade-temp-backup folders after successful update. If you want to test it out, I can provide you with a test zip file made in MacOS.

YahnisElsts commented 1 month ago

All right, I ran a quick test myself to confirm, and it worked fine. I will merge this now.

MehbubRashid commented 1 month ago

@YahnisElsts thank you.