| 1 |
<?php |
| 2 |
|
| 3 |
namespace Code_Snippets\Admin\Menus\Insights; |
| 4 |
|
| 5 |
use Code_Snippets\Admin\Contextual_Help; |
| 6 |
use Code_Snippets\Admin\Menus\Admin_Menu; |
| 7 |
use function Code_Snippets\code_snippets; |
| 8 |
use const Code_Snippets\PLUGIN_FILE; |
| 9 |
use const Code_Snippets\PLUGIN_VERSION; |
| 10 |
|
| 11 |
/** |
| 12 |
* Provides the Insights admin menu. |
| 13 |
*/ |
| 14 |
class Insights_Menu extends Admin_Menu { |
| 15 |
|
| 16 |
/** |
| 17 |
* Handle for the Insights script and stylesheet. |
| 18 |
*/ |
| 19 |
private const ASSET_HANDLE = 'code-snippets-insights'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Class constructor. |
| 23 |
*/ |
| 24 |
public function __construct() { |
| 25 |
parent::__construct( |
| 26 |
'insights', |
| 27 |
_x( 'Insights', 'menu label', 'code-snippets' ), |
| 28 |
__( 'Snippet Insights', 'code-snippets' ) |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Render the Insights interface. |
| 34 |
* |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
public function render() { |
| 38 |
echo '<div id="code-snippets-insights-container" class="wrap"></div>'; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Load the contextual help tabs. |
| 43 |
* |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
public function load() { |
| 47 |
parent::load(); |
| 48 |
|
| 49 |
$contextual_help = new Contextual_Help( 'insights' ); |
| 50 |
$contextual_help->load(); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Enqueue Insights assets and localized runtime data. |
| 55 |
* |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
public function enqueue_assets() { |
| 59 |
wp_enqueue_style( |
| 60 |
self::ASSET_HANDLE, |
| 61 |
plugins_url( 'dist/insights.css', PLUGIN_FILE ), |
| 62 |
self::$style_deps, |
| 63 |
PLUGIN_VERSION |
| 64 |
); |
| 65 |
|
| 66 |
wp_enqueue_script( |
| 67 |
self::ASSET_HANDLE, |
| 68 |
plugins_url( 'dist/insights.js', PLUGIN_FILE ), |
| 69 |
self::$script_deps, |
| 70 |
PLUGIN_VERSION, |
| 71 |
true |
| 72 |
); |
| 73 |
|
| 74 |
wp_set_script_translations( self::ASSET_HANDLE, 'code-snippets' ); |
| 75 |
code_snippets()->localize_script( self::ASSET_HANDLE ); |
| 76 |
wp_localize_script( self::ASSET_HANDLE, 'CODE_SNIPPETS_INSIGHTS', ( new Insights_Summary() )->get() ); |
| 77 |
} |
| 78 |
} |
| 79 |
|