Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gppa-encrypt-fileupload-field-links.php: Added a snippet that encrypts file upload field links with GPPA. #697

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions gp-populate-anything/gppa-encrypt-fileupload-field-links.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Gravity Perks // Populate Anything // Encrypt File Upload Field Links
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
*
* Encrypt File Upload Links when populated with GP Populate Anything.
*
* Note: This will disable the default behavior of file upload field encryption on Gravity Forms.
* Instead, it will manually encrypt the file upload links directly on the Gravity Forms Entry.
*/
add_filter( 'gform_secure_file_download_location', '__return_false' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling this across the board doesn't seem like a good idea.


// Update 729 and 1 to the Form ID and Field ID of the dynamically populated field loading File Upload field links.
add_filter( 'gform_save_field_value_729_1', 'encrypt_links', 10, 4 );
function encrypt_links( $value, $lead, $field, $form ) {
$upload_root = GFFormsModel::get_upload_url( $form['id'] );
$upload_root = trailingslashit( $upload_root );

if ( strpos( $value, $upload_root ) !== false ) {
$value = str_replace( $upload_root, '', $value );
$download_url = site_url( 'index.php' );
$args = array(
'gf-download' => urlencode( $value ),
'form-id' => $form['id'],

Check warning on line 24 in gp-populate-anything/gppa-encrypt-fileupload-field-links.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Array double arrow not aligned correctly; expected 5 space(s) between &quot;'form-id'&quot; and double arrow, but found 1.
'field-id' => $field['id'],

Check warning on line 25 in gp-populate-anything/gppa-encrypt-fileupload-field-links.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Array double arrow not aligned correctly; expected 4 space(s) between &quot;'field-id'&quot; and double arrow, but found 1.
'hash' => GFCommon::generate_download_hash( $form['id'], $field['id'], $value ),

Check warning on line 26 in gp-populate-anything/gppa-encrypt-fileupload-field-links.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Array double arrow not aligned correctly; expected 8 space(s) between &quot;'hash'&quot; and double arrow, but found 1.
);
$download_url = add_query_arg( $args, $download_url );

return $download_url;
}
return $value;
}
Loading