| 1 |
<?php |
| 2 |
namespace JewelTheme\AdminBarEditor\Libs; |
| 3 |
|
| 4 |
// No, Direct access Sir !!! |
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
if ( ! class_exists( 'Recommended' ) ) { |
| 10 |
|
| 11 |
/** |
| 12 |
* Recommended Class |
| 13 |
* |
| 14 |
* Adds a submenu that links to the WordPress plugin install screen |
| 15 |
* filtered by author. |
| 16 |
* |
| 17 |
* Jewel Theme <support@jeweltheme.com> |
| 18 |
*/ |
| 19 |
class Recommended { |
| 20 |
|
| 21 |
public $parent_slug; |
| 22 |
public $menu_title; |
| 23 |
public $author; |
| 24 |
public $menu_order; |
| 25 |
|
| 26 |
/** |
| 27 |
* Constructor. |
| 28 |
* |
| 29 |
* @param string $parent_slug Parent menu slug to attach submenu under. |
| 30 |
* @param string $author WordPress.org plugin author slug to filter by. |
| 31 |
* @param string $menu_title Submenu label. |
| 32 |
* @param integer $menu_order Submenu order priority. |
| 33 |
*/ |
| 34 |
public function __construct( $parent_slug = '', $author = 'pixarlabs', $menu_title = '', $menu_order = 99 ) { |
| 35 |
$this->parent_slug = $parent_slug; |
| 36 |
$this->author = $author; |
| 37 |
$this->menu_title = $menu_title; |
| 38 |
$this->menu_order = $menu_order; |
| 39 |
|
| 40 |
add_action( 'admin_menu', array( $this, 'admin_menu' ), $this->menu_order ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Build the plugin-install URL filtered by author. |
| 45 |
*/ |
| 46 |
public function get_recommended_url() { |
| 47 |
$url = 'plugin-install.php?tab=search&type=author&s=' . rawurlencode( $this->author ); |
| 48 |
|
| 49 |
if( is_multisite() ) { |
| 50 |
return network_admin_url( $url ); |
| 51 |
} |
| 52 |
|
| 53 |
return admin_url( $url ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Register submenu pointing directly to plugin-install screen. |
| 58 |
*/ |
| 59 |
public function admin_menu() { |
| 60 |
if ( empty( $this->parent_slug ) ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
$title = $this->menu_title ? $this->menu_title : __( 'Recommended', 'admin-bar' ); |
| 65 |
|
| 66 |
add_submenu_page( |
| 67 |
$this->parent_slug, |
| 68 |
$title, |
| 69 |
$title, |
| 70 |
'install_plugins', |
| 71 |
$this->get_recommended_url() |
| 72 |
); |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|