Skip to content

Instantly share code, notes, and snippets.

Avatar

Rafael Ehlers rafaehlers

View GitHub Profile
@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
View gv_claim_entry_by_user_data.php
<?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
View gv-highlight-row-field.php
<?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();
@rafaehlers
rafaehlers / gv_approval_timestamp.php
Created May 18, 2022 18:21
Records a timestamp into a field when the entry approval status is changed
View gv_approval_timestamp.php
<?php // DO NOT COPY THIS LINE
add_action( 'gravityview/approve_entries/updated', 'gv_approval_timestamp', 10, 2 );
function gv_approval_timestamp($entry_id, $status){
if( !class_exists( 'GFAPI' ) ) {
gravityview()->log->error( 'GFAPI does not exist' );
return false;
}
@rafaehlers
rafaehlers / gfexcel-add-title.php
Last active January 28, 2022 22:13
Add a title to the CSV exported file
View gfexcel-add-title.php
<?php //DO NOT LINE
add_filter('gfexcel_renderer_matrix', static function (array $rows) {
// Make up the title
$title = 'text';
// Wrap in array to become a row.
$title = [$title];
array_unshift($rows, $title);
@rafaehlers
rafaehlers / gv-remove-lightbox-pdf.php
Last active January 17, 2022 19:52
Remove Lightbox from PDFs
View gv-remove-lightbox-pdf.php
<?php
add_filter('gravityview/fields/fileupload/files_array', 'gv_modify_files_output_pdf',10,1);
function gv_modify_files_output_pdf($output_arr){
foreach ($output_arr as $key => $value) {
$pdf_exists = strpos($value['file_path'], '.pdf');
if ($pdf_exists !== false) {
$gf_download = strpos($value['file_path'],'?gf-download=');
if ($gf_download == false) {
$gravity_forms = strpos($value['file_path'],'/gravity_forms/');
@rafaehlers
rafaehlers / gv-remove-other-from-search-bar-dropdowns.php
Created January 7, 2022 22:16
If there's an "Other" choice on a dropdown field inside a Search Bar, remove it.
View gv-remove-other-from-search-bar-dropdowns.php
<?php // DO NOT COPY THIS LINE
add_action( 'gravityview_search_widget_fields_before', 'gv_modify_search_fields', 10);
function gv_modify_search_fields( $search_obj ){
foreach( $search_obj->search_fields as $key => &$search_field ) {
if ( $search_field['type'] === 'select' ){
foreach ( $search_field['choices'] as $key => $value ){
@rafaehlers
rafaehlers / gf-calendar-events.php
Last active March 10, 2022 22:15
Modify event colors based on a field value
View gf-calendar-events.php
<?php // DO NOT COPY THIS LINE
/**
* Modify event array that is output to FullCalendar
* In this sample code, we add a background color to a specific event
*
* @param array $events Array of events.
* @param object $form Calendar form.
* @param object $feed Calendar feed.
* @param array $field_map Array of feed fields mapped to calendar settings (e.g., start_time, end_time).
* @param array $entries Array of entries being displayed in the calendar (Requires 1.5.2)
@rafaehlers
rafaehlers / gv-expiration.php
Created June 18, 2021 20:05
Shortcode that receives a date field and calculates it with another date using relative dates
View gv-expiration.php
<?php // DO NOT COPY THIS LINE
//USAGE: [gv_expiration date="2" duration="+1 year"]
// 2 is the field ID of the date field
// If original date is "2021-04-01" it will output "2022-04-01"
// https://docs.gravityview.co/article/79-using-relative-start-dates-and-end-dates
add_shortcode( 'gv_expiration', 'gv_expiration' );
function gv_expiration( $atts ) {
global $gravityview_view;
@rafaehlers
rafaehlers / gravityview_trigger_all_form_feeds.php
Created June 7, 2021 22:20
Trigger all feeds on your form when editing an entry in GravityView
View gravityview_trigger_all_form_feeds.php
<?php // DO NOT COPY THIS LINE
add_action( 'gravityview/edit_entry/after_update', 'gravityview_trigger_feeds', 10, 3 );
function gravityview_trigger_feeds( $form = array(), $entry_id = array(), $object ) {
if ( 100 !== (int) $form['id'] ) { // replace 100 with your form ID
return;
}
@rafaehlers
rafaehlers / gravityview_trigger_webhooks_feed.php
Created June 3, 2021 18:45
Trigger WebHook feeds on your form when editing an entry in GravityView
View gravityview_trigger_webhooks_feed.php
<?php // DO NOT COPY THIS LINE
add_action( 'gravityview/edit_entry/after_update', 'gravityview_trigger_webhooks_feed', 10, 3 );
function gravityview_trigger_webhooks_feed( $form = array(), $entry_id = array(), $object ) {
if ( 100 !== (int) $form['id'] ) { // replace 100 with your form ID
return;
}