update_post_meta( '248304', '_product_image_gallery', '');
WordPress Poedit 如何排除 text domain
如果你的佈景主題有用到別的程式,其中包含翻譯文字,而你又不希望這個 text domain 出現在你的翻譯檔中,可以在 Poedit 中排除。
使用 Poedit 打開你的 pot 檔,透過上方 [翻譯] -> [屬性] 選單來打開設定介面。點擊 [原始程式碼路徑],在下方有排除的路徑,點擊 + 號來選擇你要排除的檔案或路徑。

如何避免 git pull 產生不必要的 merge commit
之前跟別人協作的時候,使用 git pull 並 commit 後會產生額外的 merge 訊息。

這是因為其實 git pull 這個動作是包含了 git fetch 和 git merge
如果你不希望產生額外的 merge commit,可以透過 rebase 來處理
git pull --rebase origin main
上面的指令,其實結合了 git fetch 和 git rebase,會將我們 local 的 commit 放在遠端 commit 的前面
git fetch
git rebase origin main
參考資料
https://gitbook.tw/chapters/github/pull-from-github
https://coderwall.com/p/jgn6-q/git-pull-is-evil
https://dev.to/mliakos/don-t-git-pull-use-git-pull-rebase-instead-5b8k
VS Code Intelephense 無法辨識 WordPress 函式
PHP Intelephense 是 VS Code 中相當熱門的一個擴充,讓 VS Code 可以更接近 PHPStorm 具有 IDE (Integrated Development Environment) 的功能。
當在開發 WordPress 的時候,可能會遇到 VS Code 無法辨識 WordPress 函式的狀況。

你可以開啟設定,然然找到 Intelephense: Stubs 這個設定,將 WordPress 加入,重新啟動 VS Code 就可以了。

PHP 在瀏覽器中顯示 PDF
如果要直接在瀏覽器中顯示 PDF,請把 Content-Disposition 改成 inline。
如果要下載 PDF,則將 Content-Disposition 改為 attachment
Elementor 宣布裁員 15% 的員工
才在上週宣佈收購 Strattic 的 Elementor,宣布裁員 60 位員工,大約是 15% 的員工。大多數屬於行銷部門,工程部門並不受影響。
消息來源:https://en.globes.co.il/en/article-elementor-begins-laying-off-15-of-workforce-1001415176
WordPress/WooCommerce 分類排序
WordPress 分類排序
方法1: 在 wp_terms 資料表新增一個欄位來記錄排序
這個外掛會新增一個 term_order 的欄位來記錄排序
這個外掛也是新增一個 term_order 的欄位來記錄排序
WooCommerce 商品分類排序

//woocommerce/includes/class-wc-ajax.php
term_ordering
wc_reorder_terms
//woocommerce/includes/wc-term-functions.php
wc_reorder_terms
wc_set_term_order
update_term_meta( $term_id, ‘order’, $index );
woocommerce 是用 order 這個 meta key 來記錄 term 的排序,記錄在 wp_termmeta 資料表
Elementor 收購 Strattic
Elementor 在 6/8 宣佈收購了同樣來自以色列的公司 Strattic。 Strattic 主要提供靜態化 (Static) 和 Headless WordPress 的主機服務。
這幾年在 WordPress 生態圈出現了許多收購,特別是由主機商的收購,各家主機商好像在搞軍備競賽似的,收購了許多大大小小的外掛,來加強自己在生態圈的優勢。例如 Godaddy、WPEngine、Liquidweb 皆收購了不少 WordPress 生態圈的外掛。而這次 Elementor 收購了 Strattic 則是相當有趣地由外掛方發起的收購,也因此引起了大家的好奇心和注意。
而事實上 Elementor 也在今年推出了自家的主機託管服務 Cloud Website,除了提供主機託管服務外,也內建了 Elementor Pro 外掛的授權。相信在未來 Elementor 和 Strattic 會有更多的整合,提供給使用 Elementor 架站的使用者更優質的託管服務和架站體驗。
參考資料:
plugin_loaded v.s plugins_loaded
WordPress 有兩個 action 可以在外掛啟用時執行,分別是 plugin_loaded 和 plugins_loaded,差一個 s ,使用上可別搞錯了。
plugin_loaded
當某一個特定啟用的外掛載入時執行
使用方式:do_action( ‘plugin_loaded’, string $plugin )
plugins_loaded
當所有啟用的外掛載入時執行
使用方式:do_action( ‘plugins_loaded’ )
wp_script_is
函式:wp_script_is( string $handle, string $list = ‘enqueued’ )
說明:https://developer.wordpress.org/reference/functions/wp_script_is/
功能:判斷script是否有被加入到佇列中
範例
if ( ! wp_script_is( 'my-script' ) ) {
wp_enqueue_script( 'my-script', PLUGIN_PATH . 'script.js', array( 'jquery' ), '1.0.0' );
}