WordPress如何識(shí)別Windows11評(píng)論
Windows11是Windows10的換皮,useragent值中的版本號(hào)Windows版本號(hào)還是Windows NT 10,所以,評(píng)論插件全部翻車。
在Chrome 95以后的內(nèi)核后,可以通過(guò)JS的方式,來(lái)識(shí)別Windows版本。
詳情查看:微軟官方說(shuō)明
navigator.userAgentData.getHighEntropyValues(["platformVersion"])
.then(ua => {
if (navigator.userAgentData.platform === "Windows") {
const majorPlatformVersion = parseInt(ua.platformVersion.split('.')[0]);
if (majorPlatformVersion >= 13) {
console.log("Windows 11 or later");
}
else if (majorPlatformVersion > 0) {
console.log("Windows 10");
}
else {
console.log("Before Windows 10");
}
}
else {
console.log("Not running on Windows");
}
});
但是,就算是JS識(shí)別到了,也沒法修改客戶端UA啊
所以,這兒給一個(gè)方法,給評(píng)論添加一個(gè)隱藏表單,內(nèi)容自定義。添加鉤子:preprocess_comment
可以獲取到表單的內(nèi)容,并且識(shí)別他,然后把UA改成Windows NT 11.0版本,這樣就能正常顯示W(wǎng)indows11了。效果如下圖所示。
版權(quán)聲明:
作者:applek
鏈接:http://m.aaigroup.cn/wordpressrhsbwindows11pl.html
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載。
THE END