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

Blueprint: Add an Import Theme Starter Content step. #1521

Merged
merged 12 commits into from
Jul 9, 2024

Conversation

dd32
Copy link
Member

@dd32 dd32 commented Jun 18, 2024

Motivation for the change, related issues

As part of working on Theme Previews for WordPress.org, I found myself needing to import Starter Content from themes into the playground site.

After working up the PHP as a runPHP step (See WordPress/wordpress.org#329), similar to the importWXR step I felt that this might be useful to others, so I've converted it into a fully fledged playground Step.

This was also partially an exercise in understanding how Playground Steps work under the hood. If this is deemed to not be useful feature for Playground Core, that's OK, we can't add everything as a builtin option.

Implementation details

This is modeled on the existing ImportWXR and runPHP steps, using some somewhat awkward PHP to simulate a Customizer save request, before using the Customizer import starter content to changeset function, and publish changeset functions to make the changes to the site.

I imagine this could also be an option to toggle on installTheme, such as installStarterContent: true. Option implemented

This is the same as the user loading a playground instance with a theme, clicking customize, seeing the starter content, then clicking publish. (See the video at the end)

Testing Instructions (or ideally a Blueprint)

http://127.0.0.1:5400/website-server/#{%22steps%22:[{%22step%22:%22login%22,%22username%22:%22admin%22,%22password%22:%22password%22},{%22step%22:%22installTheme%22,%22themeZipFile%22:{%22resource%22:%22wordpress.org/themes%22,%22slug%22:%22twentytwenty%22},%22options%22:{%22importStarterContent%22:true}}]}

{
  "steps": [
    {
      "step":"installTheme",
      "themeZipFile":{
        "resource":"wordpress.org/themes",
        "slug":"twentytwenty"
       },
       "options":{
         "importStarterContent": true
       }
    }
  ]
}
Without Starter Content With Starter Content The manual process this automates
Screenshot 2024-06-18 at 2 19 13 PM Screenshot 2024-06-18 at 2 18 16 PM
Screen.Recording.2024-06-18.at.2.20.33.PM.mov
@dd32
Copy link
Member Author

dd32 commented Jun 18, 2024

This doesn't have any docs or integration tests included as I wasn't sure if it was going to be accepted, I can look into that if wanted.

Additionally, the above has a lint failure due to the step not requiring any args, I'm not sure of the best way to handle that.

I did go down the route of adding an option just to satisfy the linter, but I felt that the option was better off not added ultimately. So I force-pushed that commit off this PR.

@bgrgicak
Copy link
Collaborator

I imagine this could also be an option to toggle on installTheme, such as installStarterContent: true

@dd32 it would be great if we could trigger this using an option instead of another blueprint step. The step feels really specific so the option seems like a good fit.

@dd32
Copy link
Member Author

dd32 commented Jun 19, 2024

if we could trigger this using an option instead of another blueprint step

I agree, but as it'd probably live as a step in code anyway, submitting it as-is seemed the easiest way to see if there was any buy-in.

It'd probably be called the same as activateTheme is frominstallTheme:

const activate = 'activate' in options ? options.activate : true;
if (activate) {
await activateTheme(
playground,
{
themeFolderName: assetFolderName,
},
progress
);
}

@dd32
Copy link
Member Author

dd32 commented Jun 26, 2024

Implemented the option on installTheme and added a unit test.

3b9a9b4 took way too long to track down..

@adamziel
Copy link
Collaborator

adamziel commented Jul 9, 2024

This is a lovely feature. The PR looks great @dd32, thank you!

@adamziel adamziel merged commit f677792 into WordPress:trunk Jul 9, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants