Skip to content

Commit d9b373e

Browse files
committed
more check on PHP side
1 parent 3729247 commit d9b373e

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

includes/LinkPrefetch/LinkPrefetch.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ class LinkPrefetch {
3838
*/
3939
public static $option_name = 'nfd_link_prefetch_settings';
4040

41+
/**
42+
* Site capabilities for link prefetch Click.
43+
*
44+
* @var bool
45+
*/
46+
public static $has_link_prefetch_click = false;
47+
48+
/**
49+
* Site capabilities for link prefetch Hover.
50+
*
51+
* @var bool
52+
*/
53+
public static $has_link_prefetch_hover = false;
54+
4155
/**
4256
* Default settings.
4357
*
@@ -62,11 +76,12 @@ public function __construct( Container $container ) {
6276
$this->container = $container;
6377

6478
$capabilities = new SiteCapabilities();
65-
$clickEnbaled = $capabilities->get( 'hasLinkPrefetchClick' );
66-
$hoverEnbaled = $capabilities->get( 'hasLinkPrefetchHover' );
6779

68-
if ( ! $clickEnbaled && ! $hoverEnbaled ) {
69-
update_option( self::$option_name, self::$default_settings );
80+
$this::$has_link_prefetch_click = $capabilities->get( 'hasLinkPrefetchClick' );
81+
$this::$has_link_prefetch_hover = $capabilities->get( 'hasLinkPrefetchHover' );
82+
83+
if ( ! $this::$has_link_prefetch_click && ! $this::$has_link_prefetch_hover ) {
84+
delete_option( self::$option_name );
7085
return;
7186
}
7287

@@ -85,6 +100,9 @@ public function __construct( Container $container ) {
85100
* @return array Modified runtime object.
86101
*/
87102
public function add_to_runtime( $sdk ) {
103+
104+
self::$default_settings['behavior'] = $this::$has_link_prefetch_click && $this::$has_link_prefetch_hover ? 'mouseHover' : 'mouseDown';
105+
88106
$values = array(
89107
'settings' => get_option( self::$option_name, self::$default_settings ),
90108
);

0 commit comments

Comments
 (0)