Support

Account

Home Forums ACF PRO Rename files upon uploading Reply To: Rename files upon uploading

  • If I insert the code from add_attachment to after_save_post as below, then I end up with ‘double images’ because the image does gets renamed, but in a new file. It doesn’t rename the current file.

    The new files names are linked to the post, the original file names are not and thus they can not be deleted with a function, otherwise the issue would be solved.

    if ( false == $image_is_approved ) {
    
        $file = $this->get_location_of_attachment_file( $stored_profile_pic );
        if ( false !== $file ) {
            $path        = pathinfo( $file );
            $newfilename = $this->getToken( 10 );
            $newfile = $path[ 'dirname' ] . "/" . $newfilename . "." . $path[ 'extension' ];
    
            rename( $file, $newfile );
            update_attached_file( $stored_profile_pic, $newfile );
        }
    
        global $wpdb;