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-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-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-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-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 / gv_approval_timestamp.php
Created May 18, 2022 18:21
Records a timestamp into a field when the entry approval status is changed
<?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 / 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;
@rafaehlers
rafaehlers / gk_math_second_form.php
Last active December 21, 2023 21:13
Filter for GravityMath to pull records from a secondary form
<?php // DO NOT COPY THIS LINE
add_filter( 'gravityview/math/shortcode/before', function ( $formula ) {
preg_match_all( '/~[^~]*?:(\d+(\.\d+)?|[a-z_]+)(:(.*?))?~/mi', $formula, $merge_tags, PREG_SET_ORDER );
foreach ( $merge_tags as $merge_tag ) {
$updated_merge_tag = str_replace( '~', '', $merge_tag[0] );
$updated_merge_tag = sprintf( '{%s}', $updated_merge_tag );
$formula = str_replace( $merge_tag[0], $updated_merge_tag, $formula );