-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin.php
76 lines (65 loc) · 1.88 KB
/
plugin.php
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
<?php
/**
* Plugin Name: DevBlog Dataviews Plugin
* Description: Displays a dataset of images for upload to the Media Library.
* Version: 1.0.1
* Requires at least: 6.1
* Requires PHP: 7.4
* Author: JuanMa Garrido
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: devblog-dataviews-plugin
*/
defined( 'ABSPATH' ) || exit;
add_action( 'admin_menu', 'devblog_dataviews_admin_menu' );
/**
* Creates a new Media subsection and set the HTML for it.
*/
function devblog_dataviews_admin_menu() {
add_media_page(
__( 'Add Media from third party service', 'devblog-dataviews-plugin' ),
__( 'Add Media from third party service', 'devblog-dataviews-plugin' ),
'manage_options',
'add-media-from-third-party-service',
function () {
printf(
'<h1>%s</h1><div id="add-media-from-third-party-service"></div>',
esc_html__( 'Add Media from third party service', 'devblog-dataviews-plugin' )
);
}
);
}
add_action( 'admin_enqueue_scripts', 'devblog_dataviews_admin_enqueue_assets' );
/**
* Enqueues JS and CSS files for our custom Media subsection page.
*
* @param string $hook_suffix The current admin page.
*/
function devblog_dataviews_admin_enqueue_assets( $hook_suffix ) {
// Load only on ?page=add-media-from-third-party-service.
if ( 'media_page_add-media-from-third-party-service' !== $hook_suffix ) {
return;
}
$dir = plugin_dir_path( __FILE__ );
$url = plugin_dir_url( __FILE__ );
$asset_file = $dir . 'build/index.asset.php';
if ( ! file_exists( $asset_file ) ) {
return;
}
$asset = include $asset_file;
wp_enqueue_script(
'devblog-dataviews-script',
$url . 'build/index.js',
$asset['dependencies'],
$asset['version'],
array(
'in_footer' => true,
)
);
wp_enqueue_style(
'devblog-dataviews-styles',
$url . 'build/style-index.css',
array( 'wp-components' ),
$asset['version'],
);
}