| 1 |
<?php |
| 2 |
|
| 3 |
namespace Code_Snippets\Admin\Menus; |
| 4 |
|
| 5 |
use Code_Snippets\Admin\Contextual_Help; |
| 6 |
use Code_Snippets\Client\Welcome_Client; |
| 7 |
use function Code_Snippets\code_snippets; |
| 8 |
use const Code_Snippets\PLUGIN_FILE; |
| 9 |
use const Code_Snippets\PLUGIN_VERSION; |
| 10 |
|
| 11 |
/** |
| 12 |
* This class handles the welcome menu. |
| 13 |
* |
| 14 |
* @since 3.7.0 |
| 15 |
* @package Code_Snippets |
| 16 |
*/ |
| 17 |
class Welcome_Menu extends Admin_Menu { |
| 18 |
|
| 19 |
/** |
| 20 |
* Client instance. |
| 21 |
* |
| 22 |
* @var Welcome_Client |
| 23 |
*/ |
| 24 |
protected Welcome_Client $client; |
| 25 |
|
| 26 |
/** |
| 27 |
* Class constructor |
| 28 |
* |
| 29 |
* @param Welcome_Client $client Client instance. |
| 30 |
*/ |
| 31 |
public function __construct( $client ) { |
| 32 |
parent::__construct( |
| 33 |
'welcome', |
| 34 |
_x( "What's New", 'menu label', 'code-snippets' ), |
| 35 |
__( 'Resources and Updates', 'code-snippets' ) |
| 36 |
); |
| 37 |
|
| 38 |
$this->client = $client; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Load the welcome menu. |
| 43 |
* |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
public function render() { |
| 47 |
echo '<div id="code-snippets-welcome-container" class="wrap"></div>'; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Load the contextual help tabs. |
| 52 |
* |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
public function load() { |
| 56 |
parent::load(); |
| 57 |
|
| 58 |
$contextual_help = new Contextual_Help( 'welcome' ); |
| 59 |
$contextual_help->load(); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Enqueue assets necessary for the welcome menu. |
| 64 |
* |
| 65 |
* @return void |
| 66 |
*/ |
| 67 |
public function enqueue_assets() { |
| 68 |
$handle = 'code-snippets-welcome'; |
| 69 |
|
| 70 |
wp_enqueue_style( |
| 71 |
$handle, |
| 72 |
plugins_url( 'dist/welcome.css', PLUGIN_FILE ), |
| 73 |
self::$style_deps, |
| 74 |
PLUGIN_VERSION |
| 75 |
); |
| 76 |
|
| 77 |
wp_enqueue_script( |
| 78 |
$handle, |
| 79 |
plugins_url( 'dist/welcome.js', PLUGIN_FILE ), |
| 80 |
self::$script_deps, |
| 81 |
PLUGIN_VERSION, |
| 82 |
true |
| 83 |
); |
| 84 |
|
| 85 |
code_snippets()->localize_script( $handle ); |
| 86 |
|
| 87 |
wp_localize_script( |
| 88 |
$handle, |
| 89 |
'CODE_SNIPPETS_WELCOME', |
| 90 |
[ |
| 91 |
'banner' => $this->client->get_banner(), |
| 92 |
'hero' => $this->client->get_hero_item(), |
| 93 |
'changelog' => $this->client->get_changelog(), |
| 94 |
'features' => $this->client->get_features(), |
| 95 |
'partners' => $this->client->get_partners(), |
| 96 |
] |
| 97 |
); |
| 98 |
} |
| 99 |
} |
| 100 |
|