搜尋
首頁CMS教程&#&按增強您的主題:整合 Envato WordPress 工具包插件

增强您的主题:集成 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。

  1. 下載 TGM 外掛程式啟動並將主類別腳本放入主題中的 inc 資料夾中。路徑應為:mytheme/inc/class-tgm-plugin-activation.php
  2. #接下來,下載 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 外掛,那麼您應該會看到與此類似的通知:

增强您的主题:集成 Envato WordPress 工具包插件


#結論

從我們現在所掌握的情況來看,我們實際上可以停止該系列,您的用戶將能夠從管理員內部更新主題;但是,用戶只有在 Toolkit 管理面板中才能看到更新。

本教學的第 2 部分將教您如何整合 Envato WordPress 工具包庫,以及如何在 ThemeForest 中出現主題更新時顯示管理通知。

#

以上是增強您的主題:整合 Envato WordPress 工具包插件的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
我可以在3天內學習WordPress嗎?我可以在3天內學習WordPress嗎?Apr 09, 2025 am 12:16 AM

能在三天內學會WordPress。 1.掌握基礎知識,如主題、插件等。 2.理解核心功能,包括安裝和工作原理。 3.通過示例學習基本和高級用法。 4.了解調試技巧和性能優化建議。

WordPress是CMS嗎?WordPress是CMS嗎?Apr 08, 2025 am 12:02 AM

WordPress是內容管理系統(CMS)。它提供內容管理、用戶管理、主題和插件功能,支持創建和管理網站內容。其工作原理包括數據庫管理、模板系統和插件架構,適用於從博客到企業網站的各種需求。

WordPress有什麼用?WordPress有什麼用?Apr 07, 2025 am 12:06 AM

wordpressgood forvortalyanewebprojectDuetoItsAsatilityAsacms.itexcelsin:1)用戶友好性,允許Aeserywebsitesetup; 2)sexibility andcustomized andcustomization and numerthemesandplugins; 3)seoop timigimization; and4)and4)

我應該使用Wix或WordPress嗎?我應該使用Wix或WordPress嗎?Apr 06, 2025 am 12:11 AM

Wix適合沒有編程經驗的用戶,WordPress適合希望有更多控制和擴展能力的用戶。 1)Wix提供拖放式編輯器和豐富模板,易於快速搭建網站。 2)WordPress作為開源CMS,擁有龐大社區和插件生態,支持深度自定義和擴展。

WordPress的成本是多少?WordPress的成本是多少?Apr 05, 2025 am 12:13 AM

WordPress本身免費,但使用需額外費用:1.WordPress.com提供從免費到付費的套餐,價格從每月幾美元到幾十美元不等;2.WordPress.org需購買域名(每年10-20美元)和託管服務(每月5-50美元);3.插件和主題多數免費,付費的價格在幾十到幾百美元之間;通過選擇合適的託管服務、合理使用插件和主題、定期維護和優化,可以有效控制和優化WordPress的成本。

WordPress仍然免費嗎?WordPress仍然免費嗎?Apr 04, 2025 am 12:06 AM

WordPress核心版本是免費的,但使用過程中可能產生其他費用。 1.域名和託管服務需要付費。 2.高級主題和插件可能需要付費。 3.專業服務和高級功能可能需要付費。

對於初學者來說,WordPress容易嗎?對於初學者來說,WordPress容易嗎?Apr 03, 2025 am 12:02 AM

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

為什麼有人會使用WordPress?為什麼有人會使用WordPress?Apr 02, 2025 pm 02:57 PM

人們選擇使用WordPress是因為其強大和靈活性。 1)WordPress是一個開源的CMS,易用性和可擴展性強,適合各種網站需求。 2)它有豐富的主題和插件,生態系統龐大,社區支持強大。 3)WordPress的工作原理基於主題、插件和核心功能,使用PHP和MySQL處理數據,支持性能優化。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。