Skip to content

Instantly share code, notes, and snippets.

View rafaehlers's full-sized avatar

Rafael Ehlers rafaehlers

View GitHub Profile
@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 );
@rafaehlers
rafaehlers / gk-approval-data.php
Last active October 15, 2024 23:54
Store the username and the date of the entry approval
<?php // DO NOT COPY THIS LINE
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'] );
$run_on_views = [100,200]; //Change this to the IDs of the Views you'd like to run this code
@rafaehlers
rafaehlers / gk-explode-modifier.php
Last active October 1, 2024 21:20
:explode merge tag modifier for use on GravityCalendar event titles
<?php // DO NOT COPY THIS LINE
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value ) {
if( 'all_fields' !== $merge_tag && 'explode' === $modifier ) {
$choices = explode(',', $value);
foreach ($choices as $key => $choice) {
$output .= $choice.'<br>';
}
@rafaehlers
rafaehlers / gk_custom_remove_field.php
Last active September 18, 2024 22:08
Hide field from GravityView's Edit Entry page when the Edit Entry layout is left empty in the View editor
<?php // DO NOT COPY THIS LINE
add_filter( 'gravityview/edit_entry/form_fields', function ( $gf_fields, $edit_entry_fields, $form, $view_id ) {
if ( 1 !== $view_id ) { // Replace 1 with the View ID you want to target.
return $gf_fields;
}
foreach ( $gf_fields as $index => $field ) {
if ( 2 === $field->id ) { // Replace 2 with the Field ID you want to hide.
unset( $gf_fields[ $index ] );
@rafaehlers
rafaehlers / gv-download_links.php
Last active September 10, 2024 00:35
Shortcode to output a download button after receiving a file upload field Merge Tag. It supports multiple files.
@rafaehlers
rafaehlers / gk_exact_match_fields.php
Created July 31, 2024 19:16
Only performs a search if the search exactly matches the field values
<?php // DO NOT COPY THIS LINE
add_filter( 'gravityview_fe_search_criteria', 'gk_exact_field', 10, 2 );
/**
* @param array $search_criteria
* @param int $form_id
*
* @return array Modified search, if it's the current form
*/
@rafaehlers
rafaehlers / gk_trigger_workflow_after_duplication.php
Last active July 11, 2024 00:44
Trigger workflow after duplicating an entry in GravityView
<?php // DO NOT COPY THIS LINE
add_action( 'gravityview/duplicate-entry/duplicated', 'gk_run_stuff_after_duplication', 10, 2 );
function gk_run_stuff_after_duplication($duplicated_entry, $entry){
$form_id = $duplicated_entry['form_id'];
$form = GFAPI::get_form( $form_id );
$run_on_forms = [92]; //The IDs of the Forms you'd like to affect. To target more forms, use [36,81,12] as an example
if( !in_array( $form['id'], $run_on_forms ) ){
@rafaehlers
rafaehlers / gk_dt_widgets.php
Created May 9, 2024 18:51
Deactivate DataTables widgets
<?php //DO NOT COPY THIS LINE
add_filter( 'gravityview_datatables_js_options', function( $dt_config, $view_id, $post ) {
$run_on_views = [100,200]; //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 ) ){
$dt_config['lengthChange'] = false;
$dt_config['paging'] = false;
$dt_config['searching'] = false;
@rafaehlers
rafaehlers / gk-dt-buttons-pdf-logo.js
Last active April 17, 2024 21:14
DataTables > Buttons > PDF > Include a logo
document.addEventListener( 'DOMContentLoaded', function () {
wp.hooks.addFilter( 'gk.datatables.options', 'dt-custom-code', function ( options ) {
options.buttons = options.buttons.map( button => {
if ( 'pdf' === button.extend ) {
button.customize = function ( doc ) {
doc.content.splice( 1, 0, {
margin: [ 0, 0, 0, 12 ],
alignment: 'center',
width: 200,
height: 80,