Skip to content

Instantly share code, notes, and snippets.

View rafaehlers's full-sized avatar

Rafael Ehlers rafaehlers

View GitHub Profile
@rafaehlers
rafaehlers / gk-modify-file-array.php
Created October 26, 2023 01:35
Modify the output of a File Upload field
<?php // DO NOT COPY THIS LINE
add_filter('gravityview/fields/fileupload/files_array', 'gv_modify_files_output',10,1);
function gv_modify_files_output($output_arr){
foreach ($output_arr as $key => $value) {
$output_arr[$key]['content'] = '<a href="'.$value['file_path'].'" target="_blank"><span class="dashicons dashicons-media-default"></span></a>';
}
return $output_arr;
}
@rafaehlers
rafaehlers / gk_trigger_gravityexport_feeds.php
Created September 13, 2023 21:44
Trigger a GravityExport Save feed after editing an Entry in GravityView
<?php // DO NOT COPY THIS LINE
add_action( 'gravityview/edit_entry/after_update', 'gk_trigger_gravityexport_feeds', 10, 3 );
function gk_trigger_gravityexport_feeds( $form = array(), $entry_id = array(), $object ) {
$form_ids = array( 10, 85, 77 );
// Check if the form ID matches any of the expected values
if ( ! in_array( (int) $form['id'], $form_ids ) ) {
@rafaehlers
rafaehlers / gk-urlify-list-fields.php
Last active August 29, 2023 21:24
List Field Merge Tag Modifier to convert text URLs into clickable links
<?php // DO NOT COPY THIS LINE
add_filter( 'gform_merge_tag_filter', 'gv_list_columns', 30, 6 );
function gv_list_columns( $value, $merge_tag, $modifier, $field, $raw_value, $format ) {
if ( $field->type == 'list' && $merge_tag != 'all_fields' && 'urlify' === $modifier ) {
$values = unserialize( $raw_value );
$output = '<ul>';
@rafaehlers
rafaehlers / gk-search-states.php
Created August 28, 2023 20:05
Convert state name search to state abbreviations
add_filter( 'gravityview_fe_search_criteria', function ( $search_criteria ) {
if ( empty( $search_criteria['field_filters'] ) ) {
return $search_criteria;
}
foreach ( $search_criteria['field_filters'] as &$filter ) {
if ( $filter['value'] == 'Alabama' ) { $filter['value'] = 'AL';}
if ( $filter['value'] == 'Alaska' ) { $filter['value'] = 'AK';}
if ( $filter['value'] == 'Arizona' ) { $filter['value'] = 'AZ';}
@rafaehlers
rafaehlers / gv-remote-entry-approval-notes.php
Last active March 10, 2023 19:56
Prevent Entry Approval Notes from displaying on the View
<?php // DO NOT COPY THIS LINE
add_filter( 'gravityview/entry_notes/get_notes', 'gv_remove_entry_approval_notes', 10, 2 );
function gv_remove_entry_approval_notes( $notes, $entry_id ) {
foreach($notes as $key => $note){
if (strpos( $note->value, 'WordPress') !== false){
unset( $notes[ $key] );
}
}
return $notes;
@rafaehlers
rafaehlers / gv-divi-widgets.php
Created March 6, 2019 23:29
Prevent a DIVI powered theme from disabling GravityView's widgets when the View is embedded in a page
<?php //Remove this line
add_filter( 'et_grab_image_setting', function( $default ) {
if ( gravityview()->request->is_view() ) return false;
return $default;
} );
@rafaehlers
rafaehlers / gv-entry-approval-filters.php
Created February 28, 2023 18:16
GravityView filters for entry approval
<?php // DO NOT COPY THIS LINE
add_action( 'gravityview/approve_entries/disapproved', 'gv_custom_function',10,1);
add_action( 'gravityview/approve_entries/unapproved', 'gv_custom_function',10,1);
add_action( 'gravityview/approve_entries/updated', 'gv_custom_function',10,1);
add_action( 'gravityview/approve_entries/approved', 'gv_custom_function',10,1);
function gv_custom_function($entry_id){
$entry = GFAPI::get_entry( $entry_id );
$form = GFAPI::get_form( $entry['form_id'] );
@rafaehlers
rafaehlers / gv-edit-entry-validation.php
Last active February 22, 2023 23:59
GravityView - Prevent a required field from being required on Edit Entry page
<?php // DO NOT COPY THIS LINE
add_filter( 'gform_pre_render', 'gravityview_edit_entry_dont_require_fields' );
add_filter( 'gform_pre_validation', 'gravityview_edit_entry_dont_require_fields' );
function gravityview_edit_entry_dont_require_fields( $form ) {
if ( ! class_exists( '\GravityView_View' ) ) {
return $form;
}
@rafaehlers
rafaehlers / gv_claim_entry_by_user_data.php
Created November 29, 2022 21:13
Modify whether the currently logged-in user can edit an entry that was not created by him - Several Views
<?php // DO NOT COPY THIS LINE
add_filter('gravityview/edit_entry/user_can_edit_entry', 'gv_claim_entry_by_user_data', 20, 3 );
/**
* Modify whether the currently logged-in user can edit an entry that was not created by him
*
* @param boolean $user_can_edit Can the current user edit the current entry? (Default: false)
* @param array $entry Gravity Forms entry array
* @param int $view_id ID of the view you want to check visibility against {@since 1.15}
*
@rafaehlers
rafaehlers / gv-highlight-row-field.php
Created June 10, 2022 20:41
Highlight an entire row if entry was created by currently logged-in user
<?php // DO NOT COPY THIS LINE
add_filter( 'gravityview/template/table/entry/class', function( $class, $context ) {
if ( ! is_user_logged_in() ) {
return $class;
}
$view_id = $context->view->ID;
$current_user_id = get_current_user_id();