Skip to content
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

Try: refactor clone to copy theme to current site #294

Closed
wants to merge 11 commits into from

Conversation

jffng
Copy link
Contributor

@jffng jffng commented Mar 28, 2023

This PR is an attempt to address #284 #288 and #186, by modifying the behavior of the Clone option.

Instead of generating a zip, Clone creates a copy of the currently active theme, along with any user modifications, to the current site — providing a convenient way for users to effectively fork an existing theme.

Export was updated to work like Clone did — allowing users to edit the metadata for an export.

notes

To test

  • Make some changes to templates and global styles via the site editor
  • Use the Clone option
  • Verify the cloned theme appears as expected in Appearance > Themes
  • Verify that the export and overwrite options still work as expected
@jffng jffng marked this pull request as ready for review March 28, 2023 21:26
Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this out using the latest version of GB with Archeo and Iotix.

Verify the cloned theme appears as expected in Appearance > Themes

The cloned theme appears with the correct edits (screenshot, name) in Themes ✅

However, when I view the cloned theme in the Site Editor, I'm not seeing most of the content:

image

I think this is because of the way I named the theme. I was testing with Archeo here and I named the clone, "Archeo clone 2". The textdomain has come through as archeoclone2clone2, and the template parts and patterns are usingarcheoclone2 as a theme slug. I'm guessing this mismatch has caused these references to fail.

I also tried with a single word name, "ClonedArcheo", but the textdomain came through as clonedclonedarcheo, so I saw the same issue with the parts and patterns.

Verify that the export and overwrite options still work as expected

Yes! ✅

admin/class-create-block-theme-admin.php Outdated Show resolved Hide resolved
@mikachan
Copy link
Member

If we like this idea, I think we should add the ability to edit the metadata to the Export option as a fast follow up

I think this is a great idea!

Copy link
Contributor

@matiasbenedetto matiasbenedetto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi 👋
This looks very good :)

Could we add some theme name/slug validation? I ask this because if, for example, there is already a theme with that name in the themes folder, the plugin fails silently. Let's say I export a "TT3" clone with the name "hola," and after that, I activate the "Disco" theme, and I clone it with the same name ("hola"). The resulting folder /themes/hola have the TT3 content.

We could get a list of the themes/directories in the themes folder to know if the name/slug is valid.

Apart from that, having the option to edit the theme data when you export seems important; otherwise, the user could not get a zip of a theme with a name and data.

admin/create-theme/theme-zip.php Outdated Show resolved Hide resolved
@matiasbenedetto
Copy link
Contributor

Using this branch, I get 0-byte zip files when using the "export" option.

@jffng
Copy link
Contributor Author

jffng commented Mar 30, 2023

Thanks for the reviews @mikachan @matiasbenedetto !

I think this is because of the way I named the theme.

@mikachan you're right, there was a bug in the replace_namespace function — it did not handle "overlapping" cases e.g. where the old name is present in the new one. I think I fixed it here, but it could use another test and review because my regex is not very specific.

Using this branch, I get 0-byte zip files when using the "export" option.

This should be fixed with the latest commit f4c3f2c

@jffng
Copy link
Contributor Author

jffng commented Mar 30, 2023

Could we add some theme name/slug validation?

Good idea, I will add this to the PR.

@mikachan
Copy link
Member

there was a bug in the replace_namespace function

With the very latest commit, I see this error when I try to clone: 'Theme name already exists, please choose a different name.'

If I use f4c3f2c, it looks like the name of the theme does prevent it from being cloned, but I'm struggling to find a pattern. I'm using Archeo again, and these names didn't seem to work: 'ArcheoClone', 'Clone Archeo', 'New Archeo'. But these did: 'Archeos', 'Theme', 'New Theme', 'Archeo2'.

@jffng jffng force-pushed the try/clone-and-activate branch 2 times, most recently from 861dc5b to c1797be Compare April 3, 2023 17:36
@jffng
Copy link
Contributor Author

jffng commented Apr 3, 2023

Okay I rebased this PR. Since #292 was merged, it made sense to also solve #186 at the same time.

With the very latest commit, I see this error when I try to clone: 'Theme name already exists, please choose a different name.'

Sorry there was a bug in this, I think I fixed it in c1797be.

If you wouldn't mind testing the following flows again, that would be greatly appreciated:

  • Clone
  • Export
  • Export from the site editor
Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested with Archeo again. I've added a custom image to the home template and changed the headings in global styles to a different colour (red).

Clone:

I cloned the theme and named it 'Oak':

  • I get a cloned theme with the correct name
  • The change to global styles is correctly included in the clone

I'm seeing intermittent problems with the custom image. Sometimes the image is included in the cloned theme assets folder, but on other attempts, the image is added to the existing version of Archeo (e.g. when I check my themes directory with git status).

I'm not sure what's triggering the differences - the only difference in my testing is different theme names, but I've seen both happen on the same theme name.

Export:

  • Works well if I don't change the name of the theme
  • If I change the name from Archeo (I tried 'Export', 'Oak', 'Test') I get the following warning from the add_media_to_zip function:

Warning: file() expects parameter 1 to be a valid path, object given in /admin/create-theme/theme-zip.php on line 106

Edit: I've just been testing out something else and I'm still seeing this warning, so I don't think it's related to this PR. It seems to consistently happen with Archeo but not any other theme - so I've either messed up my local version of Archeo or there's a bug in that theme...

Export from the site editor:

  • Works well 👍
  • I get a zip file that includes my custom image and my change to global styles

I'm sorry that I'm still seeing errors with export - does it sound like I'm testing correctly? I feel like I'm doing something particularly awkward. Let me know if you need more info!

@jffng
Copy link
Contributor Author

jffng commented Apr 19, 2023

Thanks for the thorough test and reporting @mikachan ! I am not sure what's going on with the Export there, I tried with Archeo and it seems to be working after I rebased this branch.

What is not working for me is the Export from Site Editor option. I narrowed it down fail when I include a media asset in the template, and the download_url fails. Any ideas? cc @matiasbenedetto who recently worked on a bug with this I think.

@vcanales
Copy link
Member

What is not working for me is the Export from Site Editor option. I narrowed it down fail when I include a media asset in the template, and the download_url fails.

Clone from the Site Admin has a similar issue; the resulting theme does not include custom fonts, although it fails silently.

@mikachan
Copy link
Member

I narrowed it down fail when I include a media asset in the template, and the download_url fails.

This sounds like the same error I was seeing with add_media_to_zip above, but I'm pretty sure it's not related to this PR as I was seeing the same error on different branches.

@vcanales
Copy link
Member

vcanales commented Apr 26, 2023

I created a PR with fixes for the Export/download_url problem. #338

@vcanales
Copy link
Member

I created a PR with fixes for the Export/download_url problem. #338

Forgot to mention; as @mikachan said, it doesn't seem to be related to this PR. I tested it both on trunk and here, and it looks good.

@jffng
Copy link
Contributor Author

jffng commented Jul 11, 2023

Closing this one as outdated.

@jffng jffng closed this Jul 11, 2023
@vcanales vcanales deleted the try/clone-and-activate branch May 23, 2024 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants