-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathImport_Menu.php
More file actions
96 lines (83 loc) · 1.87 KB
/
Import_Menu.php
File metadata and controls
96 lines (83 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Code_Snippets\Admin\Menus;
use Code_Snippets\Admin\Contextual_Help;
use function Code_Snippets\code_snippets;
use const Code_Snippets\PLUGIN_FILE;
use const Code_Snippets\PLUGIN_VERSION;
/**
* This class handles the import admin menu.
*
* @since 2.4.0
* @package Code_Snippets
*/
class Import_Menu extends Admin_Menu {
/**
* Class constructor
*/
public function __construct() {
parent::__construct(
'import',
_x( 'Import', 'menu label', 'code-snippets' ),
__( 'Import Snippets', 'code-snippets' )
);
add_action( 'admin_init', [ $this, 'register_importer' ] );
add_action( 'load-importer-code-snippets', [ $this, 'load' ] );
}
/**
* Executed when the menu is loaded
*/
public function load() {
parent::load();
$contextual_help = new Contextual_Help( 'import' );
$contextual_help->load();
}
/**
* Add the importer to the Tools > Import menu
*/
public function register_importer() {
if ( ! defined( 'WP_LOAD_IMPORTERS' ) || ! code_snippets()->current_user_can() ) {
return;
}
register_importer(
'code-snippets',
__( 'Code Snippets', 'code-snippets' ),
__( 'Import snippets from a code snippets export file', 'code-snippets' ),
[ $this, 'render' ]
);
}
/**
* Enqueue assets for the import menu.
*
* @return void
*/
public function enqueue_assets() {
wp_enqueue_script(
'code-snippets-import',
plugins_url( 'dist/import.js', PLUGIN_FILE ),
[
'react',
'react-dom',
'react-jsx-runtime',
'wp-i18n',
'wp-components',
],
PLUGIN_VERSION,
true
);
wp_enqueue_style(
'code-snippets-import',
plugins_url( 'dist/import.css', PLUGIN_FILE ),
[],
PLUGIN_VERSION
);
code_snippets()->localize_script( 'code-snippets-import' );
}
/**
* Render Import menu UI.
*
* @return void
*/
public function render() {
echo '<div id="import-container"></div>';
}
}