Skip to content

Commit fd06053

Browse files
committed
Add links to AMP compatible themes and plugins
1 parent 074f845 commit fd06053

File tree

5 files changed

+66
-22
lines changed

5 files changed

+66
-22
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Check if the provided URL is external.
3+
*
4+
* @param {string} url URL to be checked.
5+
* @return {boolean} True if the URL is external, false otherwise.
6+
*/
7+
export const isExternalUrl = ( url ) => global?.location?.host !== new URL( url ).host;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
import { isExternalUrl } from '../is-external-url';
5+
6+
describe( 'isExternalUrl', () => {
7+
it( 'should return true if of a URL is external and false otherwise', () => {
8+
expect( isExternalUrl( 'https://example.com/' ) ).toBe( true );
9+
expect( isExternalUrl( 'https://localhost/' ) ).toBe( false );
10+
} );
11+
} );

assets/src/components/site-scan-results/plugins-with-amp-incompatibility.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
*/
44
import PropTypes from 'prop-types';
55
import classnames from 'classnames';
6+
import { AMP_COMPATIBLE_PLUGINS_URL } from 'amp-settings'; // From WP inline script.
67

78
/**
89
* WordPress dependencies
910
*/
10-
import { __, sprintf } from '@wordpress/i18n';
11-
import { useMemo } from '@wordpress/element';
11+
import { __ } from '@wordpress/i18n';
12+
import { createInterpolateElement, useMemo } from '@wordpress/element';
13+
import { ExternalLink } from '@wordpress/components';
1214

1315
/**
1416
* Internal dependencies
1517
*/
1618
import { useNormalizedPluginsData } from '../plugins-context-provider/use-normalized-plugins-data';
1719
import { IconLaptopPlug } from '../svg/laptop-plug';
20+
import { isExternalUrl } from '../../common/helpers/is-external-url';
1821
import { SiteScanSourcesList } from './site-scan-sources-list';
1922
import { SiteScanResults } from './index';
2023

@@ -47,15 +50,24 @@ export function PluginsWithAmpIncompatibility( {
4750
{ ...props }
4851
>
4952
{ showHelpText && (
50-
<p
51-
dangerouslySetInnerHTML={ {
52-
__html: sprintf(
53-
// translators: placeholder stands for page anchors.
54-
__( 'Because of plugin issues we’ve uncovered, you may want to <a href="%s">review and suppress plugins</a>.', 'amp' ),
55-
'#template-modes',
56-
),
57-
} }
58-
/>
53+
<p>
54+
{ createInterpolateElement(
55+
__( 'Because of plugin issues we’ve uncovered, you may want to <a>review and suppress plugins</a>.', 'amp' ),
56+
{
57+
// eslint-disable-next-line jsx-a11y/anchor-has-content -- Anchor has content defined in the translated string.
58+
a: <a href="#plugin-suppression" />,
59+
},
60+
) }
61+
{ AMP_COMPATIBLE_PLUGINS_URL ? createInterpolateElement(
62+
` ${ __( 'You may also want to browse <a>AMP compatible plugins</a>.', 'amp' ) }`,
63+
{
64+
a: isExternalUrl( AMP_COMPATIBLE_PLUGINS_URL )
65+
? <ExternalLink href={ AMP_COMPATIBLE_PLUGINS_URL } />
66+
// eslint-disable-next-line jsx-a11y/anchor-has-content -- Anchor has content defined in the translated string.
67+
: <a href={ AMP_COMPATIBLE_PLUGINS_URL } />,
68+
},
69+
) : '' }
70+
</p>
5971
) }
6072
<SiteScanSourcesList
6173
sources={ sources }

assets/src/components/site-scan-results/themes-with-amp-incompatibility.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
*/
44
import PropTypes from 'prop-types';
55
import classnames from 'classnames';
6+
import { AMP_COMPATIBLE_THEMES_URL } from 'amp-settings'; // From WP inline script.
67

78
/**
89
* WordPress dependencies
910
*/
10-
import { __, sprintf } from '@wordpress/i18n';
11-
import { useMemo } from '@wordpress/element';
11+
import { __ } from '@wordpress/i18n';
12+
import { createInterpolateElement, useMemo } from '@wordpress/element';
13+
import { ExternalLink } from '@wordpress/components';
1214

1315
/**
1416
* Internal dependencies
1517
*/
1618
import { useNormalizedThemesData } from '../themes-context-provider/use-normalized-themes-data';
1719
import { IconWebsitePaintBrush } from '../svg/website-paint-brush';
20+
import { isExternalUrl } from '../../common/helpers/is-external-url';
1821
import { SiteScanSourcesList } from './site-scan-sources-list';
1922
import { SiteScanResults } from './index';
2023

@@ -47,15 +50,24 @@ export function ThemesWithAmpIncompatibility( {
4750
{ ...props }
4851
>
4952
{ showHelpText && (
50-
<p
51-
dangerouslySetInnerHTML={ {
52-
__html: sprintf(
53-
// translators: placeholder stands for page anchors.
54-
__( 'Because of theme issues we’ve found, you’ll want to switch your template mode. Please see <a href="%s">template mode recommendations</a> below.', 'amp' ),
55-
'#template-modes',
56-
),
57-
} }
58-
/>
53+
<p>
54+
{ createInterpolateElement(
55+
__( 'Because of theme issues we’ve found, you’ll want to switch your template mode. Please see <a>template mode recommendations</a> below.', 'amp' ),
56+
{
57+
// eslint-disable-next-line jsx-a11y/anchor-has-content -- Anchor has content defined in the translated string.
58+
a: <a href="#template-modes" />,
59+
},
60+
) }
61+
{ AMP_COMPATIBLE_THEMES_URL ? createInterpolateElement(
62+
` ${ __( 'You may also want to browse <a>AMP compatible themes</a>.', 'amp' ) }`,
63+
{
64+
a: isExternalUrl( AMP_COMPATIBLE_THEMES_URL )
65+
? <ExternalLink href={ AMP_COMPATIBLE_THEMES_URL } />
66+
// eslint-disable-next-line jsx-a11y/anchor-has-content -- Anchor has content defined in the translated string.
67+
: <a href={ AMP_COMPATIBLE_THEMES_URL } />,
68+
},
69+
) : '' }
70+
</p>
5971
) }
6072
<SiteScanSourcesList
6173
sources={ sources }

src/Admin/OptionsMenu.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ public function enqueue_assets( $hook_suffix ) {
236236
);
237237

238238
$js_data = [
239+
'AMP_COMPATIBLE_THEMES_URL' => current_user_can( 'install_themes' ) ? admin_url( '/theme-install.php?browse=amp-compatible' ) : 'https://amp-wp.org/ecosystem/themes/',
240+
'AMP_COMPATIBLE_PLUGINS_URL' => current_user_can( 'install_plugins' ) ? admin_url( '/plugin-install.php?tab=amp-compatible' ) : 'https://amp-wp.org/ecosystem/plugins/',
239241
'AMP_QUERY_VAR' => amp_get_slug(),
240242
'AMP_SCAN_IF_STALE' => QueryVar::AMP_SCAN_IF_STALE,
241243
'CURRENT_THEME' => [

0 commit comments

Comments
 (0)