增強您的主題:整合 Envato WordPress 工具包插件
身為 ThemeForest 中的 WordPress 作者,我們希望透過偶爾為客戶提供錯誤修復和主題增強功能來讓他們滿意。但我們面臨的一個關鍵問題是如何在有更新可供下載時通知我們的用戶。
在過去,我們每個人都必須在自己的主題更新通知程式實作中進行編碼。雖然現在有一個複選框可以啟用 Envato 市場中的項目更新通知,但用戶仍然必須針對每個項目打開它,並手動執行主題更新。
如果更新通知顯示在 WordPress 管理中心內不是更好嗎?並且可以在管理員中立即執行更新嗎?幸運的是,我們現在擁有 Envato WordPress 工具包外掛和工具包庫。
在本系列中,您將學習如何將這些工具包整合到您的主題中。
我們將在本系列中介紹什麼內容
在本教程中,我們將在我們的主題中實作 Envato WordPress 工具包外掛程式和函式庫。當我們的主題被啟動時,用戶將被要求安裝並啟動 Toolkit 外掛。
一旦外掛程式處於活動狀態,我們的主題將定期檢查更新,如果發現更新,則會在管理中顯示一則通知,引導使用者存取外掛程式以更新主題。
本教學分為兩部分:
- 第 1 部分 - 整合 TGM 外掛啟動類,使使用我們的主題時需要 Envato WordPress Toolkit 外掛;和
- 第 2 部分 - 在我們的主題中實作 Envato WordPress 工具包庫,以允許新的主題版本檢查和更新。
外掛程式和函式庫?
Envato WordPress 工具包有兩種形式,有不同的用途和目的。為了避免混淆這兩者,這裡有一個比較:
- 工具包外掛程式 - 這是一個獨立的插件,任何 Envato 客戶都可以在其 WordPress 網站中安裝。啟動後,所有先前購買的主題以及主題更新都可以直接從管理員下載。
- 工具包庫 - 作者可以在其 WordPress 主題中包含程式碼,使主題能夠使用 Envato Marketplace API 檢查主題版本更新並進行自我更新。
1.包含所需的檔案
我們首先需要在專案中包含一些文件。我們將把 Toolkit 外掛程式與我們的主題捆綁在一起,並使用 TGM 外掛程式啟動來安裝和啟動 Toolkit。
- 下載 TGM 外掛程式啟動並將主類別腳本放入主題中的 inc 資料夾中。路徑應為:mytheme/inc/class-tgm-plugin-activation.php
- #接下來,下載 Envato WordPress Toolkit 外掛程式 ZIP 檔案並將其放入主題中名為「plugins」的新資料夾中。路徑應為:mytheme/plugins/envato-wordpress-toolkit-master.zip
注意:您可以更改上述文件的位置以滿足您的需求。 或者,您可以從本文頂部的下載連結下載完整原始碼。
2.TGM鉤子函數
現在我們已經有了所需的文件,讓我們開始編碼。我們需要在 functions.php 中包含 TGM 外掛程式啟動類,並掛鉤到自訂 WordPress 操作。我們將在此處設置 TGM 的一些設置,並定義要包含的插件。
/** * Load the TGM Plugin Activator class to notify the user * to install the Envato WordPress Toolkit Plugin */ require_once( get_template_directory() . '/inc/class-tgm-plugin-activation.php' ); function tgmpa_register_toolkit() { // Code here } add_action( 'tgmpa_register', 'tgmpa_register_toolkit' );
3.指定Toolkit外掛
#接下來,我們配置包含 Toolkit 外掛所需的參數。在 tgmpa_register_toolkit
函數內,加入以下程式碼。如果您在第 1 步驟中指定了另一個外掛程式資料夾,請變更來源參數中的路徑。
// Specify the Envato Toolkit plugin $plugins = array( array( 'name' => 'Envato WordPress Toolkit', 'slug' => 'envato-wordpress-toolkit-master', 'source' => get_template_directory() . '/plugins/envato-wordpress-toolkit-master.zip', 'required' => true, 'version' => '1.5', 'force_activation' => true, 'force_deactivation' => false, 'external_url' => '', ), );
您也可以透過在 $plugins
變數新增更多陣列來新增其他外掛程式。
4.配置TGM
然後設定 TGM 的選項。同樣在 tgmpa_register_toolkit
函數中,在上一步下方加入以下程式碼來設定 TGM。我不會深入探討各個設定的具體作用。如果您想了解有關這些設定的更多信息,TGM 插件啟動網站可以很好地解釋每一個細節。
// i18n text domain used for translation purposes $theme_text_domain = 'default'; // Configuration of TGM $config = array( 'domain' => $theme_text_domain, 'default_path' => '', 'parent_menu_slug' => 'admin.php', 'parent_url_slug' => 'admin.php', 'menu' => 'install-required-plugins', 'has_notices' => true, 'is_automatic' => true, 'message' => '', 'strings' => array( 'page_title' => __( 'Install Required Plugins', $theme_text_domain ), 'menu_title' => __( 'Install Plugins', $theme_text_domain ), 'installing' => __( 'Installing Plugin: %s', $theme_text_domain ), 'oops' => __( 'Something went wrong with the plugin API.', $theme_text_domain ), 'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.' ), 'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.' ), 'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.' ), 'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.' ), 'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.' ), 'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.' ), 'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.' ), 'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.' ), 'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins' ), 'activate_link' => _n_noop( 'Activate installed plugin', 'Activate installed plugins' ), 'return' => __( 'Return to Required Plugins Installer', $theme_text_domain ), 'plugin_activated' => __( 'Plugin activated successfully.', $theme_text_domain ), 'complete' => __( 'All plugins installed and activated successfully. %s', $theme_text_domain ), 'nag_type' => 'updated' ) );
將 $theme_text_domain
變數變更為您正在使用的文字網域,或將其保留為 default
。
5.啟動TGM
最後,讓我們在 tgmpa_register_toolkit
函數結束之前初始化 TGM。
tgmpa( $plugins, $config );
現在儲存您的functions.php
#嘗試一下
嘗試啟動您的主題。如果您尚未安裝或啟動 Envato WordPress Toolkit 外掛,那麼您應該會看到與此類似的通知:
#結論
從我們現在所掌握的情況來看,我們實際上可以停止該系列,您的用戶將能夠從管理員內部更新主題;但是,用戶只有在 Toolkit 管理面板中才能看到更新。
本教學的第 2 部分將教您如何整合 Envato WordPress 工具包庫,以及如何在 ThemeForest 中出現主題更新時顯示管理通知。
以上是增強您的主題:整合 Envato WordPress 工具包插件的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

博客是人們在網上表達觀點、意見和見解的理想平台。許多新手渴望建立自己的網站,卻因擔心技術障礙或成本問題而猶豫不決。然而,隨著平台不斷發展以滿足初學者的能力和需求,現在開始變得比以往任何時候都更容易。 本文將逐步指導您如何建立一個WordPress博客,從主題選擇到使用插件提升安全性和性能,助您輕鬆創建自己的網站。 選擇博客主題和方向 在購買域名或註冊主機之前,最好先確定您計劃涵蓋的主題。個人網站可以圍繞旅行、烹飪、產品評論、音樂或任何激發您興趣的愛好展開。專注於您真正感興趣的領域可以鼓勵持續寫作

有四種方法可以調整 WordPress 文章列表:使用主題選項、使用插件(如 Post Types Order、WP Post List、Boxy Stuff)、使用代碼(在 functions.php 文件中添加設置)或直接修改 WordPress 數據庫。

您想了解如何在父分類存檔頁面上顯示子分類嗎?在自定義分類存檔頁面時,您可能需要執行此操作,以使其對訪問者更有用。在本文中,我們將向您展示如何在父分類存檔頁面上輕鬆顯示子分類。為什麼在父分類存檔頁面上顯示子分類?通過在父分類存檔頁面上顯示所有子分類,您可以使其不那麼通用,對訪問者更有用。例如,如果您運行一個關於書籍的WordPress博客,並且有一個名為“主題”的分類法,那麼您可以添加“小說”、“非小說”等子分類法,以便您的讀者可以

最近,我們向您展示瞭如何通過允許用戶將自己喜歡的帖子保存在個性化庫中來為用戶創建個性化體驗。您可以通過在某些地方(即歡迎屏幕)使用他們的名字,將個性化結果提升到另一個水平。幸運的是,WordPress使獲取登錄用戶的信息變得非常容易。在本文中,我們將向您展示如何檢索與當前登錄用戶相關的信息。我們將利用get_currentuserinfo(); 功能。這可以在主題中的任何地方使用(頁眉、頁腳、側邊欄、頁面模板等)。為了使其工作,用戶必須登錄。因此我們需要使用

WordPress對初學者來說容易上手。 1.登錄後台後,用戶界面直觀,簡潔的儀表板提供所有必要功能鏈接。 2.基本操作包括創建和編輯內容,所見即所得的編輯器簡化了內容創建。 3.初學者可以通過插件和主題擴展網站功能,學習曲線存在但可以通過實踐掌握。

過去,我們分享過如何使用PostExpirator插件使WordPress中的帖子過期。好吧,在創建活動列表網站時,我們發現這個插件非常有用。我們可以輕鬆刪除過期的活動列表。其次,多虧了這個插件,按帖子過期日期對帖子進行排序也非常容易。在本文中,我們將向您展示如何在WordPress中按帖子過期日期對帖子進行排序。更新了代碼以反映插件中更改自定義字段名稱的更改。感謝Tajim在評論中讓我們知道。在我們的特定項目中,我們將事件作為自定義帖子類型。現在

我們的一位用戶詢問其他網站如何在頁腳中顯示查詢數量和頁面加載時間。您經常會在網站的頁腳中看到這一點,它可能會顯示類似以下內容:“1.248秒內64個查詢”。在本文中,我們將向您展示如何在WordPress中顯示查詢數量和頁面加載時間。只需將以下代碼粘貼到主題文件中您喜歡的任何位置(例如footer.php)。 queriesin

您是否正在尋找自動化 WordPress 網站和社交媒體帳戶的方法? 通過自動化,您將能夠在 Facebook、Twitter、LinkedIn、Instagram 等平台上自動分享您的 WordPress 博客文章或更新。 在本文中,我們將向您展示如何使用 IFTTT、Zapier 和 Uncanny Automator 輕鬆實現 WordPress 和社交媒體的自動化。 為什麼要自動化 WordPress 和社交媒體? 自動化您的WordPre
