@@ -38,6 +38,20 @@ class LinkPrefetch {
38
38
*/
39
39
public static $ option_name = 'nfd_link_prefetch_settings ' ;
40
40
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
+
41
55
/**
42
56
* Default settings.
43
57
*
@@ -62,11 +76,12 @@ public function __construct( Container $container ) {
62
76
$ this ->container = $ container ;
63
77
64
78
$ capabilities = new SiteCapabilities ();
65
- $ clickEnbaled = $ capabilities ->get ( 'hasLinkPrefetchClick ' );
66
- $ hoverEnbaled = $ capabilities ->get ( 'hasLinkPrefetchHover ' );
67
79
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 );
70
85
return ;
71
86
}
72
87
@@ -85,6 +100,9 @@ public function __construct( Container $container ) {
85
100
* @return array Modified runtime object.
86
101
*/
87
102
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
+
88
106
$ values = array (
89
107
'settings ' => get_option ( self ::$ option_name , self ::$ default_settings ),
90
108
);
0 commit comments