In This Article, you will learn how to add your WordPress featured plugin according to your need. You can handle the featured plugins argument by extending functionality to write code your own way.
Especially this article for plugin developers who love to learn regularly. if you have multiple plugins in wordpress.org then these small tips will help you. When a user adds your WordPress plugin then your other plugin also will suggest to users when they try to add a new plugin in their dashboard.
How to Add WordPress featured plugin in Dashboard.
There have 3 steps you have to follow.
- Download the code snippet from our website.
- Create new file like “class-plugin-suggest.php”
- Then put code into “class-plugin-sugeest.php
- After adding code then you need to load the created file
<?php /** * CodePopular_Plugin_Featured */ if ( ! class_exists( 'CodePopular_Plugin_Featured' ) ) { class CodePopular_Plugin_Featured { /** * Initialize Hooks. * * @return void */ static function init(){ if (is_admin()) { add_filter('install_plugins_table_api_args_featured', array(__CLASS__, 'featured_plugins_tab')); } } /** * Add our plugins to recommended list. * * @param [type] $res * @param [type] $action * @param [type] $args * @return void */ static function plugins_api_result($res, $action, $args) { remove_filter('plugins_api_result', array(__CLASS__, 'plugins_api_result'), 10, 1); // Add plugin list which you want to show as feature in dashboard. $res = self::add_plugin_favs('wp-maximum-upload-file-size', $res); $res = self::add_plugin_favs('unlimited-theme-addons', $res); return $res; } /** * Helper function for adding plugins to fav list. * * @param [type] $args * @return void */ static function featured_plugins_tab($args) { add_filter('plugins_api_result', array(__CLASS__, 'plugins_api_result'), 10, 3); return $args; } /** * Add single plugin to list of favs. * * @param [type] $plugin_slug * @param [type] $res * @return void */ static function add_plugin_favs($plugin_slug, $res) { if (!empty($res->plugins) && is_array($res->plugins)) { foreach ($res->plugins as $plugin) { if (is_object($plugin) && !empty($plugin->slug) && $plugin->slug == $plugin_slug) { return $res; } } // foreach } if ($plugin_info = get_transient('wf-plugin-info-' . $plugin_slug)) { array_unshift($res->plugins, $plugin_info); } else { $plugin_info = plugins_api('plugin_information', array( 'slug' => $plugin_slug, 'is_ssl' => is_ssl(), 'fields' => array( 'banners' => true, 'reviews' => true, 'downloaded' => true, 'active_installs' => true, 'icons' => true, 'short_description' => true, ) )); if (!is_wp_error($plugin_info)) { $res->plugins[] = $plugin_info; set_transient('wf-plugin-info-' . $plugin_slug, $plugin_info, DAY_IN_SECONDS * 7); } } return $res; } } } /** * Initialize Class. */ add_action('init', array('CodePopular_Plugin_Featured', 'init'));
The plugin owners will benefit more benefited by adding this code snippet to their project. You can boost your plugin installation by adding to the featured list. if you have an old plugin that has already achieved thousands of installations then you will have the opportunity to suggest another plugin. if you are a WordPress plugin developer so you will also be interested in how to save plugin data in the database. plugin suggestion tips will big help for new addition plugin.
Tips for only wordpress.org | Change your class name “CodePopular_Plugin_Featured” depending your project. otherwise it can be conflict by other some one plugin class name.
This plugin suggestion things only work if your plugin is hosted on wordpress.org if your plugin is hosted outside of wordpress.org then above code will not work.
Hi, My name is Shamim. I am a freelance PHP developer in Bangladesh. I have been working as a freelance developer since 2014. I am a passionate and creative web development person. As a senior level, I focus on your requirements in detail and deliver high-quality work on your budget.
Thank you for this. I was looking everywhere for a solution. For those that want to remove the default featured plugins, in your `plugins_api_result` function, add the following above `$res = self::add_plugin_favs()`:
“`
$res->plugins = [];
“`
Thank you too.