我已将媒体按钮作为post meta field 在以下情况下将图像URL插入文本字段Insert Into Page 单击按钮。它一直工作到打开“媒体存储库”窗口、选择“图像”和“插入”为止,但没有向输入字段传递任何值。
<人力资源/>
Expected result
结果应该是URL和媒体ID插入为
https://avalon.com/dev/wp-content/uploads/2021/01/scp7147prko31.jpg|12
但没有返回值。我可以手动输入URL并保存数据。
我彻底扫描了我的代码,并尝试了许多javascript方法,我认为这是失败的根源。调试控制台指示名为的预期函数存在故障
tabs
与插件关联
classic editor 但我找不到这样的。我甚至禁用了插件,失败依然存在。
I\'ve stared down the code for now 4 hours and cannot define a solution, so I am seeking assistance to resolve.
Console Log
Uncaught TypeError: $(...).tabs is not a function
<anonymous> https://avalon.com/dev/wp-admin/post.php?post=2&action=edit&classic-editor&message=1:300
jQuery 2
mightThrow
process
post.php:300:21
代码
public static function mediabutton($fname, $value)
{
add_action(\'admin_enqueue_scripts\', function() {
wp_enqueue_media();
});
$js = \'<script>
jQuery(function($)
{
if( $(".mb-insertimg").length > 0 )
{
if( typeof wp !== "undefined" && wp.media && wp.media.editor ) {
$(".mb-insertimg").on("click", function(e) {
e.preventDefault();
wp.media.editor.send.attachment = function(props, attachment) {
$("#mb-socialimg").val(wp.media.attachment(attachment.id).get("url")+"|"+attachment.id);
};
wp.media.editor.open($(this));
return false;
});
}
}
$("a.clearit").on("click", function() {
$("#mb-socialimg").val("");
});
});
</script>\';
$thumb= $imgUrl=\'\';
if( !empty($value) )
{
if( strstr($value, \'|\') ) {
list($imgUrl, $imgId) = explode(\'|\', $value);
$tid = wp_get_attachment_image_src($imgId, \'thumbnail\');
$thumb = \'<img src="\'.$tid[0].\'" />\';
}else{
$imgUrl = $value;
$thumb = \'<img src="\'.$value.\'" />\';
}
}
$img = \'
<div class="mb-imginsert">
<span><input type="text" id="mb-socialimg" name="\'.$fname.\'" value="\'.$imgUrl.\'" /></span>
<span><button class="mb-insertimg button">Select Image</button></span>
<span><a class="button clearit dashicons dashicons-no" style="width: auto;" href="javascript:;"></a></span>
<span>\'.$thumb.\'</span>
</div>
\'.$js;
return $img;
}