-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal-media-button.php
More file actions
103 lines (83 loc) · 2.73 KB
/
external-media-button.php
File metadata and controls
103 lines (83 loc) · 2.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
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/*
* Plugin Name: External Media Button
* Description: Moves selected media menu items from the "Add Media" window into a new window titled "Add External Media".
* Version: 0.1-alpha
* Author: r-a-y
* Author URI: https://profiles.wordpress.org/r-a-y
*/
defined( 'ABSPATH' ) or die();
/**
* Instantiates the plugin during 'plugins_loaded' action.
*/
add_action( 'plugins_loaded', array( 'Ray_External_Media_Button', 'init' ) );
/**
* Main plugin class.
*
* Props ocean90 for some JS hints:
* @link https://github.com/ocean90/media-modal-demo
*/
class Ray_External_Media_Button {
/**
* Static initializer.
*/
public static function init() {
return new self;
}
/**
* Constructor.
*/
protected function __construct() {
add_action( 'media_buttons', array( $this, 'add_media_button' ) );
add_action( 'wp_enqueue_media', array( $this, 'enqueue_assets' ) );
add_action( 'admin_head', array( $this, 'press_this_inline_css' ) );
// Shortcake - Remove "Add Post Element" button.
add_action( 'init', function() {
if ( class_exists( 'Shortcode_UI', false ) && is_callable( array( Shortcode_UI::get_instance(), 'action_media_buttons' ) ) ) {
remove_action( 'media_buttons', array( Shortcode_UI::get_instance(), 'action_media_buttons' ) );
}
}, 6 );
}
/**
* Output "Add External Media" button beside the existing "Add Media" button.
*
* @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
*/
public function add_media_button( $editor_id ) {
print sprintf(
'<button id="add-external-media" data-editor="content" class="button add_media" type="button"><span class="dashicons dashicons-admin-site"></span> %1$s</button>',
__( 'Add External Media', 'external-media-button' )
);
}
/**
* Enqueue assets.
*/
public function enqueue_assets() {
// Do not enqueue CSS when on "Press This" page.
if ( false !== strpos( $_SERVER['REQUEST_URI'], '/press-this.php' ) ) {
return;
}
$base = plugin_dir_url( __FILE__ );
wp_enqueue_script( 'ray-media', $base . 'modal.js', array(
'media-editor'
) );
wp_enqueue_style( 'ray-media', $base . 'modal.css' );
}
/**
* Add inline CSS when on the "Press This" page.
*/
public function press_this_inline_css() {
// Skip if we're not on the "Press This" page.
if ( false === strpos( $_SERVER['REQUEST_URI'], '/press-this.php' ) ) {
return;
}
// This doesn't really work at the moment, but leave it here anyway.
add_filter( 'mexp_vimeo_uploader_css_class', '__return_empty_string', 999 );
$inline_css = <<<EOD
.press-this .mexp-content-vimeo-vupload .drop-instructions {
display: none;
}
EOD;
printf( '<style type="text/css">%s</style>', $inline_css );
}
}