| 1 |
/** |
| 2 |
* Defines the structure of a Content Intelligence Permissions object. |
| 3 |
* |
| 4 |
* @since 3.16.0 |
| 5 |
*/ |
| 6 |
export interface ContentHelperPermissions { |
| 7 |
ExcerptSuggestions: boolean; |
| 8 |
SmartLinking: boolean; |
| 9 |
TitleSuggestions: boolean; |
| 10 |
TrafficBoost: boolean; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Returns the current user's permissions for Content Intelligence. |
| 15 |
* |
| 16 |
* @since 3.16.0 |
| 17 |
* |
| 18 |
* @return {ContentHelperPermissions} The current user's permissions. |
| 19 |
*/ |
| 20 |
export function getContentHelperPermissions(): ContentHelperPermissions { |
| 21 |
const defaultPermissions: ContentHelperPermissions = { |
| 22 |
ExcerptSuggestions: false, |
| 23 |
SmartLinking: false, |
| 24 |
TitleSuggestions: false, |
| 25 |
TrafficBoost: false, |
| 26 |
}; |
| 27 |
|
| 28 |
try { |
| 29 |
const permissions = JSON.parse( window.wpParselyContentHelperPermissions ); |
| 30 |
|
| 31 |
if ( 'object' !== typeof permissions || null === permissions ) { |
| 32 |
return defaultPermissions; |
| 33 |
} |
| 34 |
|
| 35 |
return permissions; |
| 36 |
} catch ( e ) { |
| 37 |
return defaultPermissions; |
| 38 |
} |
| 39 |
} |
| 40 |
|