Skip to content

Commit

Permalink
Themes: Fix try&customize for themes on AT sites (#11621)
Browse files Browse the repository at this point in the history
Apply install fix from #11608 to try&customize action now that Automated Transfer sites do not need the -wpcom suffix on theme IDs when installing themes.
  • Loading branch information
seear authored Feb 28, 2017
1 parent 64725fb commit 826f937
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions client/state/themes/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ export function requestActiveTheme( siteId ) {
export function activate( themeId, siteId, source = 'unknown', purchased = false ) {
return ( dispatch, getState ) => {
if ( isJetpackSite( getState(), siteId ) && ! getTheme( getState(), siteId, themeId ) ) {
// AT sites do not use the -wpcom suffix
const siteIsAT = isSiteAutomatedTransfer( getState(), siteId );
const installId = siteIsAT ? themeId : themeId + '-wpcom';
const installId = suffixThemeIdForInstall( getState(), siteId, themeId );
// If theme is already installed, installation will silently fail,
// and it will just be activated.
return dispatch( installAndActivateTheme( installId, siteId, source, purchased ) );
Expand Down Expand Up @@ -504,9 +502,10 @@ export function clearActivated( siteId ) {
export function tryAndCustomize( themeId, siteId ) {
return ( dispatch, getState ) => {
if ( isJetpackSite( getState(), siteId ) && ! getTheme( getState(), siteId, themeId ) ) {
// Suffix themeId here with `-wpcom`. If the suffixed theme is already installed,
// installation will silently fail, and we just switch to the customizer.
return dispatch( installAndTryAndCustomizeTheme( themeId + '-wpcom', siteId ) );
const installId = suffixThemeIdForInstall( getState(), siteId, themeId );
// If theme is already installed, installation will silently fail,
// and we just switch to the customizer.
return dispatch( installAndTryAndCustomizeTheme( installId, siteId ) );
}

return dispatch( tryAndCustomizeTheme( themeId, siteId ) );
Expand Down Expand Up @@ -826,3 +825,11 @@ export function hideThemePreview() {
themeId: null
};
}

function suffixThemeIdForInstall( state, siteId, themeId ) {
// AT sites do not use the -wpcom suffix
if ( isSiteAutomatedTransfer( state, siteId ) ) {
return themeId;
}
return themeId + '-wpcom';
}

0 comments on commit 826f937

Please sign in to comment.