Skip to content

Instantly share code, notes, and snippets.

@webaware
Created June 18, 2023 04:38
Show Gist options
  • Save webaware/4a4f2dca44b1c10fb9a8fe85a5f90f40 to your computer and use it in GitHub Desktop.
Save webaware/4a4f2dca44b1c10fb9a8fe85a5f90f40 to your computer and use it in GitHub Desktop.
Add download links to WordPress plugins with updates available
<?php
/*
Plugin Name: Plugin Download
Plugin URI: https://gist.github.com/webaware/4a4f2dca44b1c10fb9a8fe85a5f90f40
Update URI: plugin-download
Description: add download links to plugins with updates available
Version: 0.0.1
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
/*
copyright (c) 2023 WebAware Pty Ltd (email : support@webaware.com.au)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* maybe add a download link to plugin row meta on the Plugins admin page
*/
add_filter('plugin_row_meta', function(array $row_meta, string $plugin_file, array $plugin_data) : array {
if (empty($plugin_data['new_version']) || empty($plugin_data['Version']) || empty($plugin_data['package'])) {
return $row_meta;
}
if (version_compare($plugin_data['new_version'], $plugin_data['Version'], '>')) {
$row_meta[] = sprintf('<a href="%s">Download update package</a>', esc_url($plugin_data['package']));
}
return $row_meta;
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment