Created
November 27, 2013 23:06
-
-
Save danielbachhuber/7684646 to your computer and use it in GitHub Desktop.
How to integrate WordPress Core updates with your custom Plugin or Theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
You're welcome!
This is exactly what I needed and I ended up throwing it into a composer library.
Thanks!
Thank you very much, this is exactly what I need. Your example is simple and clear.
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.
It's really helpfull.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just an encouraging compliment. There are several pretty confusing tutorials and code examples that I've found. Your example here is clear and simple. Thank you,