(Open/Access WP Media library tinymce), , :
. , , . , .
, WP Add Media, script. , wp_enqueue_media() :
add_action('admin_enqueue_scripts', 'enqueue_scripts_styles_admin');
function enqueue_scripts_styles_admin(){
wp_enqueue_media();
}
, WP Media.
, HTML- / URL , - :
<input type="text" class="selected_image" />
<input type="button" class="upload_image_button" value="Upload Image">
URL- , - .
jscript - :
var custom_uploader;
$('.upload_image_button').click(function(e) {
e.preventDefault();
var $upload_button = $(this);
custom_uploader = wp.media.frames.file_frame = wp.media({
title: 'Choose Image',
button: {
text: 'Choose Image'
},
multiple: false
});
custom_uploader.on('select', function() {
var attachment = custom_uploader.state().get('selection').first().toJSON();
$upload_button.siblings('input[type="text"]').val(attachment.url);
});
custom_uploader.open();
});
, . , wp, .
TinyMCE ( ). hi lo , , . , . , "WP is undefined" . , WP script :
(function() {
tinymce.create('tinymce.plugins.someplugin', {
init : function(ed, url) {
ed.addCommand('mcebutton', function() {
ed.windowManager.open(
{
file : url + '/editor_button.php',
width : 800 + parseInt(ed.getLang('button.delta_width', 0)),
height : 600 + parseInt(ed.getLang('button.delta_height', 0)),
inline : 1
},
{
plugin_url : url,
wp: wp
}
);
});
ed.addButton('someplugin_button', {title : 'Insert Seomthing', cmd : 'mcebutton', image: url + '/images/some_button.gif' });
}
});
tinymce.PluginManager.add('someplugin_button', tinymce.plugins.someplugin);
})();
= > "wp: wp". , wp (iframe ...), , tinymce. - ( ed.windowManager.open)!
, : wp javascript:
var args = top.tinymce.activeEditor.windowManager.getParams();
var wp = args.wp;
, / WP.
, , . , , :)