Table of Contents
What we will cover in this series
Plug-ins and libraries?
try it
in conclusion
Home CMS Tutorial WordPress Enhance your theme: Integrate the Envato WordPress Toolkit plugin

Enhance your theme: Integrate the Envato WordPress Toolkit plugin

Sep 04, 2023 pm 12:13 PM

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

As WordPress authors in ThemeForest, we hope to keep our customers happy by providing them with occasional bug fixes and theme enhancements. But a key issue we faced was how to notify our users when an update was available for download.

In the past, we each had to code in our own implementation of the theme update notifier. While there is now a checkbox to enable project update notifications in the Envato Marketplace, users still have to turn it on for each project and perform theme updates manually.

Wouldn’t it be better if update notifications were displayed in the WordPress admin center? And can the update be performed immediately in the admin? Luckily, we now have the Envato WordPress toolkit plugin and toolkit library.

In this series, you will learn how to integrate these toolkits into your theme.


What we will cover in this series

In this tutorial we will implement the Envato WordPress Toolkit plugin and library into our theme. When our theme is activated, users will be asked to install and activate the Toolkit plugin.

Once the plugin is active, our theme will periodically check for updates and if an update is found, a notification will be displayed in the admin directing the user to the plugin to update the theme.

This tutorial is divided into two parts:

  • Part 1 - Integrate the TGM plugin activation class so that using our theme requires the Envato WordPress Toolkit plugin; and
  • Part 2 - Implementing the Envato WordPress Toolkit library in our theme to allow new theme version checking and updating.

Plug-ins and libraries?

The Envato WordPress toolkit comes in two flavors with different uses and purposes. To avoid confusing the two, here's a comparison:

  • Toolkit Plugin - This is a standalone plugin that any Envato customer can install in their WordPress site. Upon activation, all previously purchased themes as well as theme updates can be downloaded directly from the administrator.
  • Toolkit Library - Authors can include code in their WordPress themes that enables the theme to check for theme version updates and update itself using the Envato Marketplace API.

1.Include required files

We first need to include some files in the project. We will bundle the Toolkit plugin with our theme and use TGM plugin activation to install and activate the Toolkit.

  1. Download the TGM plug-in activation and put the main class script into the inc folder in the theme. The path should be: mytheme/inc/class-tgm-plugin-activation.php
  2. Next, download the Envato WordPress Toolkit plugin ZIP file and place it into a new folder called “plugins” in your theme. The path should be: mytheme/plugins/envato-wordpress-toolkit-master.zip

NOTE: You can change the location of the above files to suit your needs. Alternatively, you can download the full source code from the download link at the top of this article.


2.TGM hook function

Now that we have the required files, let's start coding. We need to include the TGM plugin activation class in functions.php and hook into the custom WordPress action. Here we will set up some settings for the TGM and define the plugins to include.

/**
 * 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' );
Copy after login

3.Specify Toolkit plug-in

Next, we configure the parameters required to include the Toolkit plug-in. Inside the tgmpa_register_toolkit function, add the following code. If you specified another plugin folder in Step 1, change the path in the source parameter.

// 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' => '',
	),
);
Copy after login

You can also add additional plugins by adding more arrays to the $plugins variable.


4.Configure TGM

Then set the TGM options. Also in the tgmpa_register_toolkit function, add the following code below the previous step to configure the TGM. I won’t go into the specifics of what each setting does. If you want to learn more about these settings, the TGM Plugin Activation website does a great job explaining every detail.

// 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'
	)
);
Copy after login

Change the $theme_text_domain variable to the text domain you are using, or leave it as default.


5.Start TGM

Finally, let's initialize the TGM before the tgmpa_register_toolkit function ends.

tgmpa( $plugins, $config );
Copy after login

Now save your functions.php


try it

Try activating your theme. If you haven't installed or activated the Envato WordPress Toolkit plugin, you should see a notification similar to this:

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


in conclusion

From what we know now, we can actually stop the series and your users will be able to update themes from within the admin; however, users will only see updates in the Toolkit admin panel.

Part 2 of this tutorial will teach you how to integrate the Envato WordPress Toolkit library and how to display admin notifications when theme updates occur in ThemeForest.

The above is the detailed content of Enhance your theme: Integrate the Envato WordPress Toolkit plugin. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is WordPress easy for beginners? Is WordPress easy for beginners? Apr 03, 2025 am 12:02 AM

WordPress is easy for beginners to get started. 1. After logging into the background, the user interface is intuitive and the simple dashboard provides all the necessary function links. 2. Basic operations include creating and editing content. The WYSIWYG editor simplifies content creation. 3. Beginners can expand website functions through plug-ins and themes, and the learning curve exists but can be mastered through practice.

What is the WordPress good for? What is the WordPress good for? Apr 07, 2025 am 12:06 AM

WordPressisgoodforvirtuallyanywebprojectduetoitsversatilityasaCMS.Itexcelsin:1)user-friendliness,allowingeasywebsitesetup;2)flexibilityandcustomizationwithnumerousthemesandplugins;3)SEOoptimization;and4)strongcommunitysupport,thoughusersmustmanageper

Can I learn WordPress in 3 days? Can I learn WordPress in 3 days? Apr 09, 2025 am 12:16 AM

Can learn WordPress within three days. 1. Master basic knowledge, such as themes, plug-ins, etc. 2. Understand the core functions, including installation and working principles. 3. Learn basic and advanced usage through examples. 4. Understand debugging techniques and performance optimization suggestions.

Should I use Wix or WordPress? Should I use Wix or WordPress? Apr 06, 2025 am 12:11 AM

Wix is ​​suitable for users who have no programming experience, and WordPress is suitable for users who want more control and expansion capabilities. 1) Wix provides drag-and-drop editors and rich templates, making it easy to quickly build a website. 2) As an open source CMS, WordPress has a huge community and plug-in ecosystem, supporting in-depth customization and expansion.

How much does WordPress cost? How much does WordPress cost? Apr 05, 2025 am 12:13 AM

WordPress itself is free, but it costs extra to use: 1. WordPress.com offers a package ranging from free to paid, with prices ranging from a few dollars per month to dozens of dollars; 2. WordPress.org requires purchasing a domain name (10-20 US dollars per year) and hosting services (5-50 US dollars per month); 3. Most plug-ins and themes are free, and the paid price ranges from tens to hundreds of dollars; by choosing the right hosting service, using plug-ins and themes reasonably, and regularly maintaining and optimizing, the cost of WordPress can be effectively controlled and optimized.

How To Begin A WordPress Blog: A Step-By-Step Guide For Beginners How To Begin A WordPress Blog: A Step-By-Step Guide For Beginners Apr 17, 2025 am 08:25 AM

Blogs are the ideal platform for people to express their opinions, opinions and opinions online. Many newbies are eager to build their own website but are hesitant to worry about technical barriers or cost issues. However, as the platform continues to evolve to meet the capabilities and needs of beginners, it is now starting to become easier than ever. This article will guide you step by step how to build a WordPress blog, from theme selection to using plugins to improve security and performance, helping you create your own website easily. Choose a blog topic and direction Before purchasing a domain name or registering a host, it is best to identify the topics you plan to cover. Personal websites can revolve around travel, cooking, product reviews, music or any hobby that sparks your interests. Focusing on areas you are truly interested in can encourage continuous writing

Is WordPress still free? Is WordPress still free? Apr 04, 2025 am 12:06 AM

The core version of WordPress is free, but other fees may be incurred during use. 1. Domain names and hosting services require payment. 2. Advanced themes and plug-ins may be charged. 3. Professional services and advanced features may be charged.

Why would anyone use WordPress? Why would anyone use WordPress? Apr 02, 2025 pm 02:57 PM

People choose to use WordPress because of its power and flexibility. 1) WordPress is an open source CMS with strong ease of use and scalability, suitable for various website needs. 2) It has rich themes and plugins, a huge ecosystem and strong community support. 3) The working principle of WordPress is based on themes, plug-ins and core functions, and uses PHP and MySQL to process data, and supports performance optimization.

See all articles