我要讓所有的input產品和購物車頁面標簽帶班qty有type="number",并readonly="readonly"通過與PHP修改DOM屬性。當我將其限制為購物車和產品頁面時,它“僅”使延遲加載插件和自動優化插件停止為這兩個頁面工作,而其他頁面則很好。我也無法在管理頁面上發現任何控制臺錯誤。當我允許它為每個頁面運行時,會發生以下情況:產品和購物車頁面的控制臺中沒有錯誤。Ajax 請求將 Ajax 添加到購物車插件中斷。我收到多個控制臺錯誤,這些錯誤會破壞許多管理頁面的布局,移動和隱藏部分內容。這些輸出緩沖區修改感覺就像黑客攻擊導致的錯誤/不兼容。難道是因為libxml_use_internal_errors(true);它隱藏了警告并且實際上沒有解決任何問題?這是我的functions.php:add_action( 'template_redirect', 'acau_activate_buffer', 99999 );function acau_activate_buffer() { // cart and product page only, WooCommerce required for below line to work, remove to reproduce issues without WooCommerce if ( ! is_cart() && ! is_product() ) return; ob_start();}add_action('shutdown', function() { // cart and product page only, WooCommerce required for below line to work, remove to reproduce issues without WooCommerce if ( ! is_cart() && ! is_product() ) return; $final = ''; // Collect output from all previous buffers. $levels = ob_get_level(); for ($i = 0; $i < $levels; $i++) { $final .= ob_get_clean(); } echo apply_filters('acau_output', $final);}, -99999);// Filter final output.add_filter('acau_output', function($output) { $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML(mb_convert_encoding($output, 'HTML-ENTITIES', 'UTF-8')); foreach ($dom->getElementsByTagName('input') as $node) { $classes = explode (' ', $node->getAttribute('class') ); if ( in_array ( 'qty', $classes ) ) { $node->setAttribute('type', 'number'); $node->setAttribute('readonly', 'readonly'); } } $newHtml = $dom->saveHtml(); return $newHtml;});
- 1 回答
- 0 關注
- 192 瀏覽
添加回答
舉報
0/150
提交
取消