Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
rafaehlers / gk_store_who_updated.php
Last active July 28, 2025 23:59
Store the username of the user that last modified the entry
<?php // DO NOT COPY THIS LINE
add_action( 'gravityview/edit_entry/after_update', 'gv_custom_function', 10, 3 );
function gv_custom_function( $form = array(), $entry_id = array(), $object ){
$run_on_views = [4049]; //Change this to the IDs of the Views you'd like to run this code
$view_id = GravityView_View::getInstance()->getViewId();
if( !in_array( $view_id, $run_on_views ) ){
return false;
@rafaehlers
rafaehlers / gravityexport_format_date_excel.php
Created July 23, 2025 23:22
This code snippet will format field id 6 on form 2 as a date field in excel
<?php // DO NOT COPY THIS LINE
$binder = new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder();
add_filter( 'gfexcel_renderer_cell_properties_2', function ( \PhpOffice\PhpSpreadsheet\Cell\Cell $cell, \GFExcel\Values\BaseValue $value ) use ( $binder ) {
if ( $value->getFieldId() == 6 && $cell->getRow() > 1 ) {
$old_binder = \PhpOffice\PhpSpreadsheet\Cell\Cell::getValueBinder();
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( $binder );
$cell->setValue( $value->getValue() );
$cell
@rafaehlers
rafaehlers / gk_file_upload_modifier.php
Created July 2, 2025 05:09
Merge Tag modifier to output file upload links with filenames
<?php // DO NOT COPY THIS LINE
add_filter( 'gform_secure_file_download_location', '__return_false' );
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value ) {
if ( 'all_fields' !== $merge_tag && 'linker' === $modifier ) {
// Split on <br> tags, line breaks, or commas
$files = preg_split('/<br\s*\/?>|\r\n|\r|\n|,/', trim($value));
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rafaehlers
rafaehlers / gk-dt-buttons-excel-html.js
Created May 21, 2025 23:04
DataTables > Buttons > Excel > Exclude HTML tags on export
document.addEventListener('DOMContentLoaded', () => {
wp.hooks.addFilter('gk.datatables.options', 'gv-strip-html-excel', (opts) => {
opts.buttons = opts.buttons.map((btn) => {
if (btn.extend === 'excel') {
// Ensure the sub-objects exist
btn.exportOptions = btn.exportOptions || {};
@rafaehlers
rafaehlers / gv_custom_icon_for_file_type.php
Last active May 15, 2025 19:39
Output a custom image icon for every uploaded file type in GravityView.
<?php // DO NOT COPY THIS LINE
/**
* Output a custom image icon for every uploaded file type in GravityView.
*
* @filter gravityview/fields/fileupload/files_array
*
* @param array $output_arr Array of uploaded files passed by GravityView.
* @return array Modified array with icon-image output.
*/
@rafaehlers
rafaehlers / gv_iconify_fileupload_output.php
Created May 15, 2025 19:25
Replace File-Upload output with an icon that matches the file type.
<?php // DO NOT COPY THIS LINE
/**
* Replace File-Upload output with an icon that matches the file type.
*
* @see https://github.com/GravityKit/GravityView/blob/a6584d8a/includes/fields/class-gravityview-field-fileupload.php#L455
* @filter gravityview/fields/fileupload/files_array
*
* @param array $output_arr Array of files, one item per uploaded file.
* @return array Modified array with icon-only output.
@rafaehlers
rafaehlers / gk_remove_due_choice.php
Created May 14, 2025 21:10
Remove the “Due” choice from a specific Drop Down field on Inline Edit (GravityEdit)
<?php // DO NOT COPY THIS LINE
/**
* Remove the “Due” choice from a specific Drop Down field.
*
* – change 123 to your form ID
* – change 456 to your View ID
* – change 789 to your dropdown field ID
*
*/
@rafaehlers
rafaehlers / gk_note_on_trash.php
Created May 9, 2025 23:29
Adds an entry note with information about the user who moved the entry to the trash.
<?php // DO NOT COPY THIS LINE
/**
* Add a note whenever a Gravity Forms entry is moved to the Trash.
*
* Hook: gform_update_status — fires when an entry’s status changes
* (e.g., active → trash, spam → active).
*/
add_action( 'gform_update_status', 'gk_note_on_trash', 10, 3 );