├── 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 plugin Update Notifier
2 |
3 | This is a simple WordPress plugin update notifier that will provide your plugin Buyers with a notification every time you issue a plugin 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 plugin is, and compares it with the current version of the plugin 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 plugin.
14 |
15 | Edit your plugin's main 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_PLUGIN_NAME', 'Your Plugin Name' ); // The plugin name
22 | define( 'NOTIFIER_PLUGIN_SHORT_NAME', 'ABC' ); // The plugin short name. Use this if your plugin has a long name and messes up the menu items. Otherwise remove it.
23 | define( 'NOTIFIER_PLUGIN_FOLDER_NAME', 'name-of-your-plugin-folder' ); // The plugin folder name
24 | define( 'NOTIFIER_PLUGIN_FILE_NAME', 'main-plugin-file.php' ); // The plugin's main file name
25 | define( 'NOTIFIER_XML_FILE', 'http://yoururl.com/updates/notifier.xml' ); // The remote notifier XML file containing the latest version of the plugin and changelog
26 | define( 'NOTIFIER_CACHE_INTERVAL', 21600 ); // The time interval for the remote XML cache in the database (21600 seconds = 6 hours)
27 |
28 | Everything should be in place now. Every time you submit a plugin update you should edit the XML file in your server and change the following code to the latest version you've updated:
29 |
30 | 1.0
31 |
32 | 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.
33 |
34 | **NOTE:** when you submit plugin updates make sure to update the plugin Version number in the top of the main plugin file.
35 |
--------------------------------------------------------------------------------
/notifier.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1.0
4 |
5 | Version 1.0
7 |
8 | - This is a line in the changelog
9 | - This is another line in the changelog
10 |
11 | ]]>
12 |
13 |
--------------------------------------------------------------------------------
/update-notifier.php:
--------------------------------------------------------------------------------
1 | latest > (string) $plugin_data['Version'] ) { // Compare current plugin version with the remote XML version
37 | if ( defined( 'XXX_NOTIFIER_PLUGIN_SHORT_NAME' ) ) {
38 | $menu_name = XXX_NOTIFIER_PLUGIN_SHORT_NAME;
39 | } else {
40 | $menu_name = XXX_NOTIFIER_PLUGIN_NAME;
41 | }
42 | add_dashboard_page( XXX_NOTIFIER_PLUGIN_NAME . ' Plugin Updates', $menu_name . ' New Updates', 'administrator', 'xxx-plugin-update-notifier', 'xxx_update_notifier');
43 | }
44 | }
45 | }
46 | add_action('admin_menu', 'xxx_update_plugin_notifier_menu');
47 |
48 |
49 |
50 | // Adds an update notification to the WordPress 3.1+ Admin Bar
51 | function xxx_update_notifier_bar_menu() {
52 | if ( function_exists( 'simplexml_load_string' ) ) { // Stop if simplexml_load_string funtion isn't available
53 | global $wp_admin_bar, $wpdb;
54 |
55 | 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
56 | return;
57 |
58 | $xml = xxx_get_latest_plugin_version( XXX_PLUGIN_NOTIFIER_CACHE_INTERVAL ); // Get the latest remote XML file on our server
59 | $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . XXX_NOTIFIER_PLUGIN_FOLDER_NAME . '/' .XXX_NOTIFIER_PLUGIN_FILE_NAME ); // Read plugin current version from the main plugin file
60 |
61 | if( (string) $xml->latest > (string) $plugin_data['Version'] ) { // Compare current plugin version with the remote XML version
62 | $wp_admin_bar->add_menu( array( 'id' => 'plugin_update_notifier', 'title' => '' . XXX_NOTIFIER_PLUGIN_NAME . ' New Updates', 'href' => get_admin_url() . 'index.php?page=xxx-plugin-update-notifier' ) );
63 | }
64 | }
65 | }
66 | add_action( 'admin_bar_menu', 'xxx_update_notifier_bar_menu', 1000 );
67 |
68 |
69 |
70 | // The notifier page
71 | function xxx_update_notifier() {
72 | $xml = xxx_get_latest_plugin_version( XXX_PLUGIN_NOTIFIER_CACHE_INTERVAL ); // Get the latest remote XML file on our server
73 | $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . XXX_NOTIFIER_PLUGIN_FOLDER_NAME . '/' .XXX_NOTIFIER_PLUGIN_FILE_NAME ); // Read plugin current version from the main plugin file ?>
74 |
75 |
80 |
81 |
82 |
83 |
84 |
Plugin Updates
85 |
There is a new version of the plugin available. You have version installed. Update to version latest; ?>.
86 |
87 |
88 |
Update Download and Instructions
89 |
Please note: make a backup of the Plugin inside your WordPress installation folder /wp-content/plugins//
90 |
To update the Plugin, login to CodeCanyon, head over to your downloads section and re-download the plugin like you did when you bought it.
91 |
Extract the zip's contents, look for the extracted plugin folder, and after you have all the new files upload them using FTP to the /wp-content/plugins// folder overwriting the old ones (this is why it's important to backup any changes you've made to the plugin files).
92 |
If you didn't make any changes to the plugin files, you are free to overwrite them with the new ones without the risk of losing any plugins settings, and backwards compatibility is guaranteed.
93 |
94 |
95 |
Changelog
96 | changelog; ?>
97 |
98 |
99 |
100 | $interval ) ) {
114 | // cache doesn't exist, or is old, so refresh it
115 | if( function_exists( 'curl_init' ) ) { // if cURL is available, use it...
116 | $ch = curl_init( $notifier_file_url );
117 | curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
118 | curl_setopt( $ch, CURLOPT_HEADER, 0 );
119 | curl_setopt( $ch, CURLOPT_TIMEOUT, 10 );
120 | $cache = curl_exec( $ch );
121 | curl_close( $ch );
122 | } else {
123 | $cache = file_get_contents( $notifier_file_url ); // ...if not, use the common file_get_contents()
124 | }
125 |
126 | if ( $cache ) {
127 | // we got good results
128 | update_option( $db_cache_field, $cache );
129 | update_option( $db_cache_field_last_updated, time() );
130 | }
131 | // read from the cache file
132 | $notifier_data = get_option( $db_cache_field );
133 | }
134 | else {
135 | // cache file is fresh enough, so read from it
136 | $notifier_data = get_option( $db_cache_field );
137 | }
138 |
139 | // Let's see if the $xml data was returned as we expected it to.
140 | // 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
141 | if( strpos( (string) $notifier_data, '' ) === false ) {
142 | $notifier_data = '1.0';
143 | }
144 |
145 | // Load the remote XML data into a variable and return it
146 | $xml = simplexml_load_string( $notifier_data );
147 |
148 | return $xml;
149 | }
150 |
--------------------------------------------------------------------------------