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.
- 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
- 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' );
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' => '', ), );
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' ) );
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 );
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:
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!

Do you want to move your blog from WordPress.com to WordPress.org? Many beginners start with WordPress.com but quickly realize their limitations and want to switch to the self-hosted WordPress.org platform. In this step-by-step guide, we will show you how to properly move your blog from WordPress.com to WordPress.org. Why migrate from WordPress.com to WordPress.org? WordPress.com allows anyone to create an account

Are you looking for ways to automate your WordPress website and social media accounts? With automation, you will be able to automatically share your WordPress blog posts or updates on Facebook, Twitter, LinkedIn, Instagram and more. In this article, we will show you how to easily automate WordPress and social media using IFTTT, Zapier, and Uncanny Automator. Why Automate WordPress and Social Media? Automate your WordPre

Just a few days ago, one of our users reported an unusual problem. The problem is that he reaches the limit of custom menu items. Any content he saves after reaching the menu item limit will not be saved at all. We've never heard of this issue, so we decided to give it a try on our local installation. More than 200 menu items were created and saved. The effect is very good. Move 100 items to the drop-down list and save them very well. Then we knew it had to do with the server. After further research, it seems that many others have encountered the same problem. After digging deeper, we found a trac ticket ( #14134 ) that highlighted this issue. Read very

Do you need to add custom metafields to custom taxonomy in WordPress? Custom taxonomy allows you to organize content besides categories and tags. Sometimes it is useful to add other fields to describe them. In this article, we will show you how to add other metafields to the taxonomy they create. When should custom metafields be added to custom taxonomy? When you create new content on your WordPress site, you can organize it using two default taxonomy (category and tag). Some websites benefit from the use of custom taxonomy. These allow you to sort content in other ways. For example,

Windows live writer is a versatile tool that allows you to post posts directly from your desktop to your WordPress blog. This means you don't need to log in to the WordPress admin panel to update your blog at all. In this tutorial, I will show you how to enable desktop publishing for your WordPress blog using Windows Live Writer. How to set up Windows Live Writer on WordPress Step 1: To use Windows Live Writer in WordPr

Recently, one of our users reported a very strange installation problem. When writing a post, they can’t see anything they write. Because the text in the post editor is white. What's more, all the visual editor buttons are missing, and the ability to switch from visual to HTML doesn't work either. In this article, we will show you how to fix the white text and missing button issues in the WordPress visual editor. Be a Beginner Note: If you are looking for hidden buttons that may be seen in screenshots of other websites, you may be looking for a kitchen sink. You have to click on the kitchen sink icon to see other options such as underline, copy from word, etc.

Do you want to display avatars in user emails in WordPress? Gravatar is a network service that connects a user's email address to an online avatar. WordPress automatically displays visitors’ profile pictures in the comments section, but you may also want to add them to other areas of the site. In this article, we will show you how to display avatars in user emails in WordPress. What is Gravatar and why should I display it? Gravatar stands for globally recognized avatars, which allows people to link images to their email addresses. If the website supports

Do you want to change the default media upload location in WordPress? Moving media files to other folders can improve website speed and performance and help you create backups faster. It also gives you the freedom to organize your files in the way that suits you best. In this article, we will show you how to change the default media upload location in WordPress. Why change the default media upload location? By default, WordPress stores all images and other media files in the /wp-content/uploads/ folder. In this folder you will find children of different years and months


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)