@@ -95,6 +95,7 @@ public function __construct() {
95
95
add_action ( 'init ' , [ $ this , 'update_cloud_sites_default ' ] );
96
96
add_action ( 'admin_init ' , [ $ this , 'maybe_redirect ' ] );
97
97
add_action ( 'admin_init ' , [ $ this , 'init_no_script ' ] );
98
+ add_action ( 'plugins_loaded ' , [ $ this ,'add_permission_policy ' ] );
98
99
if ( ! is_admin () && $ this ->settings ->is_connected () && ! wp_next_scheduled ( self ::SYNC_CRON ) ) {
99
100
wp_schedule_event ( time () + 10 , 'twicedaily ' , self ::SYNC_CRON , [] );
100
101
}
@@ -114,6 +115,27 @@ public function __construct() {
114
115
add_filter ( 'themeisle-sdk/survey/ ' . OPTML_PRODUCT_SLUG , [ $ this , 'get_survey_metadata ' ], 10 , 2 );
115
116
}
116
117
118
+ /**
119
+ * Add the permission policy for CH.
120
+ *
121
+ * @return void
122
+ */
123
+ public function add_permission_policy () {
124
+ if ( ! $ this ->settings ->is_connected () ) {
125
+ return ;
126
+ }
127
+ if ( ! $ this ->settings ->is_enabled () ) {
128
+ return ;
129
+ }
130
+ if ( headers_sent () ) {
131
+ return ;
132
+ }
133
+ $ policy = 'ch-viewport-width=(self "%1$s") ' ;
134
+ if ( $ this ->settings ->get ( 'network_optimization ' ) === 'enabled ' ) {
135
+ $ policy .= ', ch-ect=(self "%1$s") ' ;
136
+ }
137
+ header ( sprintf ( 'Permissions-Policy: %s ' , sprintf ( $ policy , esc_url ( Optml_Config::$ service_url ) ) ), false );
138
+ }
117
139
/**
118
140
* Function that purges the image cache for a specific file.
119
141
*
@@ -1009,7 +1031,12 @@ public function generator() {
1009
1031
if ( ! $ this ->settings ->is_enabled () ) {
1010
1032
return ;
1011
1033
}
1012
- echo '<meta name="generator" content="Optimole ' . esc_attr ( OPTML_VERSION ) . '"> ' ;
1034
+
1035
+ $ hints = 'Viewport-Width ' ;
1036
+ if ( $ this ->settings ->get ( 'network_optimization ' ) === 'enabled ' ) {
1037
+ $ hints .= ', ECT ' ;
1038
+ }
1039
+ echo sprintf ( '<meta http-equiv="Accept-CH" content="%s" /> ' , esc_attr ( $ hints ) );
1013
1040
}
1014
1041
1015
1042
/**
0 commit comments