| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Libs; |
| 4 |
|
| 5 |
// No, Direct access Sir !!! |
| 6 |
if (!defined('ABSPATH')) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
if (!class_exists('Featured')) { |
| 11 |
|
| 12 |
/** |
| 13 |
* Featured global class |
| 14 |
* |
| 15 |
* Jewel Theme <support@jeweltheme.com> |
| 16 |
*/ |
| 17 |
class Featured |
| 18 |
{ |
| 19 |
|
| 20 |
/** |
| 21 |
* Constructor |
| 22 |
*/ |
| 23 |
public function __construct() |
| 24 |
{ |
| 25 |
add_action('plugins_loaded', [$this, 'jltwp_adminify_loaded_plgins']); |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* Plugins Loaded Function |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public function jltwp_adminify_loaded_plgins() |
| 35 |
{ |
| 36 |
if (is_admin()) { |
| 37 |
add_filter('install_plugins_table_api_args_featured', array($this, 'jltwp_adminify_featured_plugins_tab')); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Helper function for adding plugins to fav list. |
| 43 |
* |
| 44 |
* @param [type] $args . |
| 45 |
*/ |
| 46 |
public function jltwp_adminify_featured_plugins_tab($args) |
| 47 |
{ |
| 48 |
add_filter('plugins_api_result', array($this, 'jltwp_adminify_plugins_api_result'), 10, 3); |
| 49 |
|
| 50 |
return $args; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Add our plugins to recommended list. |
| 55 |
* |
| 56 |
* @param [type] $res . |
| 57 |
* @param [type] $action . |
| 58 |
* @param [type] $args . |
| 59 |
*/ |
| 60 |
public function jltwp_adminify_plugins_api_result($res, $action, $args) |
| 61 |
{ |
| 62 |
remove_filter('plugins_api_result', array($this, 'jltwp_adminify_plugins_api_result'), 10, 1); |
| 63 |
|
| 64 |
// Plugin list which you want to show as feature in dashboard. |
| 65 |
// $res = $this->jltwp_adminify_add_plugin_favs('image-hover-effects-elementor-addon', $res); . |
| 66 |
$res = $this->jltwp_adminify_add_plugin_favs('ultimate-blocks-for-gutenberg', $res); |
| 67 |
$res = $this->jltwp_adminify_add_plugin_favs('adminify', $res); |
| 68 |
$res = $this->jltwp_adminify_add_plugin_favs('master-addons', $res); |
| 69 |
|
| 70 |
return $res; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Add single plugin to list of favs. |
| 75 |
* |
| 76 |
* @param [type] $plugin_slug . |
| 77 |
* @param [type] $res . |
| 78 |
*/ |
| 79 |
public function jltwp_adminify_add_plugin_favs($plugin_slug, $res) |
| 80 |
{ |
| 81 |
if (!empty($res->plugins) && is_array($res->plugins)) { |
| 82 |
foreach ($res->plugins as $plugin) { |
| 83 |
if (is_object($plugin) && !empty($plugin->slug) && $plugin_slug === $plugin->slug) { |
| 84 |
return $res; |
| 85 |
} |
| 86 |
} // foreach |
| 87 |
} |
| 88 |
|
| 89 |
$plugin_info = new \stdClass(); |
| 90 |
if (get_transient('jltwp_adminify-plugin-info-' . $plugin_slug == $plugin_info)) { |
| 91 |
array_unshift($res->plugins, $plugin_info); |
| 92 |
} else { |
| 93 |
$plugin_info = plugins_api( |
| 94 |
'plugin_information', |
| 95 |
array( |
| 96 |
'slug' => $plugin_slug, |
| 97 |
'is_ssl' => is_ssl(), |
| 98 |
'fields' => array( |
| 99 |
'banners' => true, |
| 100 |
'reviews' => true, |
| 101 |
'downloaded' => true, |
| 102 |
'active_installs' => true, |
| 103 |
'icons' => true, |
| 104 |
'short_description' => true, |
| 105 |
), |
| 106 |
) |
| 107 |
); |
| 108 |
|
| 109 |
if (!is_wp_error($plugin_info)) { |
| 110 |
$res->plugins[] = $plugin_info; |
| 111 |
set_transient('jltwp_adminify-plugin-info-' . $plugin_slug, $plugin_info, DAY_IN_SECONDS * 7); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
return $res; |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|