Skip to content

Instantly share code, notes, and snippets.

@zackkatz
zackkatz / gravityview-datatables-prevent-state.php
Created May 27, 2022
GravityView DataTables - Prevent state saving when refreshing
View gravityview-datatables-prevent-state.php
<?php
add_filter( 'gravityview_datatables_js_options', 'gv_dt_prevent_state_save', 10, 3 );
/**
* Prevent DataTables from saving state between page loads.
* @param array $dt_config DataTables options
* @param int $view_id View ID
* @param WP_Post $post Current WordPress post object
@zackkatz
zackkatz / site_url-shortcode.php
Created Mar 31, 2022
Adds a shortcode to return the WordPress site's URL
View site_url-shortcode.php
<?php
// Shortcode for Site URL - Use [site_url] for Shortcode
add_action( 'init', function() {
add_shortcode( 'site_url', function( $atts = null, $content = null ) {
return site_url();
} );
} );
@zackkatz
zackkatz / gravityview-disable-lazy-loading.php
Created Mar 17, 2022
GravityView - Disable lazy loading for images
View gravityview-disable-lazy-loading.php
<?php
/**
* Disable lazy loading for images in GravityView (added in 2.14.3).
*
* @param string|bool $value The `loading` attribute value. Returning a falsey value will result in
* the attribute being omitted for the image.
* @param string $image The HTML `img` tag to be filtered.
* @param string $context Additional context about how the function was called or where the img tag is.
*/
@zackkatz
zackkatz / gravityview-disable-show-label-by-default.php
Created Mar 15, 2022
GravityView - Disable the "Show Label" setting by default
View gravityview-disable-show-label-by-default.php
<?php
/**
* Disables the "Show Label" setting by default for new Views.
*
* @return array $field_options Original array with `show_label` disabled.
*/
add_filter( 'gravityview_template_field_options', function( $field_options = array() ) {
$field_options['show_label'] = false;
@zackkatz
zackkatz / modify-gravityview-az_filter-collation.php
Created Mar 10, 2022
GravityView A-Z: Modify the collation so that filtering works for Polish L and Ł
View modify-gravityview-az_filter-collation.php
<?php
/**
* Override the default query collation for the letter comparison (Requires GravityView A-Z Filters version 1.3 or newer).
* @param null|string $collation_override The collation override for the query.
* @param string $query The MySQL query passed to the database.
* @return string
*/
add_filter( 'gravityview/az_filter/collation', function ( $collation = null ) {
return 'utf8mb4_bin';
@zackkatz
zackkatz / listen-to-tab-ready.js
Created Jan 24, 2022
GravityView - Add jQuery event handler for `gravityview/tab-ready` event
View listen-to-tab-ready.js
jQuery( 'body' ).on( 'gravityview/tab-ready', function ( ui, panel ) {
// This will print the jQuery DOM element of the newly-activated tab
console.log( panel );
});
@zackkatz
zackkatz / gravityview-change-select-default.php
Created Jan 13, 2022
GravityView - Change the default <select> option value
View gravityview-change-select-default.php
<?php
/**
* Modify the text for the default option in a select (multi or single dropdown)
*
* @param string $default_option Default: `&mdash;` (—)
* @param string $field_type Field type: "select" or "multiselect"
*
* @return string
*/
@zackkatz
zackkatz / gravityview-calendar-specific-feed-start-day-monday.php
Created Dec 14, 2021
GravityView Calendar - Set start day to be Monday for a specific feed
View gravityview-calendar-specific-feed-start-day-monday.php
<?php
/**
* Change the start day to something other than the WordPress settings.
*
* The value must be a number that represents the day of the week.
* Sunday=0, Monday=1, Tuesday=2, etc.
*
* @param array $calendar_options Calendar options
* @param int $form_id Form ID
@zackkatz
zackkatz / gravityview-calendar-start-day-monday.php
Created Dec 14, 2021
GravityView Calendar - Set start day to be Monday
View gravityview-calendar-start-day-monday.php
<?php
/**
* Change the start day to something other than the WordPress settings.
*
* The value must be a number that represents the day of the week.
* Sunday=0, Monday=1, Tuesday=2, etc.
*
* @param array $calendar_options Calendar options
* @param int $form_id Form ID
@zackkatz
zackkatz / gravityview-reset-gravityflow.php
Created Dec 10, 2021
GravityView - Reset all Gravity Flow workflow statuses for a duplicated entry after duplicating
View gravityview-reset-gravityflow.php
<?php
/**
* Reset all Gravity Flow workflow statuses for a duplicated entry after duplicating in GravityView.
*
* @param array $duplicated_entry The duplicated entry
*/
add_action( 'gravityview/duplicate-entry/duplicated', function( $duplicated_entry ) {
if ( ! class_exists( 'Gravity_Flow_API' ) ) {