Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberwani/13b58596ba7782a7d7aac8b55c534452 to your computer and use it in GitHub Desktop.
Save cyberwani/13b58596ba7782a7d7aac8b55c534452 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment