Last active
June 23, 2022 21:02
-
-
Save gdarko/61b75a9709492054b90227801bb352fb to your computer and use it in GitHub Desktop.
Using WP Vimeo Videos PRO upload modal in your applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Enqueue upload modal | |
*/ | |
function dgv_823828_enqueue_scripts() { | |
if(is_page(1111)) { // check by page or perhaps other condition to avoid enqueuing the script globally. | |
wp_enqueue_style('dgv-upload-modal'); | |
wp_enqueue_script('dgv-upload-modal'); | |
wp_enqueue_script('your-custom-script', 'https://url-to-script/script.js', array('jquery', 'dgv-upload-modal'), null, true); | |
} | |
} | |
add_action('wp_enqueue_scripts', 'dgv_823828_enqueue_scripts'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
// Unique id of the form, used to check if you are targetting the right event. | |
var BUTTON_CONTEXT = 'your_unique_events_namespace'; | |
// This is the value obtained from the modal. | |
// Use this function to save this value somewhere... | |
// In the example we are just printing it in a paragrahph... | |
var load_value = function (uri, context) { | |
if(BUTTON_CONTEXT === context) { | |
$('#yourParagraph').text(uri); | |
} | |
} | |
// Trigger the upload modal on button click | |
$(document).on('click', '#your-upload-button', function (e) { | |
e.preventDefault(); | |
var uploadModal = new WPVimeoVideos.UploaderModal(BUTTON_CONTEXT); | |
uploadModal.open(); | |
}); | |
// Handle the insert result. | |
$(window).on('wpdgv.events.insert', function (e, data) { | |
load_value(data.uri, data.context); | |
}); | |
// Hanlde the upload result. | |
$(window).on('wpdgv.events.upload', function (e, data) { | |
load_value(data.uri, data.context); | |
}); | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This will be populated dynamically (see line 8 in script.js) --> | |
<p id="yourParagraph"></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment