validateFile
function is triggered when user upload image to Media Library.
How do I pass $file
to php_vars
? So that I can manipulate the php_vars
value inside validation.js
$myArray = array();
add_action('admin_enqueue_scripts', 'registerValidationScript');
function registerValidationScript() {
global $myArray;
wp_enqueue_script( 'my_js_library', get_template_directory_uri() . '/js/validation.js' );
wp_localize_script( 'my_js_library', 'php_vars', $myArray);
};
add_filter('wp_handle_upload_prefilter', 'validateFile' );
function validateFile( $file ){
array_push($myArray, $file);
return $file;
}
** Edit **
I think this question is bit different with possible duplication.
Reason is, I'm trying to get PHP variable that only available after 'post back'. Meaning, after user upload the picture to Media Library. Hence the usage of wp_handle_upload_prefilter
hook.