亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WordPress 中的 PHP DOM - 在輸出緩沖區 HTML 中添加屬性

WordPress 中的 PHP DOM - 在輸出緩沖區 HTML 中添加屬性

PHP
揚帆大魚 2021-06-30 13:14:18
我要讓所有的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 回答

  • 1 回答
  • 0 關注
  • 192 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號