Skip to content

Instantly share code, notes, and snippets.

View rafaehlers's full-sized avatar

Rafael Ehlers rafaehlers

View GitHub Profile
@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 );
@rafaehlers
rafaehlers / gk_custom_excel_filename.php
Last active April 25, 2025 03:42
Change GravityExport Lite export filename
<?php // DO NOT COPY THIS LINE
/**
* Change GravityExport Lite export filename.
*
* Hook: gfexcel_renderer_filename ← all forms
* gfexcel_renderer_filename_{ID} ← one specific form
*
* @param string $filename The filename generated by the plugin.
* @param int $form_id (Since v1.6) ID of the form being exported.
@rafaehlers
rafaehlers / gk-duplicate-on-approval.php
Created April 17, 2025 19:43
Duplicate an entry on approval if conditions match
<?php // DO NOT COPY THIS LINE
function custom_duplicate_gf_entry( $entry_id ) {
if ( ! class_exists( 'GravityView_Duplicate_Entry' ) ) {
return new WP_Error( 'missing_class', 'GravityView_Duplicate_Entry class not found.' );
}
$entry = GFAPI::get_entry( $entry_id );
if ( is_wp_error( $entry ) ) {
return $entry;
@rafaehlers
rafaehlers / gk-dt-buttons-excel-urls.js
Created February 11, 2025 21:06
DataTables > Buttons > Excel > Include URLs on export
document.addEventListener('DOMContentLoaded', function () {
wp.hooks.addFilter('gk.datatables.options', 'dt-custom-code', function (options) {
options.buttons = options.buttons.map(button => {
if ('excel' === button.extend) {
button.exportOptions = {
// stripHtml: false,
format: {
body: function (data, row, column, node) {
// Check if the cell data contains an anchor tag
if (data.indexOf('<a') !== -1) {
@rafaehlers
rafaehlers / gk-gravityflow-gv-filter.php
Last active December 5, 2024 18:19
Filtering entries by GravityView's Approval Statuses on Gravity Flow's Workflow Status page
add_filter( 'gravityflow_field_filters_status_table', 'field_filters_status_expired', 10, 1 );
function field_filters_status_expired( $field_filters ) {
foreach ( $field_filters as $form => $filters ) {
if ( $form == '185' ) { // CHANGE 185 WITH YOUR FORM ID
$field_filters[ $form ][] = array(
'key' => 'is_approved',
'text' => 'View Approval Status',
'operators' => array ( 'is', 'isnot' ),
'values' => array(
array( 'value' => '1', 'text' => 'Approved' ),
@rafaehlers
rafaehlers / gk_cancel_close_lightbox.php
Created October 28, 2024 18:53
Edit Entry: Change the action of the Cancel button to close the lightbox
<?php // DO NOT COPY THIS LINE
function custom_cancel_onclick_js( $back_link, $form, $entry, $view_id, $update_count ) {
$run_on_views = [2334]; //Change this to the IDs of the Views you'd like to run this filter [100,200,300,...]
if( in_array( $view_id, $run_on_views ) ){
return 'window.parent.postMessage({closeFancybox: true}, "*"); return false;';
}
}
add_filter( 'gravityview/edit_entry/cancel_onclick', 'custom_cancel_onclick_js', 100, 5 );