What are the two numbers in the filter examples?

I cannot for the life of me find a help reference for this one - yet the example is everywhere.

Take this for example:

add_filter("gform_upload_path", "change_upload_path", 10, 2);

What is 10, and what is 2? What do those numbers refer to?


Those are WordPress conventions (not related to Gravity Forms at all). The 10 is priority the filter runs at (10 is default; lower numbers would be run earlier) and 2 is the number of arguments the filter accepts. For gform_upload_path, the two arguments are $path_info, $form_id.


That’s exactly what I needed.

Thank you!

One further question: What is the best way to apply a filter to a specific form?

For example I have a form named “Example Upload Form” and it’s form ID 15.

I actually do want to change the upload directory, but am unsure how to limit the change to just this one form.

Example code:

    add_filter("gform_upload_path", "change_upload_path", 10, 2);
   function change_upload_path($path_info, $form_id){
     $uniquefolder = rand(1,9999);
     $uniqueid = uniqid('your-reference', true);
     $path_info["path"] = "/new-upload-directory";
     $path_info["url"] = "someplace/new-upload-directory"; return $path_info;

Some filters accept the form ID as part of the filter name, like this:

add_filter( 'gform_pre_render_6', 'your_function_name' );

The gform_upload_path filter does not. But the form ID is passed in as a parameter, so you can test for it in your code. Something like this:

add_filter( "gform_upload_path", "change_upload_path", 10, 2 );
function change_upload_path( $path_info, $form_id ){
	if ( $form_id == 17 ) {
		// only apply this code for form 17
		$uniquefolder = rand( 1,9999 );
		$uniqueid = uniqid( 'your-reference', true );
		$path_info["path"] = "/new-upload-directory";
		$path_info["url"] = "someplace/new-upload-directory"; 
	// always return $path_info, even if unmodified
	return $path_info;