Skip to content

Commit 3729247

Browse files
committed
first commit - check for capabilities
1 parent 1b4b4a7 commit 3729247

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('lodash', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '126efbd4b855c1411ec8');
1+
<?php return array('dependencies' => array('lodash', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '8c1516cb1a7ac8c4b6bb');

build/performance/performance.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/LinkPrefetch/LinkPrefetch.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace NewfoldLabs\WP\Module\Performance\LinkPrefetch;
44

5+
use NewfoldLabs\WP\Module\Data\SiteCapabilities;
56
use NewfoldLabs\WP\ModuleLoader\Container;
67

78
/**
@@ -59,6 +60,16 @@ class LinkPrefetch {
5960
*/
6061
public function __construct( Container $container ) {
6162
$this->container = $container;
63+
64+
$capabilities = new SiteCapabilities();
65+
$clickEnbaled = $capabilities->get( 'hasLinkPrefetchClick' );
66+
$hoverEnbaled = $capabilities->get( 'hasLinkPrefetchHover' );
67+
68+
if ( ! $clickEnbaled && ! $hoverEnbaled ) {
69+
update_option( self::$option_name, self::$default_settings );
70+
return;
71+
}
72+
6273
add_filter( 'newfold-runtime', array( $this, 'add_to_runtime' ) );
6374
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
6475
if ( ! is_admin() ) {

src/components/App/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import ImageOptimization from '../../sections/ImageOptimization';
2222
import getAppText from './getAppText';
2323

2424
const App = () => {
25+
2526
const { title, description } = getAppText();
27+
const hasLinkPrefetchClick = NewfoldRuntime.hasCapability('hasLinkPrefetchClick');
28+
const hasLinkPrefetchHover = NewfoldRuntime.hasCapability('hasLinkPrefetchHover');
2629

2730
useEffect( () => {
2831
const brand = NewfoldRuntime.sdk?.plugin?.brand;
@@ -68,12 +71,14 @@ const App = () => {
6871
>
6972
<JetpackBoost />
7073
</Container.Block>
71-
<Container.Block
72-
separator
73-
className="newfold-link-prefetch"
74-
>
75-
<LinkPrefetch />
76-
</Container.Block>
74+
{ ( hasLinkPrefetchClick || hasLinkPrefetchHover ) && (
75+
<Container.Block
76+
separator
77+
className="newfold-link-prefetch"
78+
>
79+
<LinkPrefetch hasLinkPrefetchClick={hasLinkPrefetchClick} hasLinkPrefetchHover={hasLinkPrefetchHover}/>
80+
</Container.Block>
81+
) }
7782
<Container.Block className="newfold-image-optimization">
7883
<ImageOptimization />
7984
</Container.Block>

src/sections/LinkPrefetch/index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const useUpdateEffect = ( effect, deps ) => {
2626
}, deps );
2727
};
2828

29-
const LinkPrefetch = () => {
29+
const LinkPrefetch = ( { hasLinkPrefetchClick, hasLinkPrefetchHover } ) => {
3030
const {
3131
linkPrefetchTitle,
3232
linkPrefetchDescription,
@@ -149,14 +149,18 @@ const LinkPrefetch = () => {
149149
}
150150
className="nfd-mb-6"
151151
>
152-
<SelectField.Option
153-
label={ linkPrefetchBehaviorMouseHoverLabel }
154-
value="mouseHover"
155-
/>
156-
<SelectField.Option
157-
label={ linkPrefetchBehaviorMouseDownLabel }
158-
value="mouseDown"
159-
/>
152+
{ hasLinkPrefetchHover && (
153+
<SelectField.Option
154+
label={ linkPrefetchBehaviorMouseHoverLabel }
155+
value="mouseHover"
156+
/>
157+
)}
158+
{ hasLinkPrefetchClick && (
159+
<SelectField.Option
160+
label={ linkPrefetchBehaviorMouseDownLabel }
161+
value="mouseDown"
162+
/>
163+
) }
160164
</SelectField>
161165
) }
162166

0 commit comments

Comments
 (0)