Skip to content

Instantly share code, notes, and snippets.

@zackkatz
zackkatz / gravityimport-prevent-import-based-on-role.php
Last active November 16, 2022 23:49
GravityImport - Prevent users with the role "editor" from importing entries
/**
* Remove the ability of a user to import entries based on their role.
*
* @param array $caps Array of capabilities required to display the UI.
*
* @return array
*/
add_filter( 'gravityview/import/capabilities', function ( $caps ) {
// REPLACE THIS with the role you want to exclude from importing entries.
@zackkatz
zackkatz / disable-paging-search-and-length.php
Last active September 29, 2022 16:16
GravityView DataTables - Remove the page length, pagination menus, and search field
<?php // DO NOT COPY THIS LINE!!!!!
add_filter( 'gravityview_datatables_js_options', 'gv_dt_disable_paging_search_and_length_menus', 10, 3 );
/**
* Remove the page length, pagination menus, and search field from DataTables
* @param array $dt_config DataTables options
* @param int $view_id View ID
* @param WP_Post $post Current WordPress post object
*
@zackkatz
zackkatz / gravityview-reverse-entry-notes.php
Created July 12, 2022 02:04
GravityView - Reverse the order of Entry Notes
<?php
add_filter( 'gravityview/entry_notes/get_notes', function( $notes ) {
if ( ! $notes ) {
return $notes;
}
return array_reverse( $notes, true );
} );
@zackkatz
zackkatz / gravityview-datatables-prevent-state.php
Created May 27, 2022 19:27
GravityView DataTables - Prevent state saving when refreshing
<?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 March 31, 2022 19:22
Adds a shortcode to return the WordPress site's URL
<?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 March 17, 2022 19:54
GravityView - Disable lazy loading for images
<?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 March 15, 2022 16:40
GravityView - Disable the "Show Label" setting by default
<?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 March 10, 2022 01:05
GravityView A-Z: Modify the collation so that filtering works for Polish L and Ł
<?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 January 24, 2022 19:26
GravityView - Add jQuery event handler for `gravityview/tab-ready` event
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 January 13, 2022 21:30
GravityView - Change the default <select> option value
<?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
*/