Scrolling through my Twitter feed earlier, I found the following question from Sébastien:
Is it possible to pull a WordPress plugin's reviews to display on your site?
— Sébastien Dumont (@sebd86) January 6, 2016
I thought this was an interesting request, so I decided to spend some time figuring it out. On WordPress.org, you can access a plugin’s support threads and reviews via the RSS feed. This allows plugin authors, and whoever else, to follow new support requests and reviews. The reviews feed can be accessed by scrolling to the bottom of the reviews list for any plugin, and clicking the “RSS link for this plugin’s reviews” link. This URL is where we send our request to retrieve the reviews.
Here’s a function I wrote up, using some of the code from the fetch_feed()
documentation.
I included inline documentation, but here’s a quick rundown of what this code is doing:
- Accepting 3 parameters: the plugin’s slug on WordPress.org (required), the number of reviews to retrieve (optional and defaults to 5), and the number of hours the transient will remain (optional and defaults to 24).
- If the reviews data has already been saved, return that data. Otherwise, requests the reviews, assembles the array, and saves it to the database.
- The array stores data for each review, including the review’s date, title, content, author, and permalink.
Example use:
//* Get all reviews for Disable Gravity Forms Fields plugin add_action( 'wp_head', 'testing_rv_get_wp_plugin_reviews' ); function testing_rv_get_wp_plugin_reviews() { $rss_items = rv_get_wp_plugin_reviews( 'disable-gravity-forms-fields', -1 ); echo '<pre>'; print_r( $rss_items ); echo '</pre>'; }
This is a pretty straightforward snippet for retrieving plugin reviews from the WordPress.org plugin repository. You can easily modify it to pull reviews for themes, or support threads.
Leave a Reply