Skip to content

Instantly share code, notes, and snippets.

View rafaehlers's full-sized avatar

Rafael M. Ehlers rafaehlers

View GitHub Profile
@rafaehlers
rafaehlers / gv-rest-api-nonce.php
Created July 9, 2018 21:07
Code snippet for this: https://docs.gravityview.co/article/468-rest-api (Authentication section)
<?php
$entries_url = 'http://gv2.dev.codeseekah.com/wp-json/gravityview/v1/views/1696/entries.json';
$nonce = wp_create_nonce( 'wp_rest' );
?>
<script type="text/javascript">
jQuery.ajax( {
url: <?php echo json_encode( $entries_url ); ?>,
method: 'GET',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', <?php echo json_encode( $nonce ); ?> );
@rafaehlers
rafaehlers / gw-copy-uid-to-other-field.php
Last active October 13, 2018 08:18
Copy the Unique ID to another field
<?php
/**
* Gravity Perks // GP Unique ID // Copy ID to Another Field
* http://gravitywiz.com
*/
// change the "999" to your form ID
add_filter( 'gform_entry_post_save_999', function( $entry ) {
// update "1" to your Unique ID field's field ID
$uid_field_id = 1;
@rafaehlers
rafaehlers / gv-rename-approved-entry-note-text.php
Last active June 29, 2019 00:01
Filter to rename the "Approved the Entry" message in an Entry note.
<?php // Make sure to remove this line before pasting it on your theme's functions.php
add_filter( 'gravityview/entry_notes/get_notes', 'gv_modify_notes', 10, 2 );
function gv_modify_notes( $notes, $entry_id ) {
foreach($notes as $key => $note){
if (strpos( $note->value, 'Approved') !== false){
$note->value = "Aprovada!";
}
if (strpos( $note->value, 'Unapproved') !== false){
$note->value = "Não Aprovada!";
@rafaehlers
rafaehlers / gv-dt-change-message.php
Created July 30, 2018 22:45
Change DataTables Ajax Messages
<?php
function gravityview_datatables_change_messages( $dt_config, $view_id, $post ) {
$dt_config['language']['processing'] = 'Wait!';
//$dt_config['language']['emptyTable'] = 'No entries here!';
return $dt_config;
}
add_filter( 'gravityview_datatables_js_options', 'gravityview_datatables_change_messages', 10, 3 );
@rafaehlers
rafaehlers / gv-datables-excel-export.php
Created August 17, 2018 05:25
Filter to change the filename of the exported .XLSX file and to remove the first row containing the document title
<?php // MAKE SURE TO REMOVE THIS FIRST LINE BEFORE COPYING THIS CODE TO YOUR FUNCTIONS.PHP FILE
add_filter('gravityview/datatables/button_excel','gravityview_excel_export_settings', 10 ,2);
function gravityview_excel_export_settings( $button_config = array(), $view_id){
$button_config['filename'] = 'dt-excel-test'; //you can change the filename here (don't type the extension)
$button_config['title'] = '';
return $button_config;
}
<?php //do not copy this line to your functions.php file!
add_filter( 'gpls_rule_groups', function( $rule_groups, $form_id ) {
// Update "123" to the ID of your form.
$primary_form_id = 123;
if( $form_id == $primary_form_id ) {
return $rule_groups;
}
if(( $form_id == 4 ) || ( $form_id == 5 ) || ( $form_id == 6 ) || ( $form_id == 7 )) {
return $rule_groups;
@rafaehlers
rafaehlers / label-as-placeholder.html
Created October 30, 2018 04:55
Turn Search Bar labels into placeholders
<script type="text/javascript">
(function($){
$(document).ready(function(){
$("form.gv-widget-search :input").each(function(index, elem) {
var eId = $(elem).attr("id");
var label = null;
if (eId && (label = $(elem).parents("form").find("label[for="+eId+"]")).length == 1) {
$(elem).attr("placeholder", $(label).html());
$(label).remove();
@rafaehlers
rafaehlers / table-view-vertical.css
Created November 5, 2018 20:36
Change a Table view from horizontal to vertical
.gv-table-view thead {
display: none;
}
.gv-table-view tr {
display: block;
position: relative;
padding: 1.2em 0;
overflow-x: auto;
}
@rafaehlers
rafaehlers / gv-remove-approval-notes.php
Last active February 3, 2020 20:32
Use this code to prevent approval notes from showing up on your View
<?php // REMOVE THIS LINE BEFORE COPYING THIS CODE TO YOUR FUNCTIONS.PHP FILE
add_filter( 'gravityview/entry_notes/get_notes', 'gv_remove_entry_approval_notes', 10, 2 );
function gv_remove_entry_approval_notes( $notes, $entry_id ) {
foreach($notes as $key => $note){
if (strpos( $note->value, 'pproved') !== false){
unset( $notes[ $key] );
}
if (strpos( $note->value, 'WordPress') !== false){
unset( $notes[ $key] );
@rafaehlers
rafaehlers / gv_exact_match_fields.php
Last active December 19, 2018 00:43
Returns an exact match for two fields in a specific form
<?php // MAKE SURE TO REMOVE THIS FIRST LINE WHEN COPYING THIS to your THEME'S FUNCTIONS.PHP FILE
add_filter( 'gravityview_fe_search_criteria', 'gv_exact_match_fields', 10, 2 );
/**
* @param array $search_criteria
* @param int $form_id
*
* @return array Modified search, if it's the current form
*/
function gv_exact_match_fields( $search_criteria = array(), $form_id = 0 ) {