Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added better update message

  • Loading branch information...
commit d59362170a12788ace2caefb6131b0c1fa60fe16 1 parent c1b94a8
@franz-josef-kaiser franz-josef-kaiser authored
Showing with 74 additions and 2 deletions.
  1. +3 −1 changelog.txt
  2. +71 −1 plugin-dirs.php
View
4 changelog.txt
@@ -23,4 +23,6 @@ Renamed main plugin file to index.php to avoid accidental directory listing.
*0.7.3*
Reverted 0.7.2 to avoid plugin deactivation. Added index.html file instead.
*0.8*
-Moved Bootstrap to OOP construct. Regular child plugins are now allowed to use the default priority.
+Moved Bootstrap to OOP construct. Regular child plugins are now allowed to use the default priority.
+*0.9*
+Added better update message (as seen here).
View
72 plugin-dirs.php
@@ -4,7 +4,7 @@
Plugin Name: Additional Plugin Directories
Plugin URI: http://github.com/chrisguitarguy
Description: A framework to allow adding additional plugin directories to WordPress
-Version: 0.8
+Version: 0.9
Author: Christopher Davis
Contributors: Franz Josef Kaiser, Julien Chaumond
Author URI: http://christopherdavis.me
@@ -55,6 +55,16 @@ class CD_APD_Bootstrap
/**
+ * Used for update notices
+ * Fetches the readme file from the official plugin repo trunk.
+ * Adds to the "in_plugin_update_message-$file" hook
+ *
+ * @var (string)
+ */
+ public $remote_changelog = 'https://raw.github.com/chrisguitarguy/WP-Plugin-Directories/master/changelog.txt';
+
+
+ /**
* Creates a new static instance
*
* @since 0.8
@@ -96,6 +106,66 @@ public function __construct()
class_exists( $class ) AND add_action( 'plugins_loaded', array( $class, 'instance' ) );
}
+
+ // Better update message
+ $folder = basename( dirname( __FILE__ ) );
+ $file = basename( __FILE__ );
+ $hook = "in_plugin_update_message-{$folder}/{$file}";
+ add_action( $hook, array( $this, 'update_message' ), 20, 2 );
+ }
+
+
+ /**
+ * Displays an update message for plugin list screens.
+ * Shows only the version updates from the current until the newest version
+ *
+ * @uses WordPress HTTP API
+ *
+ * @since 0.9
+ * @param array $plugin_data Data of the plugin itself
+ * @param object $r Data of the remote request to the repo
+ * @return string The actual Output message
+ */
+ public function update_message( $plugin_data, $r )
+ {
+ if ( 'plugins.php' !== $GLOBALS['pagenow'] )
+ return;
+
+ // Get `changelog.txt` from GitHub via WP HTTP API
+ $changelog = wp_remote_get(
+ $this->remote_changelog
+ ,array(
+ // We can't force anyone to alter the `~/.ssh/config` on the server
+ 'sslverify' => false
+ )
+ );
+
+ // Die silently
+ if ( is_wp_error( $changelog ) )
+ return;
+
+ // Only retrieve what's new since the installed version
+ $details = explode(
+ '*'
+ ,stristr(
+ $changelog['body']
+ ,"*{$plugin_data['Version']}*"
+ )
+ );
+ // Build the update note
+ $whats_new = '';
+ for ( $i = 0; $i < count( $details ); $i++ )
+ {
+ $whats_new .= ( 0 != $i % 2 ) ? "<strong>{$details[ $i ]}" : "</strong><br />{$details[ $i ]}";
+ }
+
+ return printf(
+ "%sThe Update from %s to %s brings you the following new features, bug fixes and additions.%s"
+ ,'<hr />'
+ ,"<code>{$plugin_data['Version']}</code>"
+ ,"<code>{$r->new_version}</code>"
+ ,"<p style='font-weight:normal;'>{$whats_new}</p>"
+ );
}
} // END Class CD_APD_Bootstrap
Please sign in to comment.
Something went wrong with that request. Please try again.