PluginProbe
Code Snippets / 4.0.0-beta.1
Code Snippets v4.0.0-beta.1
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / php / admin-menus / class-import-menu.php

class-import-menu.php in Code Snippets 4.0.0-beta.1, at php/admin-menus/class-import-menu.php

86 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets;
4
5 /**
6 * This class handles the import admin menu.
7 *
8 * @since 2.4.0
9 * @package Code_Snippets
10 */
11 class Import_Menu extends Admin_Menu {
12
13 /**
14 * Class constructor
15 */
16 public function __construct() {
17 parent::__construct(
18 'import',
19 _x( 'Import', 'menu label', 'code-snippets' ),
20 __( 'Import Snippets', 'code-snippets' )
21 );
22 }
23
24 /**
25 * Register action and filter hooks
26 */
27 public function run() {
28 parent::run();
29 add_action( 'admin_init', array( $this, 'register_importer' ) );
30 add_action( 'load-importer-code-snippets', array( $this, 'load' ) );
31 }
32
33 /**
34 * Executed when the menu is loaded
35 */
36 public function load() {
37 parent::load();
38
39 $contextual_help = new Contextual_Help( 'import' );
40 $contextual_help->load();
41 }
42
43 /**
44 * Add the importer to the Tools > Import menu
45 */
46 public function register_importer() {
47
48 /* Only register the importer if the current user can manage snippets */
49 if ( ! defined( 'WP_LOAD_IMPORTERS' ) || ! code_snippets()->current_user_can() ) {
50 return;
51 }
52
53 /* Register the Code Snippets importer with WordPress */
54 register_importer(
55 'code-snippets',
56 __( 'Code Snippets', 'code-snippets' ),
57 __( 'Import snippets from a code snippets export file', 'code-snippets' ),
58 array( $this, 'render' )
59 );
60 }
61
62 /**
63 * Enqueue assets for the import menu.
64 *
65 * @return void
66 */
67 public function enqueue_assets() {
68 $plugin = code_snippets();
69
70 wp_enqueue_script(
71 'code-snippets-import',
72 plugins_url( 'dist/import.js', $plugin->file ),
73 [
74 'react',
75 'react-dom',
76 'wp-i18n',
77 'wp-components',
78 ],
79 $plugin->version,
80 true
81 );
82
83 $plugin->localize_script( 'code-snippets-import' );
84 }
85 }
86