jQuery(document).ready(function ($) { 'use strict'; $(document).on("click", ".upload_image_button", function (e) { e.preventDefault(); var $button = $(this); // Create the media frame. var file_frame = wp.media.frames.file_frame = wp.media({ title: 'Select or upload image', library: { // remove these to show all type: 'image' // specific mime }, button: { text: 'Select' }, multiple: false // Set to true to allow multiple files to be selected }); // When an image is selected, run a callback. file_frame.on('select', function () { // We set multiple to false so only get one image from the uploader var attachment = file_frame.state().get('selection').first().toJSON(); console.log(attachment.url); $button.parent().find('.input-image-field').val(attachment.url); }); // Finally, open the modal file_frame.open(); }); function initialValue() { return $('input[name=_customize-radio-azurelo_slider_display_type]:checked').val(); } function selectRadio(initialValue) { var sliderCategory = $('#customize-control-azurelo_slider_category'); var sliderPost = $('#customize-control-azurelo_slider_id'); if (initialValue === 'category') { sliderPost.hide(); sliderCategory.show(); } else if (initialValue === 'post') { sliderCategory.hide(); sliderPost.show(); } else { sliderPost.hide(); sliderCategory.hide(); } } setTimeout(function(){ var succeed = initialValue(); if (!succeed) initialValue(); else selectRadio(succeed); }, 1000); $(document).on("change", "input[name=_customize-radio-azurelo_slider_display_type]", function (e) { e.preventDefault(); var value = $('input[name=_customize-radio-azurelo_slider_display_type]:checked').val(); var sliderCategory = $('#customize-control-azurelo_slider_category'); var sliderPost = $('#customize-control-azurelo_slider_id'); if (value === 'category') { sliderPost.hide(); sliderCategory.show(); } else if (value === 'post') { sliderCategory.hide(); sliderPost.show(); } else { sliderPost.hide(); sliderCategory.hide(); } }); });