Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created November 27, 2013 23:06
Show Gist options
  • Save danielbachhuber/7684646 to your computer and use it in GitHub Desktop.
Save danielbachhuber/7684646 to your computer and use it in GitHub Desktop.
How to integrate WordPress Core updates with your custom Plugin or Theme
<?php
/**
* How to integrate WordPress Core updates with your custom Plugin or Theme
*
* Filter the `update_plugins` transient to report your plugin as out of date.
* Themes have a similar transient you can filter.
*/
add_filter( 'site_transient_update_plugins', 'wprp_extend_filter_update_plugins' );
add_filter( 'transient_update_plugins', 'wprp_extend_filter_update_plugins' );
function wprp_extend_filter_update_plugins( $update_plugins ) {
if ( ! is_object( $update_plugins ) )
return $update_plugins;
if ( ! isset( $update_plugins->response ) || ! is_array( $update_plugins->response ) )
$update_plugins->response = array();
// Do whatever you need to see if there's a new version of your plugin
// Your response will need to look something like this if it's out of date:
$update_plugins->response['wpremote-sample/wpremote-sample.php'] = (object)array(
'slug' => 'wpremote-sample', // Whatever you want, as long as it's not on WordPress.org
'new_version' => '0.2', // The newest version
'url' => 'https://github.com/humanmade/wp-remote-sample-plugin', // Informational
'package' => 'https://github.com/humanmade/wp-remote-sample-plugin/archive/0.2.zip', // Where WordPress should pull the ZIP from.
);
return $update_plugins;
}
@tarecord
Copy link

tarecord commented Nov 2, 2020

This is exactly what I needed and I ended up throwing it into a composer library.

Thanks!

@ngadt
Copy link

ngadt commented Jan 23, 2022

Thank you very much, this is exactly what I need. Your example is simple and clear.

@meweb-dev
Copy link

How do you have WordPress authenticate with github for private repos to download the package? I was able to authenticate using a token to check for a new version by reading a json file within the private repo but once I hit "Update" I get the "update failed: Download failed. Not Found" error message. I can download the package when logged into github so the URL works when authenticated but not when updating from wordpress. Thanks.

@amiradbrains
Copy link

It's really helpfull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment