Discover in this tutorial how to create a plugin that allows to display the plugins created by a WordPress user.
In this tutorial you will get to automatically display the plugins from the WordPress repository created by the WordPress user of your choice.
So, using the dedicated API, you can extract the user’s created plugins and all the associated data (link, author, ratings…), as well as display them as you want.
This would be the final result:
Shall we start?
Steps to display plugins created by a WordPress user
1. Create a shortcode with the WordPress user attribute
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
With the above code you create a shortcode with the wordpress_id
attribute that allows you to indicate the name of the WordPress user. Once the user is defined, you query the plugin API to extract the plugins created by the specified user.
In this example you “paint” the following data:
- Plugin name (with link).
- Rating (indicated with number of stars).
- Number of ratings.
- Author (with link).
Obviously, you can modify what you see fit to display the data you consider convenient.
In the example we are only obtaining the data of 5 endpoints, but with the API, when you make the request for information about a user, you can access all of them:
name
slug
version
author
author_profile
requires
tested
requires_php
requires_plugins
rating
ratings
num_ratings
support_threads
support_threads_resolved
active_installs
downloaded
last_updated
added
homepage
short_description
description
download link
tags
donate_link
icons
On the other hand, to avoid abusing API calls inside the shortcode, you create and use a transient to cache the result for a week (although you can modify it as you wish). This way you make sure that you don’t make more calls than necessary and the result is displayed immediately.
2. Customize how the plugin list is displayed
Once you have all the functional part you just need to style the plugin listing to display as in the example above.
To do this, add in the style.css file the following lines:
To see this and another 1097 code snippets of this website, login or subscribe here.
Obviously, you can also modify this to suit your needs.
Above all, remember to replace the URL https://yourwebsite.com/ with the URL of your website.
3. Insert the shortcode where you want
Finally, just type[plugins_autor wordpress_id="wordpress_user"]
where you want it to be displayed and change the username to the one you want to display.
This would be an example of the listing that the shortcode would show if I put my WordPress user:
Conclusions
Now you know how to display plugins created by a WordPress user and even choose the data to be displayed.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉