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