Skip to content

Instantly share code, notes, and snippets.

View rafaehlers's full-sized avatar

Rafael Ehlers rafaehlers

View GitHub Profile
@rafaehlers
rafaehlers / gv-entry-updated-return-to-entry.php
Created November 23, 2016 17:01
How To Change The 'Entry Updated. Return to Entry' Message
add_filter( 'gravityview/edit_entry/success', 'gv_edit_entry_success', 10, 4 );
function gv_edit_entry_success( $entry_updated_message , $view_id, $entry, $back_link ) {
$message = 'Product Updated. <a href="'.$back_link .'">Return to product's details page.</a>';
return $message;
}
@rafaehlers
rafaehlers / gv_modify_notes_email_content.php
Created January 16, 2017 15:16
Modify the body content of a note
add_filter( 'gravityview/field/notes/email_content', 'gv_modify_notes_email_content', 10, 4 );
function gv_modify_notes_email_content( $email_settings ) {
extract( $email_settings );
$email_settings['message'] = '<h2>'.$message.'</h2>';
return $email_settings;
}
@rafaehlers
rafaehlers / gv_modify_notes_email_content.php
Last active March 29, 2018 19:41
Modify an entry note email
<?php
add_filter( 'gravityview/field/notes/email_content', 'gv_modify_notes_email_content', 10, 4 );
function gv_modify_notes_email_content( $email_settings ) {
extract( $email_settings );
$email_settings['from'] = $from; //example@gmail.com
$email_settings['to'] = $to; //example@gmail.com
$email_settings['bcc'] $bcc; //example@gmail.com
$email_settings['reply_to'] = $reply_to; //example@gmail.com
$email_settings['subject'] = $subject; //subject of the email
$email_settings['message'] = $message; //body of the email (already in HTML format)
@rafaehlers
rafaehlers / gv_change_map_it.php
Created March 3, 2017 17:30
GravityView Maps code to change the 'Map It' text using the gravityview_map_link filter
add_filter( 'gravityview_map_link', 'gv_change_map_it', 10, 5 );
function gv_change_map_it( $link, $address, $url ){
$link = str_replace('Map It','View on Google Maps',$link);
return $link;
}
@rafaehlers
rafaehlers / gv_age.php
Last active May 21, 2018 20:06
Calculate a person's age based on a date field
<?php
add_shortcode( 'gv_age', 'gv_calculate_age' );
/**
* Calculate age in years based on entry data
*
* Usage inside a Custom Content field (Replace "2" with the ID of the date field):
*
* <code>
@rafaehlers
rafaehlers / gv_calculate_days.php
Last active November 14, 2017 18:04
Calculate days between two date fields
<?php
add_shortcode( 'gv_days', 'gv_calculate_days' );
function gv_calculate_days( $atts ) {
global $gravityview_view;
extract($gravityview_view->field_data); // create a $entry variable with current entry data array
extract( shortcode_atts(
array(
'start_date_id' => '',
'end_date_id' => '',
@rafaehlers
rafaehlers / gv_wordstrip.php
Created July 10, 2017 22:38
Strip the first word only of a string
add_shortcode( 'gv_wordstrip', 'gv_wordstrip' );
function gv_wordstrip( $atts ) {
global $gravityview_view;
extract($gravityview_view->field_data); // create a $entry variable with current entry data array
extract( shortcode_atts(
array(
'field_id' => '',
), $atts )
);
@rafaehlers
rafaehlers / gv-redirect-after-update-entry.php
Created July 17, 2017 20:20
Redirect users to a new URL after updating the entry.
<?php
add_action( 'gravityview/edit_entry/after_update', 'gravityview_redirect_after_update', 10, 2 );
function gravityview_redirect_after_update( $form, $entry_id ) {
// Get the current View ID
$view_id = GravityView_View::getInstance()->getViewId();
// Replace the 105 below to your specific View ID, otherwise, without this check all your Views will be affected
if($view_id == 105){?>
<script>
jQuery(document).ready( function() {
window.location.replace( "http://your-new-URL-here/" );
@rafaehlers
rafaehlers / maps-coordinates.php
Created August 11, 2017 16:13
Use the cordinates (Latitude and Longitude) instead of the address to position the markers over the Maps
<?php
/**
* Use the cordinates (Latitude and Longitude) instead of the address to position the markers over the Maps
* Replace 'MY_LATITUDE_FIELD_ID' and 'MY_LONGITUDE_FIELD_ID' by the form field ids containing the latitude and longitude
* @param array $fields Gravity Forms fields IDs containing the latitude and longitude
* @param GravityView_View object $view Current View object
*/
function my_gv_maps_lat_long_fields( $fields, $view ) {
return array( 'MY_LATITUDE_FIELD_ID', 'MY_LONGITUDE_FIELD_ID' );
}
@rafaehlers
rafaehlers / redirect-many-views.php
Created August 15, 2017 14:03
Redirect to diferent Views after entry update
<?php
add_action( 'gravityview/edit_entry/after_update', 'gravityview_redirect_after_update', 10, 2 );
function gravityview_redirect_after_update( $form, $entry_id ) {
// Get the current View ID
$view_id = GravityView_View::getInstance()->getViewId();
if ( $view_id == 105 ) {?>
<script>
jQuery(document).ready( function() {
window.location.replace( "http://localhost/gravity/" );
});