welcome-notice.js: the dismiss callback is sent as POST data, and `attr( 'disabled', true )` warns on WordPress 7.2

未關閉 適合新手
#122 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
1/5
預估耗時
1 小時以內
新手友好度
92/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
javascript, jquery
領域
frontend

研究方向

開啟 assets/js/src/welcome-notice.js:關閉請求建構於第 61–65 行附近,安裝按鈕在第 48 行附近被停用。將 success: hideAndRemoveNotice 從 $.post 資料物件中移出,並用 .done( hideAndRemoveNotice ) 附加,然後將 installBtn.attr( 'disabled', true ) 改為 .prop( 'disabled', true )。若要驗證,請在開啟 SCRIPT_DEBUG 的情況下載入歡迎通知並關閉它,檢查通知僅在請求成功後消失,以及點擊 Install & Activate Otter Blocks 時 jQuery Migrate 不再發出警告。

由索引模型根據 Issue 內容生成。

描述

What's wrong

Two small problems in assets/js/src/welcome-notice.js. Neither breaks the notice today.

  1. Dismiss. Lines 61–65:

    $.post( ajaxUrl, {
    	nonce,
    	action: 'fork_dismiss_welcome_notice',
    	success: hideAndRemoveNotice,
    } );
    

    success is inside the data object, not passed as a callback. When jQuery serializes data it calls any function it finds, so hideAndRemoveNotice() runs immediately when the request is built, and the request carries an empty success= field. As a result, the notice disappears even if the dismissal is not saved (for example after an expired nonce), and then comes back on the next page load. Found by reading the code.

  2. Disabled button. Line 48, installBtn.attr( 'disabled', true );. With SCRIPT_DEBUG on, WordPress 7.2's jQuery Migrate 3.6 logs JQMIGRATE: Boolean attribute 'disabled' is not set to its lowercased name when Install & Activate Otter Blocks is clicked. Seen on 7.2-RC2; the install still completes. WordPress plans to move to jQuery 4 in 7.3.

Suggested fix
$.post( ajaxUrl, { nonce, action: 'fork_dismiss_welcome_notice' } ).done( hideAndRemoveNotice );

and installBtn.prop( 'disabled', true );.

主要語言
PHP
星號
0
分支
0
平均合併
1 小時 2 分鐘
30 天內合併 PR
5

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Codeinwp/fork 的其他 Issue

查看 Codeinwp/fork 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。