Skip to content

Instantly share code, notes, and snippets.

View rafaehlers's full-sized avatar

Rafael Ehlers rafaehlers

View GitHub Profile
@rafaehlers
rafaehlers / gv-now-timestamp.php
Last active April 29, 2020 06:35
Output the timestamp of "now" for use in date comparison with [gvlogic]
<?php
add_filter( 'gform_replace_merge_tags', function ( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
$merge_tag = '{gv_now_timestamp}';
if ( strpos( $text, $merge_tag ) === false ) {
return $text;
}
$local_timestamp = GFCommon::get_local_timestamp( time() );
//$local_date = date_i18n( 'Y-m-d', $local_timestamp, true );
return str_replace( $merge_tag, $local_timestamp, $text );
}, 10, 7 );
@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
<?php
add_filter( 'gform_is_value_match', function( $is_match, $field_value, $target_value, $operation, $source_field, $rule ) {
/**
* Fix this issue for dates temporarily:
* https://github.com/gravityforms/gravityforms/commit/9d37fee852fe9946f030938bfa231e762f687728#commitcomment-23642339
*/
if ( ! $is_match && is_string( $field_value ) && is_string( $target_value ) ) {
switch ( $operation ):
case '>': return $field_value > $target_value;
case '<': return $field_value < $target_value;
@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 / gv-correct-datatables-sort.php
Last active July 25, 2019 20:44
DataTables ignore the Sort option from View Settings. This code fixes it.
<?php //this entire line should be removed when copying this code, before pasting it into your functions.php file
/** Remove default order from DataTables */
add_filter( 'gravityview_datatables_js_options', function( $dt_config, $view_id, $post ) {
$dt_config['order'] = array();
$dt_config['stateSave'] = false;
return $dt_config;
}, 10, 3 );
@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">';
<?php
add_filter( 'gravityview_entries', function( $entries, $criteria, $passed_criteria, &$total ) {
$view_id = GravityView_frontend::getInstance()->get_context_view_id();
if ( $view_id != 97 /** Augmented View ID here */ ) {
return $entries;
}
$_subtract = $criteria;
@rafaehlers
rafaehlers / gv-history-back-link.html
Created April 9, 2018 22:27
Useful to redirect from the Single Entry page to the Multiple Entries page while keeping the search query parameters.