Support » Plugin: WordPress File Upload » Javascript execution after successful upload

  • Resolved nikpar

    (@nikpar)


    Hello Nickola,
    I need to run a javascript that will do some changes to the image of the page after the file (image actually) will be uploaded successfully from the plugin. Is there an event or a listener to triger the script?

    I noticed to an answer you provided about 8 months ago that you used “… if ( $file[“upload_result”] == “success” …” in a php function but I cannot figure out how i could use that in a javascript function. As an example. for another plugin I used “… $(‘.quform-form-9’).on(‘quform:successStart’, function () …” but the quform:successStart listener was in the plugin’s code.

    Best regards,
    Nick Paraskevopoulos

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author nickboss

    (@nickboss)

    Geia sou Nick,

    Use the following code to run the Javascript code defined in $changable_data[“js_script”]:

    if (!function_exists('wfu_after_upload_handler')) {
    	function wfu_after_upload_handler($changable_data, $additional_data) {
    		foreach ( $additional_data["files"] as $file ) {
    			if ( $file["upload_result"] == "success" || $file["upload_result"] == "warning" ) {
    				$filepath = $file["filepath"];
    				$url = str_replace(ABSPATH, site_url().'/', $filepath);
    				$changable_data["js_script"] = "
    					//custom Javascript code here without <script> tags
    				";
    				break;
    			}
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
    }

    So set in $changable_data[“js_script”] the code you want. I also provide the URL of the image in a variable.

    The code will run on user’s browser right after the file is uploaded.

    Put the above code in functions.php file of your theme.

    Filika

    Nikos

    Wonderful, it worked great. You rock, thank you very much!

    Plugin Author nickboss

    (@nickboss)

    Ok thanks for letting me know.

    Regards

    Nickolas

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.