web-dev-qa-db-ja.com

メディアのアップロードがWordPress 3.8.1のテーマオプションで機能しない

私は自分のプラグインにこのjQueryコードを持っていて、できれば画像をアップロードしたり、メディアギャラリーから画像を選んだりするためにメディアボックスを表示します。

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

$('#upload_image_button').click(function(e) {

    e.preventDefault();

    //If the uploader object has already been created, reopen the dialog
    if (custom_uploader) {
        custom_uploader.open();
        return;
    }

    //Extend the wp.media object
    custom_uploader = wp.media.frames.file_frame = wp.media({
        title: 'Choose Image',
        button: {
            text: 'Choose Image'
        },
        multiple: false
    });

    //When a file is selected, grab the URL and set it as the text field's value
    custom_uploader.on('select', function() {
        attachment = custom_uploader.state().get('selection').first().toJSON();
        $('#upload_image').val(attachment.url);
    });

    //Open the uploader dialog
    custom_uploader.open();

});

});
})(jQuery);

とあなたは私のプラグインのオプションで、そのjQueryコードにバインドする次の要素です。

<input class="nput" id="upload_image" type="text" name="the_box[authorpic]" value="<?php echo $options['authorpic']; ?>" />&nbsp;<input class="button-primary" id="upload_image_button" type="button" value="Pick From Gallery" />

しかし、今では機能しません。今はボタンをクリックまたは押してもメディアボックスが表示されているはずなので(WordPress 3.8.1を使用しています)、何も表示されません。 jQueryスクリプト(私はそれをテストしました).

これが機能しなくなる原因は何ですか?任意のアイデア、推奨事項や提案は大歓迎です。前もって感謝します。

1
Juliver Galleto

先頭から(function($){を、末尾から})(jQuery);を削除してみてください。そしてjQuery(document).ready(function()jQuery(document).ready(function($)に変更してください。

1
Jaeeun Lee