Skip to content

Commit e0eb037

Browse files
committed
add ch support
1 parent 8683949 commit e0eb037

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

inc/admin.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function __construct() {
9595
add_action( 'init', [ $this, 'update_cloud_sites_default' ] );
9696
add_action( 'admin_init', [ $this, 'maybe_redirect' ] );
9797
add_action( 'admin_init', [ $this, 'init_no_script' ] );
98+
add_action( 'plugins_loaded', [ $this,'add_permission_policy' ] );
9899
if ( ! is_admin() && $this->settings->is_connected() && ! wp_next_scheduled( self::SYNC_CRON ) ) {
99100
wp_schedule_event( time() + 10, 'twicedaily', self::SYNC_CRON, [] );
100101
}
@@ -114,6 +115,27 @@ public function __construct() {
114115
add_filter( 'themeisle-sdk/survey/' . OPTML_PRODUCT_SLUG, [ $this, 'get_survey_metadata' ], 10, 2 );
115116
}
116117

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+
}
117139
/**
118140
* Function that purges the image cache for a specific file.
119141
*
@@ -1009,7 +1031,12 @@ public function generator() {
10091031
if ( ! $this->settings->is_enabled() ) {
10101032
return;
10111033
}
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 ) );
10131040
}
10141041

10151042
/**

0 commit comments

Comments
 (0)