-
Notifications
You must be signed in to change notification settings - Fork 57
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
Adding files to zip subfolder called as theme slug #357
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get quite a few warnings in WP admin when I apply this branch:
Warning: Declaration of CbtZipArchive::addEmptyDir(string $dirname, int $flags = 0) should be compatible with ZipArchive::addEmptyDir($dirname) in /admin/create-theme/cbt-zip-file.php on line 24
Warning: Declaration of CbtZipArchive::addFromString(string $name, string $content, int $flags = ZipArchive::FL_OVERWRITE) should be compatible with ZipArchive::addFromString($name, $content) in /admin/create-theme/cbt-zip-file.php on line 14
Warning: Declaration of CbtZipArchive::addFile(string $filepath, string $entryname = '', int $start = 0, int $length = 0, int $flags = ZipArchive::FL_OVERWRITE) should be compatible with ZipArchive::addFile($filepath, $entryname = NULL, $start = NULL, $length = NULL) in /admin/create-theme/cbt-zip-file.php on line 19
And a couple of: Warning: Cannot modify header information - headers already sent...
warnings.
It looks like CbtZipArchive
doesn't quite match the ZipArchive
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got the same warnings as @mikachan.
admin/create-theme/cbt-zip-file.php
Outdated
@@ -0,0 +1,31 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about naming this file cbt-zip-archive
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, updated!
It seems like overriding the ZipArchive class methods is not the best idea because the declaration of the methods is not exactly the same in all PHP versions. To work around this, I called the functions we are using with another name to avoid conflicts. It should work as expected now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a workflow that I tried that doesn't seem to be working as expected:
- Export "Adventurer" (a theme that lives in
wp-content/themes/themes/adventurer
- There already exists
adventurer.zip
in my downloads, so the export is namedadventurer (2).zip
- Upload that theme zip to the same site and receive the following error:
The package could not be installed. The theme is missing the style.css stylesheet.
Theme installation failed.
When I expand the zip locally, it results in a folder themes
containing a subfolder adventurer
.
Thanks for testing @jffng ! I could not reproduce this issue even with |
@matiasbenedetto what is the path of the themes you are testing with? I did some more testing and get the error for exported themes that live in a subfolder within the themes folder, e.g. |
@jffng The problem was only reproducible when the original theme came from a subfolder. In that case, the slug we get is a path instead of just the slug of the theme (ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is working well for me now using themes in subfolders. I followed @jffng's testing steps from here:
Export "Adventurer" (a theme that lives in wp-content/themes/themes/adventurer) ✅
Upload that theme zip to the same site, no errors and theme activates successfully ✅
Theme installation works ✅
Expanded the zip locally, I can see the theme files in the root of the zip folder ✅
I think this is good to come in now 👍
What?
Create theme files inside a subfolder called as the theme slug.
Example of zip file structure:
Before:
After:
Why?
Avoid problems with theme paths when exporting/cloning themes as zip files.
For example, when you download the theme zip file with a filename different from the expected theme slug. It's common to download files as 'themename (5).zip'. Let's see what happen if you upload that file to a WordPress instance: the theme will live in
wp-content/themes/themename-5
instead ofwp-content/themes/themename
meanwhile the theme slug will continue beingthemename
. There could be references to the theme slug in the theme, for example, if your theme is linking template parts in patterns. The end result will be missing template parts because the parts will be searched inwp-content/themes/themename/parts
when they will be located inwp-content/themes/themename-5/parts
.With this change no matter how is the zip file called. The theme will be created in
wp-content/themes/themename
so we will avoid the errors described before.