Created
April 14, 2020 15:40
-
-
Save glaubersilva/50371394d9dcbaafef7a11ad08a86038 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Plugin Name: [LuxFlow] Load Custom Javascript | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: Load example javascript to manipulate elements on this page:: https://www.luxflow.in/?gf_page=preview&id=80 | |
* Author: Glauber Silva @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* Task: 0/11289012348292/1170810850944044 | |
* License: GPLv2 or later | |
* | |
* @package LuxFlow_Load_Custom_Javascript | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
/** | |
* Add the JS code in the footer of the pages | |
*/ | |
function wpmudev_load_custom_js() { | |
ob_start(); | |
?> | |
<script type="text/javascript"> | |
window.onload = function () { | |
var element = document.querySelector('#input_80_1'); | |
if(typeof(element) != 'undefined' && element != null){ | |
console.log('Element exists | Fired here: /wp-content/mu-plugins/wpmudev-load-custom-javascript.php'); | |
document.querySelector('#input_80_1').addEventListener('change', function() { | |
//change event will be triggered once the image was selected. | |
if(document.querySelector('#input_80_1').files.length == 0) { | |
alert('Error : No file selected'); | |
return; | |
} | |
var nameInput = document.getElementById("input_80_1").files[0]; | |
console.log("Selected file : " + nameInput.name); | |
// You can get file information in this way | |
console.log( | |
"file info" + | |
nameInput.name + '\n'+ | |
nameInput.size + '\n'+ | |
nameInput.type + '\n'+ | |
nameInput.lastModified | |
); | |
}); | |
} else{ | |
console.log('Element does not exist! | Fired here: /wp-content/mu-plugins/wpmudev-load-custom-javascript.php'); | |
} | |
}; | |
</script> | |
<?php | |
$javascript = ob_get_clean(); | |
echo $javascript; // phpcs:ignore | |
} | |
add_filter( 'wp_footer', 'wpmudev_load_custom_js', PHP_INT_MAX ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment