0

0

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

王林

王林

发布时间:2023-09-04 12:13:01

|

1411人浏览过

|

来源于php中文网

原创

增强您的主题:集成 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 的一些设置,并定义要包含的插件。

Shakespeare
Shakespeare

一款人工智能文案软件,能够创建几乎任何类型的文案。

下载
/**
 * 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 中出现主题更新时显示管理通知。

WPS零基础入门到精通全套教程!
WPS零基础入门到精通全套教程!

全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等

下载

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
php文件怎么打开
php文件怎么打开

打开php文件步骤:1、选择文本编辑器;2、在选择的文本编辑器中,创建一个新的文件,并将其保存为.php文件;3、在创建的PHP文件中,编写PHP代码;4、要在本地计算机上运行PHP文件,需要设置一个服务器环境;5、安装服务器环境后,需要将PHP文件放入服务器目录中;6、一旦将PHP文件放入服务器目录中,就可以通过浏览器来运行它。

2687

2023.09.01

php怎么取出数组的前几个元素
php怎么取出数组的前几个元素

取出php数组的前几个元素的方法有使用array_slice()函数、使用array_splice()函数、使用循环遍历、使用array_slice()函数和array_values()函数等。本专题为大家提供php数组相关的文章、下载、课程内容,供大家免费下载体验。

1661

2023.10.11

php反序列化失败怎么办
php反序列化失败怎么办

php反序列化失败的解决办法检查序列化数据。检查类定义、检查错误日志、更新PHP版本和应用安全措施等。本专题为大家提供php反序列化相关的文章、下载、课程内容,供大家免费下载体验。

1522

2023.10.11

php怎么连接mssql数据库
php怎么连接mssql数据库

连接方法:1、通过mssql_系列函数;2、通过sqlsrv_系列函数;3、通过odbc方式连接;4、通过PDO方式;5、通过COM方式连接。想了解php怎么连接mssql数据库的详细内容,可以访问下面的文章。

953

2023.10.23

php连接mssql数据库的方法
php连接mssql数据库的方法

php连接mssql数据库的方法有使用PHP的MSSQL扩展、使用PDO等。想了解更多php连接mssql数据库相关内容,可以阅读本专题下面的文章。

1419

2023.10.23

html怎么上传
html怎么上传

html通过使用HTML表单、JavaScript和PHP上传。更多关于html的问题详细请看本专题下面的文章。php中文网欢迎大家前来学习。

1235

2023.11.03

PHP出现乱码怎么解决
PHP出现乱码怎么解决

PHP出现乱码可以通过修改PHP文件头部的字符编码设置、检查PHP文件的编码格式、检查数据库连接设置和检查HTML页面的字符编码设置来解决。更多关于php乱码的问题详情请看本专题下面的文章。php中文网欢迎大家前来学习。

1488

2023.11.09

php文件怎么在手机上打开
php文件怎么在手机上打开

php文件在手机上打开需要在手机上搭建一个能够运行php的服务器环境,并将php文件上传到服务器上。再在手机上的浏览器中输入服务器的IP地址或域名,加上php文件的路径,即可打开php文件并查看其内容。更多关于php相关问题,详情请看本专题下面的文章。php中文网欢迎大家前来学习。

1306

2023.11.13

PS使用蒙版相关教程
PS使用蒙版相关教程

本专题整合了ps使用蒙版相关教程,阅读专题下面的文章了解更多详细内容。

23

2026.01.19

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号