I would like to inform the users of my plugin www.mapsmarker.com also on the pluginĀ“s pages, if there is an update available - and not just under plugins.
How can this be achieved?
Thanks!
Robert
John Cotton answers:
Whether there's an update or not is held in the database - here's the snippet from the core which determines which plugins to display an update link for in the plugins table.
if ( current_user_can( 'update_plugins' ) ) {
$current = get_site_transient( 'update_plugins' );
foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
if ( isset( $current->response[ $plugin_file ] ) ) {
$plugins['all'][ $plugin_file ]['update'] = true;
$plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
}
}
}
You could easily adapt that to work for just your plugin by checked the for the plugin name.
However - and this is just a personal opinion - I wouldn't do it.
There's a real problem in my view with plugins trying to re-invent the dashboard UI to stand out or whatever. One of the beauties of WordPress (particularly for no-tech users) is it's consistency.
By adding this new "feature" to your plugin page, you just stray further from the well-worn path. And for what reason? Uses know to look on the plugins page for updates; WP flags them for them with little numbers in the UI. What are you adding but some more code to your plugin that has little benefit for few people?
In the nicest possible way... :)
Robert Seyfriedsberger comments:
reinventing the wheel is not the goal - my plugin works for multisite too and normal users dont see if there is an update available. As I push out new updates eegularly, this info on plugin page could help spreading them faster...
John Cotton comments:
Note the permissions check
current_user_can( 'update_plugins' )
in that code. You should adhere to that...
Dbranes answers:
Hi Robert
This might not be relevant for your question but I post it anyway ;-)
you can always get the info (last-update, download count, ... etc)
for your "leaflet-maps-marker" plugin via:
http://api.wordpress.org/plugins/info/1.0/leaflet-maps-marker.php
http://api.wordpress.org/plugins/info/1.0/leaflet-maps-marker.json
http://api.wordpress.org/plugins/info/1.0/leaflet-maps-marker.xml
I think this is the plugin-info that WP is fetching for each plugin.
(the .php version is serialized and one could easily use jQuery to fetch the json part)
Some plugins use this, fx wp-plugin-info
http://wordpress.org/extend/plugins/wp-plugin-info/
So if you need to display the "leaflet-maps-marker" plugin info on your homepage you could use
[wp-plugin-info plugin_id="leaflet-maps-marker" info_id="last_updated" date_format="Y-n-j"]
This is the way this wp-plugin-info does it (modified to fetch your plugin info)
$args = array(
'timeout' => 10,
'body' => array( 'action' => 'plugin_information', 'request' => serialize($obj))
);
$response = wp_remote_post("http://api.wordpress.org/plugins/info/1.0/leaflet-maps-marker", $args);
if (is_wp_error($response) || (! isset($response['body'])))
return false;
$data = (array) @unserialize($response['body']);
print_r($data);
ps: But I think John's way is ideal, i.e. to get the info from the $plugins array.