将wordpress媒体上传器集成到插件中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将wordpress媒体上传器集成到插件中相关的知识,希望对你有一定的参考价值。

It's a 3 part process, first is the php that you need to run, which includes the appropriate scripts and styles into the admin header, then you need an html button and input field to put the stored value in, then you need some jQuery to open the popup and get the appropriate information from it (then close it again).

There more information on implementation at the URL.
  1. // PHP, adds the appropriate scripts and styles in admin
  2. add_action('admin_print_scripts',array(&$this,'uploader_scripts'));
  3. add_action('admin_print_styles',array(&$this,'uploader_styles'));
  4. public function uploader_scripts(){
  5. wp_enqueue_script('media-upload');
  6. wp_enqueue_script('thinkbox');
  7. }
  8. public function uploader_styles(){
  9. wp_enqueue_style('thickbox');
  10. }
  11.  
  12. // The html for the button and hidden input for result (super simple)
  13. <input id="backdrop_upload_button" value="Upload/Select Image" type="button" class="button" />
  14. <input type="hidden" name="the_image" id="the_image" value="<?= $settings['the_image'] ?>" />
  15.  
  16. // The jQuery to open the media uploader and get the response
  17. var $ = jQuery;
  18. // Handels image uploading
  19. $(document).ready(function(){
  20. $("input#upload_button").click(function(){
  21. tb_show('','media-upload.php?type=image&post_id=1&TB_iframe=true&flash=0&backdrop=true');
  22. return false;
  23. })
  24. window.send_to_editor=function(html){
  25. var img = $('<div>'+html+'</div>').find('img').attr('src');
  26. $('#the_image').val(img);
  27. tb_remove();
  28. };
  29. });

以上是关于将wordpress媒体上传器集成到插件中的主要内容,如果未能解决你的问题,请参考以下文章

php 将复选框自定义元字段添加到媒体上传器wordpress

Wordpress 媒体上传器无法正确上传

需要一种方法来更改 wordpress 媒体上传器 div TB_window css

php 重力形成多文件上传器字段到wordpress媒体附件并添加到CPT的元

无法通过 Wordpress 上传器上传媒体

WordPress 自定义插入到帖子按钮