• Хочу сделать загрузку изображений в виджет.

    Html код в разделе «public function form( $instance )» виджета:

    <!— Image Thumbnail —>
    <img class=»custom_media_image» src=»» style=»max-width:100px; float:left; margin: 0px 10px 0px 0px; display:inline-block;» />

    <!— Upload button and text field —>
    <input class=»custom_media_url» id=»» type=»text» name=»» value=»» style=»margin-bottom:10px; clear:right;»>
    Upload`

    Js код:

    `jQuery( document ).ready( function() {

    function image_upload( button_class ) {

    var _custom_media = true,
    _orig_send_attachment = wp.media.editor.send.attachment;

    jQuery( ‘body’ ).on( ‘click’, button_class, function(e) {

    var send_attachment_bkp = wp.media.editor.send.attachment;
    var button = jQuery(this);

    wp.media.editor.send.attachment = function(props, attachment) {

    jQuery(button).prev().prev().attr(‘src’, attachment.url);
    jQuery(button).prev().val(attachment.url);

    wp.media.editor.send.attachment = send_attachment_bkp;
    }

    wp.media.editor.open(button);

    return false;
    });
    }
    image_upload( ‘.custom_media_upload’ );

    });`
    `
    (wp_enqueue_media(); — подклюено в файле functions.php)

    Выдает ошибку: Uncaught TypeError: Cannot read property ‘value’ of null

    Вроде бы жалуется на; document.getElementById(d).value+=a……

    Как с этой ошибкой бороться?

  • Тема «загрузка изображений в виджет» закрыта для новых ответов.