Beispiel #1
0
	hideForTheme: ( state, themeId, siteId ) => (
		! getCurrentUser( state ) ||
		( siteId && ( ! canCurrentUser( state, siteId, 'edit_theme_options' ) ||
		( isJetpackSite( state, siteId ) && isJetpackSiteMultiSite( state, siteId ) ) ) ) ||
		isThemeActive( state, themeId, siteId ) ||
		( isThemePremium( state, themeId ) && isJetpackSite( state, siteId ) && ! isPremiumThemeAvailable( state, themeId, siteId ) ) ||
		( isJetpackSite( state, siteId ) && ! isThemeAvailableOnJetpackSite( state, themeId, siteId ) )
	)
Beispiel #2
0
	return ( dispatch, getState ) => {
		let filteredThemes = themes;
		let found = foundCount;

		if ( isJetpackSite( getState(), siteId ) ) {
			/*
			 * We need to do client-side filtering for Jetpack sites because:
			 * 1) Jetpack theme API does not support search queries
			 * 2) We need to filter out all wpcom themes to show an 'Uploaded' list
			 */
			const filterWpcom = shouldFilterWpcomThemes( getState(), siteId );
			filteredThemes = filter(
				themes,
				theme => (
					isThemeMatchingQuery( query, theme ) &&
						! ( filterWpcom && isThemeFromWpcom( theme ) )
				)
			);
			// Jetpack API returns all themes in one response (no paging)
			found = filteredThemes.length;
		}

		dispatch( {
			type: THEMES_REQUEST_SUCCESS,
			themes: filteredThemes,
			siteId,
			query,
			found,
		} );
	};
Beispiel #3
0
	hideForTheme: ( state, themeId, siteId ) => (
		! getCurrentUser( state ) ||
		isJetpackSiteMultiSite( state, siteId ) ||
		isThemeActive( state, themeId, siteId ) ||
		( isThemePremium( state, themeId ) && ! isPremiumThemeAvailable( state, themeId, siteId ) ) ||
		( isJetpackSite( state, siteId ) && ! isThemeAvailableOnJetpackSite( state, themeId, siteId ) )
	)
Beispiel #4
0
const getSuffixedThemeId = ( state, themeId, siteId ) => {
	const siteIsJetpack = siteId && isJetpackSite( state, siteId );
	if ( siteIsJetpack && ! getTheme( state, siteId, themeId ) ) {
		return `${ themeId }-wpcom`;
	}
	return themeId;
};
Beispiel #5
0
		hideForTheme: ( state, themeId, siteId ) => (
			isJetpackSite( state, siteId ) || // No individual theme purchase on a JP site
			! getCurrentUser( state ) || // Not logged in
			! isThemePremium( state, themeId ) || // Not a premium theme
			isPremiumThemeAvailable( state, themeId, siteId ) || // Already purchased individually, or thru a plan
			isThemeActive( state, themeId, siteId ) // Already active
		)
Beispiel #6
0
export function shouldFilterWpcomThemes( state, siteId ) {
	return (
		isJetpackSite( state, siteId ) &&
		config.isEnabled( 'manage/themes/upload' ) &&
		hasJetpackSiteJetpackThemesExtendedFeatures( state, siteId ) &&
		! isJetpackSiteMultiSite( state, siteId )
	);
}
Beispiel #7
0
export function getJetpackUpgradeUrlIfPremiumTheme( state, themeId, siteId ) {
	if (
		isJetpackSite( state, siteId ) &&
		isThemePremium( state, themeId ) &&
		! hasFeature( state, siteId, FEATURE_UNLIMITED_PREMIUM_THEMES )
	) {
		return `/checkout/${ getSiteSlug( state, siteId ) }/professional`;
	}
	return null;
}
Beispiel #8
0
	return ( dispatch, getState ) => {
		if ( isJetpackSite( getState(), siteId ) && ! getTheme( getState(), siteId, themeId ) ) {
			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 ) );
	};
Beispiel #9
0
	return ( dispatch, getState ) => {
		if ( isJetpackSite( getState(), siteId ) && ! getTheme( getState(), siteId, themeId ) ) {
			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 ) );
		}

		return dispatch( activateTheme( themeId, siteId, source, purchased ) );
	};
Beispiel #10
0
		function shouldRedirectMyPosts() {
			if ( ! author ) {
				return false;
			}
			if ( areAllSitesSingleUser( state ) ) {
				return true;
			}
			if ( isSingleUserSite( state, siteId ) || isJetpackSite( state, siteId ) ) {
				return true;
			}
		}
Beispiel #11
0
			.then( theme => {
				debug( 'Received current theme', theme );
				// We want to store the theme object in the appropriate Redux subtree -- either 'wpcom'
				// for WPCOM sites, or siteId for Jetpack sites.
				const siteIdOrWpcom = isJetpackSite( getState(), siteId ) ? siteId : 'wpcom';
				dispatch( receiveTheme( theme, siteIdOrWpcom ) );
				dispatch( {
					type: ACTIVE_THEME_REQUEST_SUCCESS,
					siteId,
					theme
				} );
			} ).catch( error => {
Beispiel #12
0
export default connect( ( state, { siteId } ) => {
	const productSlug = get( getCurrentPlan( state, siteId ), 'productSlug' );
	return {
		isGoogleMyBusinessLocationConnected: isGoogleMyBusinessLocationConnectedSelector(
			state,
			siteId
		),
		isStore: isSiteStore( state, siteId ),
		isJetpack: isJetpackSite( state, siteId ),
		isWpComPaidPlan: ! isWpComFreePlan( productSlug ),
		siteId,
	};
} )( StatsNavigation );
Beispiel #13
0
export const getGroups = ( state, siteId ) => {
	const groups = [];
	const siteDetails = getSite( state, siteId );

	if ( isATEnabled( siteDetails ) ) {
		// AT sites should go to WP.com even though they are jetpack also
		groups.push( HAPPYCHAT_GROUP_WPCOM );
	} else if ( isJetpackSite( state, siteId ) ) {
		groups.push( HAPPYCHAT_GROUP_JPOP );
	} else {
		groups.push( HAPPYCHAT_GROUP_WPCOM );
	}
	return groups;
};
Beispiel #14
0
	return services.filter( ( service ) => {
		// Omit if the site is Jetpack and service doesn't support Jetpack
		if ( isJetpackSite( state, siteId ) && ! service.jetpack_support ) {
			return false;
		}

		// Omit if Jetpack module not activated
		if ( isJetpackSite( state, siteId ) && service.jetpack_module_required &&
			! isJetpackModuleActive( state, siteId, service.jetpack_module_required ) ) {
			return false;
		}

		// Omit if service is settings-oriented and user cannot manage
		if ( 'eventbrite' === service.ID && ! canCurrentUser( state, siteId, 'manage_options' ) ) {
			return false;
		}

		// Omit if Publicize service and user cannot publish
		if ( 'publicize' === service.type && ! canCurrentUser( state, siteId, 'publish_posts' ) ) {
			return false;
		}

		return true;
	} );
Beispiel #15
0
export function getPremiumThemePrice( state, themeId, siteId ) {
	if ( ! isThemePremium( state, themeId ) || isPremiumThemeAvailable( state, themeId, siteId ) ) {
		return '';
	}

	if ( isJetpackSite( state, siteId ) ) {
		return i18n.translate( 'Upgrade', {
			comment:
				'Used to indicate a premium theme is available to the user once they upgrade their plan',
		} );
	}

	const theme = getTheme( state, 'wpcom', themeId );
	return get( theme, 'price' );
}
Beispiel #16
0
	return function( context, next ) {
		const { getState } = getStore( context );
		const siteId = getSelectedSiteId( getState() );
		const isJetpack = isJetpackSite( getState(), siteId );
		const isModuleActive = isJetpackModuleActive( getState(), siteId, moduleId );

		if ( ! isJetpack ) {
			return next();
		}

		if ( isModuleActive || false === redirect ) {
			next();
		} else {
			page.redirect( 'string' === typeof redirect ? redirect : '/stats' );
		}
	};
Beispiel #17
0
/**
 * Returns the menus admin URL for the given site ID
 *
 * @param {Object}  state   Global state tree
 * @param {Number}  siteId  A site ID
 * @return {?String}        Menus admin URL
 */
export default function getMenusUrl( state, siteId ) {
	if ( ! canCurrentUser( state, siteId, 'edit_theme_options' ) ) {
		return null;
	}

	if ( isJetpackSite( state, siteId ) ) {
		return getSiteAdminUrl( state, siteId, 'customize.php' ) + '?autofocus[panel]=nav_menus';
	}
	// The Customizer's Menus panel shouldn't be available to users who haven't verified their
	// email yet, so send them to the top-level Customizer where they will (maybe?) see that Menus
	// are not available to them yet. See https://github.com/Automattic/wp-calypso/pull/13017
	if ( ! isCurrentUserEmailVerified( state ) ) {
		return '/customize/' + getSiteSlug( state, siteId );
	}

	return '/customize/menus/' + getSiteSlug( state, siteId );
}
Beispiel #18
0
export function getThemesLastPageForQuery( state, siteId, query ) {
	if ( ! state.themes.queries[ siteId ] ) {
		return null;
	}

	const pages = state.themes.queries[ siteId ].getNumberOfPages( query );
	if ( null === pages ) {
		return null;
	}

	// No pagination on Jetpack sites -- everything is returned at once, i.e. on one page
	if ( isJetpackSite( state, siteId ) ) {
		return 1;
	}

	return Math.max( pages, 1 );
}
Beispiel #19
0
function canDeleteSite( state, siteId ) {
	const canManageOptions = canCurrentUser( state, siteId, 'manage_options' );

	if ( ! siteId || ! canManageOptions ) {
		// Current user doesn't have manage options to delete the site
		return false;
	}

	if ( isJetpackSite( state, siteId ) && ! isSiteAutomatedTransfer( state, siteId ) ) {
		// Current user can't delete a Jetpack site, but can request to delete an Atomic site
		return false;
	}

	if ( isVipSite( state, siteId ) ) {
		// Current user can't delete a VIP site
		return false;
	}

	return true;
}
Beispiel #20
0
function canDeleteSite( state, siteId ) {
	const canManageOptions = canCurrentUser( state, siteId, 'manage_options' );

	if ( ! siteId || ! canManageOptions ) {
		// Current user doesn't have manage options to delete the site
		return false;
	}

	if ( isJetpackSite( state, siteId ) ) {
		// Current user can't delete a jetpack site
		return false;
	}

	if ( isVipSite( state, siteId ) ) {
		// Current user can't delete a VIP site
		return false;
	}

	return true;
}
Beispiel #21
0
export function getThemeCustomizeUrl( state, themeId, siteId ) {
	const customizerUrl = getCustomizerUrl( state, siteId );

	if ( ! ( siteId && themeId ) || isThemeActive( state, themeId, siteId ) ) {
		return customizerUrl;
	}

	const separator = includes( customizerUrl, '?' ) ? '&' : '?';
	let identifier;

	if ( isJetpackSite( state, siteId ) ) {
		identifier = themeId;
	} else {
		const theme = getTheme( state, 'wpcom', themeId );
		if ( ! theme ) {
			return customizerUrl;
		}
		identifier = theme.stylesheet;
	}

	return customizerUrl + separator + 'theme=' + identifier;
}
Beispiel #22
0
export function getThemeDetailsUrl( state, themeId, siteId ) {
	if ( ! themeId ) {
		return null;
	}

	if (
		isJetpackSite( state, siteId ) &&
		! (
			config.isEnabled( 'manage/themes/details/jetpack' ) &&
			canJetpackSiteManage( state, siteId ) &&
			hasJetpackSiteJetpackThemesExtendedFeatures( state, siteId )
		)
	) {
		return getSiteOption( state, siteId, 'admin_url' ) + 'themes.php?theme=' + themeId;
	}

	let baseUrl = oldShowcaseUrl + themeId;
	if ( config.isEnabled( 'manage/themes/details' ) ) {
		baseUrl = `/theme/${ themeId }`;
	}

	return baseUrl + ( siteId ? `/${ getSiteSlug( state, siteId ) }` : '' );
}
Beispiel #23
0
			<PlansLanding
				context={ context }
				destinationType={ context.params.destinationType }
				interval={ context.params.interval }
				basePlansPath={ '/jetpack/connect/store' }
				url={ context.query.site }
			/>,
			document.getElementById( 'primary' ),
			context.store
		);
	},

	plansSelection( context ) {
		const state = context.store.getState();
		const siteId = getSelectedSiteId( state );
		const isJetpack = isJetpackSite( state, siteId );
		const analyticsPageTitle = 'Plans';
		const basePath = route.sectionify( context.path );
		const analyticsBasePath = basePath + '/:site';

		if ( ! isJetpack ) {
			return;
		}

		removeSidebar( context );

		// FIXME: Auto-converted from the Flux setTitle action. Please use <DocumentHead> instead.
		context.store.dispatch( setTitle( translate( 'Plans', { textOnly: true } ) ) );

		analytics.tracks.recordEvent( 'calypso_plans_view' );
		analytics.pageView.record( analyticsBasePath, analyticsPageTitle );
Beispiel #24
0
export function getThemePurchaseUrl( state, themeId, siteId ) {
	if ( isJetpackSite( state, siteId ) || ! isThemePremium( state, themeId ) ) {
		return null;
	}
	return `/checkout/${ getSiteSlug( state, siteId ) }/theme:${ themeId }`;
}
	state => getSites( state ).filter( site => isJetpackSite( state, site.ID ) ),
Beispiel #26
0
	hideForTheme: ( state, themeId, siteId, origin ) => (
		! isJetpackSite( state, siteId ) ||
		! config.isEnabled( 'manage/themes/upload' ) ||
		origin === 'wpcom' ||
		isThemeActive( state, themeId, siteId )
	)
Beispiel #27
0
/**
 * Returns true if site is Jetpack and has WooCommerce plugin set to active. Otherwise false
 *
 * @param  {Object}   state  Global state tree
 * @param  {Number}   siteId Site ID
 * @return {?Boolean}        Whether site is an Jetpack and has WooCommerce active
 */
export default function isSiteStore( state, siteId ) {
	return (
		isJetpackSite( state, siteId ) &&
		get( state, [ 'sites', 'items', siteId, 'options', 'woocommerce_is_active' ], null )
	);
}