-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathclass-media-library.php
More file actions
91 lines (77 loc) · 1.73 KB
/
class-media-library.php
File metadata and controls
91 lines (77 loc) · 1.73 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
<?php
/**
* Media_Library class for the Cloudinary plugin.
*
* @package Cloudinary
*/
namespace Cloudinary;
use WP_Screen;
/**
* Class Media_Library
*/
class Media_Library extends Extension {
/**
* Holds the plugin instance.
*
* @var Plugin Instance of the global plugin.
*/
public $plugin;
/**
* Holds the page handle.
*
* @var string
*/
protected $handle;
/**
* Holds teh component slug.
*/
const MEDIA_LIBRARY_SLUG = 'cloudinary-media-library';
/**
* Setup the component
*/
public function setup() {
// Setup the main page.
$this->handle = add_menu_page(
__( 'Cloudinary Media Library', 'cloudinary' ),
__( 'Cloudinary DAM', 'cloudinary' ),
Utils::user_can( 'manage_dam' ) ? 'exist' : false, // phpcs:ignore WordPress.WP.Capabilities.Undetermined
self::MEDIA_LIBRARY_SLUG,
array( $this, 'render' ),
'dashicons-cloudinary-dam',
'81.6'
);
}
/**
* Render the page template.
*/
public function render() {
require CLDN_PATH . 'ui-definitions/components/media-library.php';
}
/**
* Check if this class is active.
*
* @return bool True if active False if not.
*/
public function is_active() {
$screen = get_current_screen();
return $screen instanceof WP_Screen && $screen->base === $this->handle;
}
/**
* Register assets to be used for the class.
*/
public function register_assets() {
}
/**
* Enqueue Assets
*/
public function enqueue_assets() {
$media = $this->plugin->get_component( 'media' );
wp_enqueue_script( 'cloudinary' );
$params = array(
'fetch_url' => Utils::rest_url( REST_API::BASE . '/asset' ),
'nonce' => wp_create_nonce( 'wp_rest' ),
);
$this->plugin->add_script_data( 'dam', $params );
$media->editor_assets();
}
}