415 posts
  • Has referred 10+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
unisphere says



Here’s my modified code and some instructions, based off of what João (unisphere) had provided:
  1. You’ll need to include the update_notifier.php into your functions.php file.
  2. Open up notifier.xml, change line 3 to reflect the latest version number of your theme, make necessary updates to the changelog.
  3. Upload this to a spot on your server.
  4. Open up update_notifier.php > find line 57 > point this to the notifier.xml file you uploaded in step 3

That’s it, if the user has a version of your theme that is lower than whats on line 3 of the notifier.xml they’ll get the notification in their admin.

NOTE : This compares the version number from line 3 in notifier.xml to the version number in style.css of your theme. So make sure these are up to date. Thanks again to João for the original code!
Sir – you are awesome and I nominate you for one of those forum badges all the kids love ;)
You’re too kind, maybe me and João can split the star ;)

Now we’re talking :D

I’m glad you all appreciate this feature, had a lot of fun coding it :)

368 posts plop
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has been part of the Envato Community for over 5 years
  • Made it to the Authors' Hall of Fame
+8 more
kimonothemes says

This is awesome! Thanks a lot guys :)

194 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 100+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
digitonik says

A BIG thanks for this!!!!! You both are awesome! :bigsmile:

342 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 1+ items on Envato Market
+5 more
reidknorr says

Hey Guys,

Thank you so much, this is a great feature that will be extremely useful in my upcoming wordpress theme. :)

194 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 100+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
digitonik says

If anyone wants to add the instructions to the php file add the below lines starting on line 5 of the code under the credits to João. Just added this to my copy.

 *****************************************************************************************************
 *****************************************************************************************************
 ** Install Instructions
 **
 **
 ** 1. You'll need to include the update_notifier.php into your functions.php file.
 ** 2. Open up notifier.xml, change line 3 to reflect the latest version number of your theme, make necessary updates to the changelog.
 ** 3. Upload this to a spot on your server.
 ** 4. Open up update_notifier.php > find line 57 > point this to the notifier.xml file you uploaded in step 3
 **
 ** That's it, if the user has a version of your theme that is lower than whats on line 3 of the notifier.xml they'll get the notification in their admin.
 **
 ** NOTE : This compares the version number from line 3 in notifier.xml to the version number in style.css of your theme. So make sure these are up to date.
 *****************************************************************************************************
 *****************************************************************************************************
256 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Won a competition
+5 more
der says

Thanks a lot for sharing the code, some people might benefit from that!. First off, my apologies for such a long comment (almost looks like a tutorial lmao!) :P

I thought some people would have some ideas with the way I deal with the update notifications, and decided on sharing the way I do it :)

First thing, I have coded a plugin, which is deeply integrated with my framework. The plugin just stores a list of my themes. The themes then connect to he update server (which is running the plugin), and receive encoded data from the server, containing the versioning information of the theme.

Every time I update one of my themes, I just need to log into my update server, and update the version information. The themes will then read that data, live.

The update server, contains information about the themes you create. You could create your own plugin, which contains your own theme options. The information I store about the themes is the following:

  • Theme Name (matching the theme name in style.css)
  • Theme Version
  • ThemeForest product page URL
  • Live Preview URL

At the beginning, I made it so each time the user entered the admin, the theme checked for new updates. This is not so efficient, since the theme would be creating lots of connections to the update server, when there is no need.

I then decided to use Cookies (using the jQuery Cookie Plugin). Here’s how you do it:

  1. Check for the encoded version data, store it in a cookie
  2. Set the cookie to expire in any amount of time (e.g. 24 hours)

After the theme has checked the version, it will display the update notification without having to connect to the update server every time (since it’s reading the cookie data). In my case, I do it without making a lot of noise:

You could create a WordPress plugin, which stores the information about the themes you have created, such as name, version, url, message etc. Enable the plugin on a wordpress site (or update server) dedicated only to the theme updates (excellent if you use Multisite).

The theme would provide a query string to your site, for example:

http://update.themeforest-author.com?theme=MyCoolTheme

Then, the server could reply with some base64 encoded data, which the theme will decode and read. You could then cache the encoded server response into the cookie.

For example, the server could provide the following base64 encoded reply:

YTozOntzOjc6InZlcnNpb24iOoiaHR0cDovL3RoZW1lZm9yZXN0

Which, after decoded, would be a PHP array, like the following:

Array
(
    [theme] => My Theme
    [live_preview] => http://themeforest.net/item/theme
    [version] => 1.0.3
)

After the theme has read the information, it will determine if it needs to show the update notification, based on a comparison between the actual version number, and the one retrieved from the update server.

Ah, I almost forget: You can do version checks directly in PHP using the normal comparison. For example:

'1.0.1' > '1.0.0';  // returns true
'1.2.1' > '1.5.3'; // returns false

When encoding the data (on the server), make sure to base64 encode it, after serializing the array:

base64_encode(serialize($data));

When receiving the data (on the client), make sure to unserialize and then base64 decode the string:

unserialize(base64_decode($encoded_data));

Have in mind, that if you use cookies, make sure that the cookie name depends on the actual theme name. This will make sure that if the user tries multiple of your themes on the same server, the updates will be tracked independently. For example:

cool-theme_version_data = ...
awesome-theme_version_data = ...

And that’s it!, just my 2 cents!

Ernie.-

751 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
CyberShot says

thanks for sharing the code guys. I will use this for sure

54 posts
  • Has referred 500+ members
  • Has sold $500,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
GhostPool says

Excellent, thanks for posting it.

I’m having some weird issues with it though. On some of my themes it works without any issues on others I get error messages like this. I don’t know if it’s relating to an initial error in the xml file that has been cached, but I’ve tried to change the caching from 6 hours to 1 second temporarily and it didn’t fix the issue. Any help would be appreciated.

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 4: parser error : AttValue: " or ' expected in /home/ghostpool/ghostpool.com/wordpress/reviewit/wp-content/themes/reviewit/lib/admin/inc/theme-update-notification.php on line 92

Warning: simplexml_load_string() [function.simplexml-load-string]: <meta charset="UTF-8" /> in /home/ghostpool/ghostpool.com/wordpress/reviewit/wp-content/themes/reviewit/lib/admin/inc/theme-update-notification.php on line 92

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/ghostpool/ghostpool.com/wordpress/reviewit/wp-content/themes/reviewit/lib/admin/inc/theme-update-notification.php on line 92
415 posts
  • Has referred 10+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
unisphere says

Excellent, thanks for posting it.

I’m having some weird issues with it though. On some of my themes it works without any issues on others I get error messages like this. I don’t know if it’s relating to an initial error in the xml file that has been cached, but I’ve tried to change the caching from 6 hours to 1 second temporarily and it didn’t fix the issue. Any help would be appreciated.

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 4: parser error : AttValue: " or ' expected in /home/ghostpool/ghostpool.com/wordpress/reviewit/wp-content/themes/reviewit/lib/admin/inc/theme-update-notification.php on line 92

Warning: simplexml_load_string() [function.simplexml-load-string]: <meta charset="UTF-8" /> in /home/ghostpool/ghostpool.com/wordpress/reviewit/wp-content/themes/reviewit/lib/admin/inc/theme-update-notification.php on line 92

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/ghostpool/ghostpool.com/wordpress/reviewit/wp-content/themes/reviewit/lib/admin/inc/theme-update-notification.php on line 92

Hey Ghost, make sure that your XML file is well-formed, particularly where you set your own custom HTML . Those errors seem to indicate that the XML cannot be properly parsed due to errors.

54 posts
  • Has referred 500+ members
  • Has sold $500,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
GhostPool says

That crossed my mind. I have multiple WordPress sites on the same domain, on some of the WP installation the XML does not cause a problem, on others it does. Here is the code I’m using:

<?xml version="1.0" encoding="UTF-8"?>
<notifier>
    <latest>2.3</latest>
    <changelog>
        <![CDATA[
            Changelog
        ]]>
    </changelog>
</notifier>
by
by
by
by
by
by