PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Notifications / notification-link.js

notification-link.js in Extendify 3.1.5, at src/Notifications/notification-link.js

26 lines 779 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // A partner-authored link can't know the customer's host at authoring time.
2 const withSiteHost = (link, host) => link?.replaceAll('{SITEURL}', host);
3
4 export const siteHost = () => {
5 try {
6 return new URL(window.extSharedData?.homeUrl ?? '').host;
7 } catch {
8 return '';
9 }
10 };
11
12 export const resolveNotificationLink = (notification, host = '') => {
13 const href = withSiteHost(notification?.link, host);
14 if (!href) return {};
15 try {
16 return { href, external: new URL(href).host !== host };
17 } catch {
18 // URL() throws on relative paths, which are never external.
19 return { href };
20 }
21 };
22
23 // `rel` travels with `target`, or the new tab keeps a handle back to wp-admin.
24 export const externalLinkProps = (external) =>
25 external ? { target: '_blank', rel: 'noreferrer' } : {};
26