Skip to content

Instantly share code, notes, and snippets.

View rafaehlers's full-sized avatar

Rafael Ehlers rafaehlers

View GitHub Profile
@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,
@rafaehlers
rafaehlers / gk-dt-buttons-pdf-links.php
Created April 17, 2024 20:39
DataTables > Buttons > PDF > Include links on export
@rafaehlers
rafaehlers / gk-dt-buttons-print-URLs.js
Created April 17, 2024 19:41
DataTables > Buttons > Print > Display link URLs
document.addEventListener('DOMContentLoaded', function() {
wp.hooks.addFilter( 'gk.datatables.options', 'dt-custom-code', function ( options ) {
options.buttons = options.buttons.map( button => {
if ( 'print' === button.extend ) {
button.exportOptions = {
stripHtml: false
}
}
return button;
} );
@rafaehlers
rafaehlers / gk-dt-buttons-PDF-images.js
Last active April 17, 2024 20:35
DataTables > Buttons > PDF > Include images on export
document.addEventListener('DOMContentLoaded', function() {
wp.hooks.addFilter( 'gk.datatables.options', 'dt-custom-code', function ( options ) {
options.buttons = options.buttons.map( button => {
if ( button.extend !== 'pdf' ) {
return button;
}
button.action = function ( e, dt, button, config ) {
const promises = [];
@rafaehlers
rafaehlers / gk-dt-buttons-PDF-image-URLs.js
Last active April 17, 2024 19:27
DataTables > Buttons > PDF > Show Image URLs
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 ) {
const originalBodyFunction = button.exportOptions?.format?.body;
button.exportOptions = button.exportOptions || {};
button.exportOptions.format = button.exportOptions.format || {};
@rafaehlers
rafaehlers / gv_dt_refresher.php
Created March 25, 2024 22:30
Refreshes a View using DataTables after inline editing a field
<?php // DO NOT COPY THIS LINE - Code shared by Rob Davis
namespace GravityView_Refresher_26096;
class Refresher {
// Form ID in question.
public $form_id = 18;
// View ID in question.
public $view_id = 26096;
@rafaehlers
rafaehlers / gv_single_rating.php
Created March 18, 2024 22:29
Allow multiple reviews but only the first has ratings
<?php // DO NOT COPY THIS LINE
add_filter( 'gv_ratings_reviews_ratings_allowed', function ( $is_allowed, $_, $__, $view ) {
if ( ! $is_allowed || ! $view instanceof GravityView_View ) {
return $is_allowed;
}
global $gv_ratings_reviews;
$post_bridge_comp = $gv_ratings_reviews->component_instances['post-bridge'];
@rafaehlers
rafaehlers / gk-allow-logged-out.php
Created January 16, 2024 20:11
Allow logged-out users to edit entrie
<?php //DO NOT COPY THIS LINE
// Removes Edit Entry "nonce" validation. Edit Entry checks whether an user has the ability to edit an entry, but it also checks a "nonce" to make sure that the Edit Entry link was recently generated by the current user visiting the page. This can sometimes cause problems; this code removes that "nonce" validation.
add_filter( 'gravityview/edit_entry/verify_nonce', '__return_true' );
// allow non logged-in users to edit entries
add_filter( 'gravityview/edit_entry/user_can_edit_entry', '__return_true' );
add_filter( 'gravityview/capabilities/allow_logged_out', '__return_true' );
add_filter( 'user_has_cap', function( $caps ) {
$caps['gravityview_edit_others_entries'] = true;