├── LICENSE
├── README.md
├── notifier.xml
└── update-notifier.php
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011 João Araújo (http://themeforest.net/user/unisphere)
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is furnished
8 | to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WordPress Theme Update Notifier
2 |
3 | This is a simple WordPress theme update notifier that will provide your theme Buyers with a notification every time you issue a theme update.
4 |
5 | It's a very simple script that requires and assumes you have an XML file in your own server. This XML file serves as an endpoint for the script to check what the latest version of the theme is, and compares it with the current version of the theme installed in the Client's server.
6 |
7 | One of the script **requirements** is that the version number are **floats**. Versions like 1.0, 1.1, 2.3 are acceptable and required.
8 |
9 | ## Installation
10 |
11 | Upload the **notifier.xml** file to your own server (the update notifier on the Client sites will check this file for the latest version)
12 |
13 | Copy the **update-notifier.php** file to the root of the theme.
14 |
15 | Edit your theme's **functions.php** file and include the **update-notifier.php** file with the following code:
16 |
17 | require('update-notifier.php');
18 |
19 | Edit the **update-notifier.php** file and make the appropriate changes to the following constants:
20 |
21 | define( 'NOTIFIER_THEME_NAME', 'JohnDoe' ); // The theme name
22 | define( 'NOTIFIER_THEME_FOLDER_NAME', 'johndoe' ); // The theme folder name
23 | define( 'NOTIFIER_XML_FILE', 'http://www.yourdomain.com/johndoe/notifier.xml' ); // The remote notifier XML file containing the latest version of the theme and changelog
24 | define( 'NOTIFIER_CACHE_INTERVAL', 21600 ); // The time interval for the remote XML cache in the database (21600 seconds = 6 hours)
25 |
26 | Everything should be in place now. Every time you submit a theme update you should edit the XML file in your server and change the following code to the latest version you've updated:
27 |
28 | 1.0
29 |
30 | This way, your Clients will see an update notification on the WordPress admin panel informing them that there's a new version available and they should update.
31 |
32 | **NOTE:** when you submit theme updates make sure to update the theme version number in the **style.css** file. This file is in the root of your theme and the "Version" is the value used for comparison.
33 |
34 | ## Screenshot
35 |
36 | 
37 |
--------------------------------------------------------------------------------
/notifier.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1.0
4 |
5 | Version 1.0
7 |
8 | - Initial theme version.
9 |
10 | ]]>
11 |
12 |
--------------------------------------------------------------------------------
/update-notifier.php:
--------------------------------------------------------------------------------
1 | latest > (float)$theme_data['Version']) { // Compare current theme version with the remote XML version
30 | add_dashboard_page( NOTIFIER_THEME_NAME . ' Theme Updates', NOTIFIER_THEME_NAME . ' New Updates', 'administrator', 'theme-update-notifier', 'update_notifier');
31 | }
32 | }
33 | }
34 | add_action('admin_menu', 'update_notifier_menu');
35 |
36 |
37 |
38 | // Adds an update notification to the WordPress 3.1+ Admin Bar
39 | function update_notifier_bar_menu() {
40 | if (function_exists('simplexml_load_string')) { // Stop if simplexml_load_string funtion isn't available
41 | global $wp_admin_bar, $wpdb;
42 |
43 | if ( !is_super_admin() || !is_admin_bar_showing() ) // Don't display notification in admin bar if it's disabled or the current user isn't an administrator
44 | return;
45 |
46 | $xml = get_latest_theme_version(NOTIFIER_CACHE_INTERVAL); // Get the latest remote XML file on our server
47 | $theme_data = get_theme_data(TEMPLATEPATH . '/style.css'); // Read theme current version from the style.css
48 |
49 | if( (float)$xml->latest > (float)$theme_data['Version']) { // Compare current theme version with the remote XML version
50 | $wp_admin_bar->add_menu( array( 'id' => 'update_notifier', 'title' => '' . NOTIFIER_THEME_NAME . ' New Updates', 'href' => get_admin_url() . 'index.php?page=theme-update-notifier' ) );
51 | }
52 | }
53 | }
54 | add_action( 'admin_bar_menu', 'update_notifier_bar_menu', 1000 );
55 |
56 |
57 |
58 | // The notifier page
59 | function update_notifier() {
60 | $xml = get_latest_theme_version(NOTIFIER_CACHE_INTERVAL); // Get the latest remote XML file on our server
61 | $theme_data = get_theme_data(TEMPLATEPATH . '/style.css'); // Read theme current version from the style.css ?>
62 |
63 |
68 |
69 |
70 |
71 |
72 |
Theme Updates
73 |
There is a new version of the theme available. You have version installed. Update to version latest; ?>.
74 |
75 |
 . '/screenshot.png'; ?>)
76 |
77 |
78 |
Update Download and Instructions
79 |
Please note: make a backup of the Theme inside your WordPress installation folder /wp-content/themes//
80 |
To update the Theme, login to ThemeForest, head over to your downloads section and re-download the theme like you did when you bought it.
81 |
Extract the zip's contents, look for the extracted theme folder, and after you have all the new files upload them using FTP to the /wp-content/themes// folder overwriting the old ones (this is why it's important to backup any changes you've made to the theme files).
82 |
If you didn't make any changes to the theme files, you are free to overwrite them with the new ones without the risk of losing theme settings, pages, posts, etc, and backwards compatibility is guaranteed.
83 |
84 |
85 |
Changelog
86 | changelog; ?>
87 |
88 |
89 |
90 | $interval) ) {
104 | // cache doesn't exist, or is old, so refresh it
105 | if( function_exists('curl_init') ) { // if cURL is available, use it...
106 | $ch = curl_init($notifier_file_url);
107 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
108 | curl_setopt($ch, CURLOPT_HEADER, 0);
109 | curl_setopt($ch, CURLOPT_TIMEOUT, 10);
110 | $cache = curl_exec($ch);
111 | curl_close($ch);
112 | } else {
113 | $cache = file_get_contents($notifier_file_url); // ...if not, use the common file_get_contents()
114 | }
115 |
116 | if ($cache) {
117 | // we got good results
118 | update_option( $db_cache_field, $cache );
119 | update_option( $db_cache_field_last_updated, time() );
120 | }
121 | // read from the cache file
122 | $notifier_data = get_option( $db_cache_field );
123 | }
124 | else {
125 | // cache file is fresh enough, so read from it
126 | $notifier_data = get_option( $db_cache_field );
127 | }
128 |
129 | // Let's see if the $xml data was returned as we expected it to.
130 | // If it didn't, use the default 1.0 as the latest version so that we don't have problems when the remote server hosting the XML file is down
131 | if( strpos((string)$notifier_data, '') === false ) {
132 | $notifier_data = '1.0';
133 | }
134 |
135 | // Load the remote XML data into a variable and return it
136 | $xml = simplexml_load_string($notifier_data);
137 |
138 | return $xml;
139 | }
140 |
141 | ?>
--------------------------------------------------------------------------------