Skip to content

Commit

Permalink
#2 Gravity form delete uploaded file.
Browse files Browse the repository at this point in the history
  • Loading branch information
alimuzzaman committed Feb 24, 2018
1 parent fadcfd1 commit 8d93cd4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/classes/compatibility/gravity-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function module_init($sm){
do_action('sm:sync::register_dir', '/gravity_forms/');
add_filter( 'gform_save_field_value', array($this, 'gform_save_field_value'), 10, 5 );
add_action( 'sm::synced::nonMediaFiles', array($this, 'modify_db'), 10, 3);

add_action( 'gform_file_path_pre_delete_file', array($this, 'gform_file_path_pre_delete_file'), 10, 2);
}


Expand Down Expand Up @@ -70,6 +72,25 @@ public function modify_db( $file_path, $fullsizepath, $media ){
$entries = $wpdb->get_results( $query );
}
}

public function gform_file_path_pre_delete_file( $file_path, $url ){
$file_path = wp_normalize_path($file_path);
$gs_host = wp_normalize_path( ud_get_stateless_media()->get_gs_host() );
$dir = wp_upload_dir();
$is_stateless = strpos($file_path, $gs_host);

if($is_stateless !== false){
$gs_name = substr($file_path, strpos($file_path, '/gravity_forms/'));
$file_path = $dir['basedir'] . $gs_name;

$client = ud_get_stateless_media()->get_client();
if( !is_wp_error( $client ) ) {
$client->remove_media( trim($gs_name, '/') );
}
}

return $file_path;
}
}

}
Expand Down

0 comments on commit 8d93cd4

Please sign in to comment.