All categories
  • All categories
  • 未分类
  • 初创
  • 应用

如何在WordPress后台的某个页面里添加上传按钮

如果你需要在后台某个页面添加上传按钮,你需要用到wp_enqueue_media()这个函数,用于引入上传所需组件。

add_action ( 'admin_enqueue_scripts', function () {
if (is_admin ())
wp_enqueue_media ();
} );

html代码例如:

<p>
<input type="number" value="" class="regular-text process_custom_images" id="process_custom_images" name="" max="" min="1" step="1">
<button class="set_custom_images button">Set Image ID</button>
</p>

js代码例如:

jQuery(document).ready(function() {
var $ = jQuery;
if ($('.set_custom_images').length > 0) {
if ( typeof wp !== 'undefined' && wp.media && wp.media.editor) {
$(document).on('click', '.set_custom_images', function(e) {
e.preventDefault();
var button = $(this);
var id = button.prev();
wp.media.editor.send.attachment = function(props, attachment) {
id.val(attachment.url);
};
wp.media.editor.open(button);
return false;
});
}
}
});

1.原文链接:https://8aaafs.com/archives/2155,转载请保留原文链接谢谢!
2.本站所有资源文章出自互联网收集整理,本站不参与制作,如果侵犯了您的合法权益,请联系本站我们会及时删除。
3.本站发布资源来源于互联网,可能存在水印或者引流等信息,请用户擦亮眼睛自行鉴别,做一个有主见和判断力的用户。
4.本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。
5.联系方式(#替换成@):VitoriaGFerreira#proton.me

0

Comments0

Please first
Captcha