__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
/**
* External dependencies
*/
import { isAtomicSite, isSimpleSite } from '@automattic/jetpack-shared-extension-utils';
import debugFactory from 'debug';
const initialState = window?.JP_CONNECTION_INITIAL_STATE;
const debug = debugFactory( 'jetpack-ai-assistant:connection' );
let hasCheckedConnection = false;
const debugOnce = content => {
if ( ! hasCheckedConnection ) {
debug( content );
hasCheckedConnection = true;
}
};
/**
* Return the initial connection status.
*
* @returns {boolean} true if the user is connected, false otherwise.
*/
export function isUserConnected(): boolean {
if ( isSimpleSite() ) {
debugOnce( 'Simple site connected ✅' );
return true;
}
if ( isAtomicSite() ) {
debugOnce( 'Atomic site connected ✅' );
return true;
}
if ( initialState?.connectionStatus?.isUserConnected ) {
debugOnce( 'Jetpack user is connected ✅' );
return true;
}
debugOnce( 'User is not connected ❌' );
return false;
}
export function canUserPurchasePlan(): boolean {
if ( isSimpleSite() ) {
// Roles on simple sites can't be inferred from the connection status.
return true;
}
const permissions =
initialState?.userConnectionData?.currentUser?.permissions ??
( {} as { manage_options?: boolean } );
return ! permissions.manage_options === false;
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| index.ts | File | 1.28 KB | 0644 |
|