I have a custom plugin hosted on github, and had previously had a plugin updater class that would poll the repo for the 'latest' version.
Now the plugin is on multiple sites, but we want the option to control what version of the plugin each site is on, not just the 'latest' version.
I have added a section to my plugin admin that polls the /releases for the repo and populates a select with the tags from the releases so the user can choose which version to upgrade to. The user simply $_posts the selected version.
I have an init function that I am using to instantiate my updater class with the version/tag chosen by the user.
function setup_updater(){ if(isset($_POST['setup_update']) && wp_verify_nonce($_POST['setup_update'],'setup-update')){ $tag = $_POST['update_value']; try{ new cp_updater( WP_PLUGIN_DIR.'/customer-portal', 'customer-portal', $tag ); }catch(Exception $e){ cp_errors()->add('error_update', __('There was an error preparing the update')); log_me($e); return; } cp_errors()->add('success_update', __('Success! Update prepared')); } } add_action('init','setup_updater'); The class constructor sets a few private variables as well as pulling the plugin info and pulling the release info via the tag so the download url etc are all set. I know it is being instantiated and that the repo information is being pulled through debug logging.
I also add these filters
add_filter( "pre_set_site_transient_update_plugins", array( $this, "setTransient" ) ); add_filter( "plugins_api", array( $this, "setPluginInfo" ), 10, 3 ); add_filter( "upgrader_pre_install", array( $this, "preInstall" ), 10, 3 ); add_filter( "upgrader_post_install", array( $this, "postInstall" ), 10, 3 ); Most of these are self-explanatory in nature, nothing crazy going on, and setTransient is just setting the update information:
public function setTransient( $transient ){ log_me($transient); if(!$this->release_data){ return $transient; } if ( empty( $transient->checked ) ){ return $transient; } $package = $this->release_data->zipball_url; $obj = new stdClass(); $obj->slug = $this->pluginSlug; $obj->new_version = $this->release_data->tag_name; $obj->url = 'https://github.com/customer-portal';//obviously fake $obj->package = $package; $transient->response[$this->pluginSlug] = $obj; return $transient; } Everything seems ok, but the update notification never appears on the plugin update banner, and when I poll the plugins_api and *transient* hooks (see below, using ajax so I don't need to add buttons somewhere), I don't see my callbacks listed, nor does the $transient information ever get logged out.
function check_plugin_updates(){ $plugin_updates = get_site_transient( 'update_plugins' ); log_me($plugin_updates); } add_action( 'wp_ajax_check_plugin_updates', 'check_plugin_updates' ); function check_pre_site_filter(){ global $wp_filter; foreach ( $wp_filter as $key => $val ){ if ( FALSE !== strpos( $key, 'transient_update' ) ) { log_me($key); log_me($val); } } } add_action( 'wp_ajax_check_pre_site_filter', 'check_pre_site_filter' ); log_me is just a debug function that dumps out data to a log file.
Anyone have any thoughts on this? Is there an easier way to set the transient data so I can make an update available?