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_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_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 / my_gv_wpseo_opengraph_image.php
Last active August 30, 2017 19:57
Specify an entry image or a default image to the og:image Open Graph tag.
<?php
add_action( 'wpseo_opengraph', 'my_gv_wpseo_opengraph_image', 10, 1);
function my_gv_wpseo_opengraph_image( $img ) {
if( ! function_exists('gravityview_is_single_entry') || ! function_exists( 'gravityview_get_entry') ) {
return $img;
}
// get single entry id
$entry_id = gravityview_is_single_entry();
if( empty( $entry_id ) ) {
return $img;
@rafaehlers
rafaehlers / modify-review-form.php
Last active October 5, 2017 23:31
Filter to modify the review form
<?php
/** The defaults below are just for reference to use with the filter:
$defaults = array(
'fields' => $fields,
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Review', 'noun', 'gravityview-ratings-reviews' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
// This filter is documented in wp-includes/link-template.php
'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.', 'gravityview-ratings-reviews' ), wp_login_url( $permalink ) ) . '</p>',
// This filter is documented in wp-includes/link-template.php
'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', 'gravityview-ratings-reviews' ), get_edit_user_link(), $user_identity, wp_logout_url( $permalink ) ) . '</p>',
'comment_notes_befo
@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_tag_shortcode.php
Created December 15, 2017 19:14
Custom Shortcode to split tag fields into links to use as a search parameter for a View in another page
<?php
add_shortcode( 'gv_tag', 'gv_tag_shortcode' );
function gv_tag_shortcode( $atts ) {
extract( shortcode_atts(
array(
'field' => '',
), $atts )
);
$links = "";
@rafaehlers
rafaehlers / gv-maxwords2-modifier.php
Created February 13, 2018 18:06
:maxwords2 used to have manual control over the maxwords modifier
<?php
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value ) {
if( 'all_fields' !== $merge_tag && 'maxwords2' === $modifier ) {
/* Number of words to display */
$max = 4;
$more_placeholder = '&hellip;';
/**
@rafaehlers
rafaehlers / gvgravatar.php
Created March 19, 2018 22:53
Custom shortcode to display the user's Gravatar on the View based on an email field.
<?php // remove this whole line when copying this code to your theme's function.php file
add_shortcode( 'gvgravatar', 'gv_gravatar_shortcode' );
function gv_gravatar_shortcode( $atts ) {
extract( shortcode_atts(
array(
'email' => '',
), $atts )
);
$md5 = md5($email);
$image = '<img src="https://secure.gravatar.com/avatar/'.$md5.'?s=55">';