目录
我们将在本系列中介绍什么内容
插件和库?
尝试一下
结论
首页 CMS教程 &#&按 增强您的主题:集成 Envato WordPress 工具包插件

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

Sep 04, 2023 pm 12:13 PM

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

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

对于初学者来说,WordPress容易吗? 对于初学者来说,WordPress容易吗? Apr 03, 2025 am 12:02 AM

WordPress对初学者来说容易上手。1.登录后台后,用户界面直观,简洁的仪表板提供所有必要功能链接。2.基本操作包括创建和编辑内容,所见即所得的编辑器简化了内容创建。3.初学者可以通过插件和主题扩展网站功能,学习曲线存在但可以通过实践掌握。

如何开始WordPress博客:初学者的分步指南 如何开始WordPress博客:初学者的分步指南 Apr 17, 2025 am 08:25 AM

博客是人们在网上表达观点、意见和见解的理想平台。许多新手渴望建立自己的网站,却因担心技术障碍或成本问题而犹豫不决。然而,随着平台不断发展以满足初学者的能力和需求,现在开始变得比以往任何时候都更容易。 本文将逐步指导您如何建立一个WordPress博客,从主题选择到使用插件提升安全性和性能,助您轻松创建自己的网站。 选择博客主题和方向 在购买域名或注册主机之前,最好先确定您计划涵盖的主题。个人网站可以围绕旅行、烹饪、产品评论、音乐或任何激发您兴趣的爱好展开。专注于您真正感兴趣的领域可以鼓励持续写作

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)

我可以在3天内学习WordPress吗? 我可以在3天内学习WordPress吗? Apr 09, 2025 am 12:16 AM

能在三天内学会WordPress。1.掌握基础知识,如主题、插件等。2.理解核心功能,包括安装和工作原理。3.通过示例学习基本和高级用法。4.了解调试技巧和性能优化建议。

我应该使用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 02, 2025 pm 02:57 PM

人们选择使用WordPress是因为其强大和灵活性。1)WordPress是一个开源的CMS,易用性和可扩展性强,适合各种网站需求。2)它有丰富的主题和插件,生态系统庞大,社区支持强大。3)WordPress的工作原理基于主题、插件和核心功能,使用PHP和MySQL处理数据,支持性能优化。

See all articles