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