In the WordPress repo, on the main page for every plugin, it displays the date of the plugin's last update (screenshot). From my own WordPress site, is it possible to fetch this data with custom PHP and/or JavaScript code? I would like to fetch this information for each plugin that is installed on my site, then display it on the Dashboard-->Plugins page.
Perhaps there is some sort of API available which makes this data accessible for all plugins in the WordPress repo?
If possible, I might also want to fetch other data related to the plugin, e.g. 'WordPress version' and 'Tested up to.'
In the WordPress repo, on the main page for every plugin, it displays the date of the plugin's last update (screenshot). From my own WordPress site, is it possible to fetch this data with custom PHP and/or JavaScript code? I would like to fetch this information for each plugin that is installed on my site, then display it on the Dashboard-->Plugins page.
Perhaps there is some sort of API available which makes this data accessible for all plugins in the WordPress repo?
If possible, I might also want to fetch other data related to the plugin, e.g. 'WordPress version' and 'Tested up to.'
Share Improve this question asked Aug 14, 2019 at 10:02 cag8fcag8f 1,9973 gold badges21 silver badges31 bronze badges 4- 1 See this (and check the examples linked from there). – Sally CJ Commented Aug 16, 2019 at 9:56
- 1 @SallyCJ Bringo, that's exactly what I wanted--thanks. Am I allowed to mark this as the solution? Or do you need to formally add it as an answer first? – cag8f Commented Aug 17, 2019 at 14:22
- I've just posted an answer.. :) – Sally CJ Commented Aug 18, 2019 at 12:25
- hello and good day I'm currently working on a parser to fetch metadata on the newest plugins in wordpress. stackoverflow/questions/61679425/… your approach is much simple - many thanks – zero Commented Jun 1, 2020 at 7:19
1 Answer
Reset to default 3Perhaps there is some sort of API available
Yes, there is, and you can check it out here.
There are examples linked from that Codex page, and you might want to use version 1.2 (GET
requests only) or 1.1 of the API where these versions both have the response format in JSON.
And actually, there's also plugins_api()
which make things easy for you; however, you'd need to manually load the file where the function is defined (wp-admin/includes/plugin-install.php
).
Example using plugins_api()
// You may comment this out IF you're sure the function exists.
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$args = [
'slug' => 'woocommerce',
];
$data = plugins_api( 'plugin_information', $args );
//var_dump( $data );
if ( $data && ! is_wp_error( $data ) ) {
echo 'Latest version: ' . $data->version;
}
Example with manual HTTP requests
$args = [
'slug' => 'woocommerce',
];
$url = 'http://api.wordpress/plugins/info/1.2/';
$url = add_query_arg( [
'action' => 'plugin_information', // first param for plugins_api()
'request' => $args, // second param for plugins_api()
], $url );
$res = wp_remote_get( $url );
if ( ! is_wp_error( $res ) ) {
$data = json_decode( wp_remote_retrieve_body( $res ) );
//var_dump( $data );
echo 'Latest version: ' . $data->version;
}
Either way, if you want to exclude certain fields like reviews and read-me sections like "description" and "installation", you can use the fields
argument like so:
$args = [
'slug' => 'woocommerce',
'fields' => [
'sections' => false, // excludes all readme sections
'reviews' => false, // excludes all reviews
],
];
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745234415a4617822.html
评论列表(0条)