{"id":3388,"date":"2017-02-01T10:18:06","date_gmt":"2017-02-01T09:18:06","guid":{"rendered":"https:\/\/en.florianbrinkmann.de\/?p=3388"},"modified":"2020-02-09T10:59:57","modified_gmt":"2020-02-09T09:59:57","slug":"automatic-updates-for-wordpress-themes-which-are-not-in-the-theme-directory","status":"publish","type":"post","link":"https:\/\/florianbrinkmann.com\/en\/automatic-updates-for-wordpress-themes-which-are-not-in-the-theme-directory-3388\/","title":{"rendered":"Automatic updates for WordPress themes which are not in the theme directory"},"content":{"rendered":"\n
You can install automatic updates for themes from the WordPress.org directory. Here I show you how you can provide these automatic updates for themes, which are not in the directory.<\/p>\n\n\n\n\n\n\n\n
Update from February 9, 2017<\/strong>: This solution does not work for multisite installations.<\/p>\n<\/div>\n\n\n\n I did not want to dive into the subject of theme updates. My search for a solution for my shop guided me to the plugin WooCommerce API Manager<\/em><\/a>, which I used for a short while. From the beginning, I did not like the idea, that the users have to create an account on my site for getting automatic updates. After stumbling over a few problems with child themes and update notifications which appear twice, I searched for the reason in the plugin\u2019s code and WordPress core.<\/p>\n\n\n\n After some time I have not fixed all problems but understood how theme updates are working. So I created my own solution because I did not have many requirements.<\/p>\n\n\n\n I do not need to check in how many installations a bought theme is active because I do not limit the downloads. The following points should be fulfilled:<\/p>\n\n\n\n Before we continue with the solution, here comes a summary of how theme updates work in WordPress.<\/p>\n\n\n\n It is important for us that there is a transient If we decrease the version of Extant<\/em> manually, we get the following output (and an update notification in the backend):<\/p>\n\n\n The To notify WordPress about a theme update, you only have to insert the right information into the Our solution requires the following:<\/p>\n\n\n\n It does not matter, how this metadata page is created. You can just upload a static JSON file to your server and update it after releasing a new version. On my site, I have a custom post type for displaying the WordPress themes and their changelogs. The changelog is visible via appending a Update routine requirements<\/h2>\n\n\n\n
Procedure of theme updates in WordPress<\/h2>\n\n\n\n
update_themes<\/code> which stores information about the installed themes and available updates. The transient\u2019s content can look something like that when all themes are up to date:<\/p>\n\n\n
object(stdClass)#273 (4) {<\/span>\n [\"last_checked\"<\/span>]=>int(1485868202<\/span>)\n [\"checked\"<\/span>]=>array<\/span>(7<\/span>) {\n [\"extant\"<\/span>]=>string(5<\/span>) \"1.0.1\"<\/span>\n [\"rindby\"<\/span>]=>string(5<\/span>) \"1.1.3\"<\/span>\n [\"schlicht-child\/schlicht-child\"<\/span>]=>string(3<\/span>) \"1.0\"<\/span>\n [\"schlicht\"<\/span>]=>string(5<\/span>) \"1.0.4\"<\/span>\n [\"twentyfifteen\"<\/span>]=>string(3<\/span>) \"1.7\"<\/span>\n [\"twentyfourteen\"<\/span>]=>string(3<\/span>) \"1.9\"<\/span>\n [\"twentysixteen\"<\/span>]=>string(3<\/span>) \"1.3\"<\/span>\n }\n [\"response\"<\/span>]=>array<\/span>(0<\/span>) {\n }\n [\"translations\"<\/span>]=>array<\/span>(0<\/span>) {\n }\n}<\/code><\/div>Code language:<\/span> PHP<\/span> (<\/span>php<\/span>)<\/span><\/small><\/pre>\n\n\n
object(stdClass)#273 (4) {<\/span>\n [\"last_checked\"<\/span>]=>int(1485868693<\/span>)\n [\"checked\"<\/span>]=>array<\/span>(7<\/span>) {\n [\"extant\"<\/span>]=>string(3<\/span>) \"1.0\"<\/span>\n [\"rindby\"<\/span>]=>string(5<\/span>) \"1.1.3\"<\/span>\n [\"schlicht-child\/schlicht-child\"<\/span>]=>string(3<\/span>) \"1.0\"<\/span>\n [\"schlicht\"<\/span>]=>string(5<\/span>) \"1.0.4\"<\/span>\n [\"twentyfifteen\"<\/span>]=>string(3<\/span>) \"1.7\"<\/span>\n [\"twentyfourteen\"<\/span>]=>string(3<\/span>) \"1.9\"<\/span>\n [\"twentysixteen\"<\/span>]=>string(3<\/span>) \"1.3\"<\/span>\n }\n [\"response\"<\/span>]=>array<\/span>(1<\/span>) {\n [\"extant\"<\/span>]=>array<\/span>(4<\/span>) {\n [\"theme\"<\/span>]=>string(6<\/span>) \"extant\"<\/span>\n [\"new_version\"<\/span>]=>string(5<\/span>) \"1.0.1\"<\/span>\n [\"url\"<\/span>]=>string(36<\/span>) \"https:\/\/wordpress.org\/themes\/extant\/\"<\/span>\n [\"package\"<\/span>]=>string(54<\/span>) \"https:\/\/downloads.wordpress.org\/theme\/extant.1.0.1.zip\"<\/span>\n }\n }\n [\"translations\"<\/span>]=>array<\/span>(0<\/span>) {\n }\n}<\/code><\/div>Code language:<\/span> PHP<\/span> (<\/span>php<\/span>)<\/span><\/small><\/pre>\n\n\n
checked<\/code> version of
extant<\/code> now is
1.0<\/code> \u2013 the theme directory\u2019s version is
1.0.1<\/code>. Interesting is the
response<\/code> part, which stores information about the new version. There is an array with the theme slug as the key. Inside this array, there is another array with the following entries:<\/p>\n\n\n\n
theme<\/code> contains the theme slug again. As far as I can say, this is optional.<\/li>
new_version<\/code> contains the new version number.<\/li>
url<\/code> is a URL, which is displayed in the overlay after clicking View version 1.0.1 details<\/em> (optional).<\/li>
package<\/code> is the URL of the ZIP which contains the latest theme version (optional). If this is not set, the user will get an update notification without the update possibility.<\/li><\/ul>\n\n\n\n
response<\/code> array. Everything else is handled by the theme update routine of WordPress core. To modify the transient, there is the filter
pre_set_site_transient_update_themes<\/code>, and with that we are ready for the implementation.<\/p>\n\n\n\n
Implementation of the update script<\/h2>\n\n\n\n
new_version<\/code>.<\/li>
package<\/code>.<\/li>
pre_set_site_transient_update_themes<\/code> which checks for updates and modifies the transient, to kick off the update routine of WordPress.<\/li>
switch_theme<\/code> hook to remove the value of the customizer option, if neither the paid theme nor its child theme is active.<\/li><\/ul>\n\n\n\n
Creating metadata page<\/h3>\n\n\n\n
changelog\/<\/code> to the single view of a theme (for example the changelog of Schlicht<\/a>).<\/p>\n\n\n\n