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

Subtheme installation fails after installing main theme, if subtheme was tried first, due to left-behind directory #410

Open
mvl22 opened this issue Mar 7, 2024 · 3 comments

Comments

@mvl22
Copy link

mvl22 commented Mar 7, 2024

If you attempt to install a theme which is a subtheme, the install returns:

The parent theme could not be found. You will need to install the parent theme, <parent-theme-name>, before you can use this child theme.

However, it leaves behind a directory. After going to install the parent theme, re-running the command to install the subtheme then fails, with:

Destination folder already exists.

For instance:

# Attempt to install rockfield theme (not realising this is a subtheme)
wp theme install https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip --activate
# returns error "The parent theme could not be found. You will need to install the parent theme..."

# Attempt to install main theme
wp theme install https://public-api.wordpress.com/rest/v1/themes/download/varia.zip --activate
# returns success

# Now, go back to install the subtheme, rockfield:
wp theme install https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip --activate
# returns error "Destination folder already exists..."

# Workaround - firstly remove the left-behind folder, then retry the subtheme install:
rm -rf /path/to/wp-content/themes/rockfield-wpcom
wp theme install https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip --activate

If installation of a subtheme fails because the main theme is not there, the folder should not be left behind, i.e. it should be properly atomic.

@wojsmol
Copy link
Contributor

wojsmol commented Mar 7, 2024

Hi
Other workaround is to use --force parameter - wp theme install https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip --activate --force

@danielbachhuber
Copy link
Member

If installation of a subtheme fails because the main theme is not there, the folder should not be left behind, i.e. it should be properly atomic.

I agree with this.

Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.

@UmeshSingla
Copy link

UmeshSingla commented May 19, 2024

I'm unable to replicate the issue. WP CLI definitely throws an error when it tries to activate the newly installed child theme with no parent theme available in WordPress install.

But once you install the parent theme, child theme can be successfully activated from the back-end or the shell, there is no need to install the child theme again.

wp theme install https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip --activate

Downloading installation package from https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip...
Unpacking the package...
Installing the theme...
This theme requires a parent theme. Checking if it is installed...
The parent theme could not be found. You will need to install the parent theme, varia-wpcom, before you can use this child theme.
Theme installed successfully.
Activating 'rockfield-wpcom'...
Error: The parent theme is missing. Please install the "varia-wpcom" parent theme.

wp theme install https://public-api.wordpress.com/rest/v1/themes/download/varia.zip --activate

Downloading installation package from https://public-api.wordpress.com/rest/v1/themes/download/varia.zip...
Unpacking the package...
Installing the theme...
Theme installed successfully.
Activating 'varia-wpcom'...
Success: Switched to 'Varia' theme.
Success: Installed 1 of 1 themes.

wp theme activate rockfield-wpcom

Success: Switched to 'Rockfield' theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants