Last active
January 15, 2020 21:15
-
-
Save mintplugins/ef99f29672c006db11aa6ee67dfc3fe0 to your computer and use it in GitHub Desktop.
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
function get_my_plugin_data(){ | |
// You'll likely replace this with some sort of API call home. | |
$plugin = json_decode( | |
json_encode( | |
array( | |
'new_version' => 89, | |
'stable_version' => 89, | |
'name' => 'My Fake Plugin', | |
'slug' => 'my-fake-plugin', | |
'url' => 'https://myfakeplugin.com', | |
'version' => 998, | |
'author' => '<a href="https://philjdrums.com">Phil Johnston</a>', | |
'last_updated' => '2019-01-24 18:42:57', | |
'requires' => 1.0, | |
'requires_php' => 7.3, | |
'tested' => 900, | |
'active_installs' => 50000, | |
//'slug' => 'include-me-if-on-wp-org-repo', | |
'homepage' => 'https://myfakeplugin.com', | |
'donate_link' => 'https://myfakeplugin.com/donate', | |
'rating' => 100, //percentage | |
'num_ratings' => 19, | |
//'ratings' => array( 5 => 10, 4 => 1, 3 => 7, 2 => 1, 1=> 0 ), //These are the number of reviews, not ratings. Only include if plugin is on wp.org as links are hardcoded. | |
'package' => 'https://myfakeplugin.com/my-fake-plugin.zip', | |
'download_link' => 'https://myfakeplugin.com', | |
'sections' => array( | |
'description' => wpautop( strip_tags( 'This plugin does this and that.', '<p><li><ul><ol><strong><a><em>' ) ), | |
'installation' => wpautop( strip_tags( 'Here is how you install the plugin.', '<p><li><ul><ol><strong><a><em>' ) ), | |
'faq' => 'Frequently asked questions go here.', | |
'changelog' => html_entity_decode( 'This and that changed' ), | |
'screenshots' => 'Screenshots go here', | |
'reviews' => 'Reviews go here', | |
), | |
'icons' => array( | |
'2x' => 'https://philjdrums.com/wp-content/uploads/2019/01/Phil-J-Drums-1.png', | |
'1x' => 'https://philjdrums.com/wp-content/uploads/2019/01/Phil-J-Drums-1.png', | |
'svg' => 'https://philjdrums.com/wp-content/uploads/2019/01/Phil-J-Drums-1.png' | |
), | |
'banners' => array( | |
'high' => 'https://philjdrums.com/wp-content/uploads/2019/01/Phil-J-Drums-1.png', | |
'low' => 'https://philjdrums.com/wp-content/uploads/2019/01/Phil-J-Drums-1.png' | |
), | |
'contributors' => array( | |
'johnstonphilip' => array( | |
'display_name' => 'Phil Johnston', | |
'profile' => '//profiles.wordpress.org/johnstonphilip', | |
'avatar' => 'https://wordpress.org/grav-redirect.php?user=johnstonphilip', | |
) | |
), | |
) | |
), false, 4 | |
); | |
// Format the contributors array the way WP core needs it. | |
$formatted_contributors = array(); | |
foreach( (array)$plugin->contributors as $contributor => $contributor_info ) { | |
$formatted_contributors[$contributor] = (array)$contributor_info; | |
} | |
// Format each part the way WP core needs it, as an object containing an array. | |
$plugin->sections = (array)$plugin->sections; | |
$plugin->icons = (array)$plugin->icons; | |
$plugin->banners = (array)$plugin->banners; | |
$plugin->contributors = (array)$formatted_contributors; | |
// Set the name according to the plugin and name of the main file. | |
$plugin->plugin = 'my-fake-plugin/my-fake-plugin.php'; | |
return $plugin; | |
} | |
function simple_plugin_updater( $update_plugins, $transient_name ) { | |
$plugin = get_my_plugin_data(); | |
// Add this plugin to the list of plugins with update data being saved | |
$update_plugins->response['my-fake-plugin/my-fake-plugin.php'] = $plugin; | |
return $update_plugins; | |
} | |
add_filter( 'pre_set_site_transient_update_plugins', 'simple_plugin_updater', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment