@replace @int {{seconds}}
add_filter( 'auth_cookie_expiration', function ( $expiration, $user_id, $remember ) {
if ( $remember )
return {{seconds}};
return $expiration;
}, 10, 3 );
@replace @int {{seconds}}
add_filter( 'auth_cookie_expiration', function ( $expiration, $user_id, $remember ) {
if ( $remember )
return {{seconds}};
return $expiration;
}, 10, 3 );
@replace @int {{position}}
{{position}} = 4 (before Posts)
{{position}} = 50 (after Comments)
// Set position for the Gravity Forms admin menu item
add_filter( 'gform_menu_position', function( $position ) {
return {{position}};
} );
@requires @plugin Members
// Sync roles across multisite network by hooking to Members plugin (https://wordpress.org/plugins/members/)
add_action( 'members_role_updated', function() {
if ( function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) {
$roles = get_option( 'wp_user_roles' );
$sites = get_sites( array( 'fields' => 'ids' ) );
foreach ( $sites as $site_id ) {
update_blog_option( $site_id, 'wp_' . $site_id . '_user_roles', $roles );
}
}
} );
Add gravityforms
as field’s Wrapper Attributes class.
// Dynamically populate the options of an ACF select field with Gravity Forms existing on the site
if ( class_exists( 'GFForms' ) ) {
add_filter( 'acf/load_field/type=select', function( $field ) {
if ( 'gravityforms' == $field['wrapper']['class'] ) {
$gf['forms']['active'] = GFAPI::get_forms();
$gf['forms']['inactive'] = GFAPI::get_forms( false );
$gf['forms']['all'] = array_merge( $gf['forms']['active'], $gf['forms']['inactive'] );
foreach ( $gf['forms']['all'] as $form ) {
$field['choices'][ $form['id'] ] = $form['title'];
}
}
return $field;
} );
}
Add link-the-caption
as Additional CSS Class on image block. Caption should contain no other links.
// Auto-link image caption to the same URL as that to which the image has been linked
jQuery(document).ready(function( $ ) {
$('.link-the-caption').each( function() {
let image_link = $(this).attr('href');
let image_caption = $(this).next().html();
$(this).next().html('<a href="'+image_link+'">'+image_caption+'</a>');
});
});
<?php // Replace the numbered months with named months in a Gravity Forms dropdown date field
add_action( 'wp_footer', function () { ?>
<script type="text/javascript">
jQuery(document).ready(function( $ ) {
$('.gfield_date_dropdown_month select option').each( function(i, option) {
switch( option.value ) {
case '1': option.innerHTML = 'January'; break;
case '2': option.innerHTML = 'February'; break;
case '3': option.innerHTML = 'March'; break;
case '4': option.innerHTML = 'April'; break;
case '5': option.innerHTML = 'May'; break;
case '6': option.innerHTML = 'June'; break;
case '7': option.innerHTML = 'July'; break;
case '8': option.innerHTML = 'August'; break;
case '9': option.innerHTML = 'September'; break;
case '10': option.innerHTML = 'October'; break;
case '11': option.innerHTML = 'November'; break;
case '12': option.innerHTML = 'December'; break;
}
});
});
</script>
<?php } );
@replace {{_formID}}
<?php // Prepends or appends fields (marked by class `prepend-to-pages` or `append-to-pages` respectively) to every page of a Gravity Form
add_action( 'gform_pre_render{{_formID}}', function( $form ) {
add_action( 'wp_footer', function () { ?>
<script type="text/javascript">
jQuery(document).bind('gform_post_render', function(event, form_id, current_page) {
jQuery(jQuery('.gfield.prepend-to-pages').get().reverse()).each(function() {
jQuery(this).prependTo(`#gform_page_${form_id}_${current_page} .gform_fields`);
});
jQuery(jQuery('.gfield.append-to-pages').get().reverse()).each(function() {
jQuery(this).appendTo(`#gform_page_${form_id}_${current_page} .gform_fields`);
});
} );
</script>
<?php } );
return $form;
} );
// Remove the image link from all posts queried via WP Show Posts
add_filter( 'wpsp_disable_image_link', '__return_true' );
// Remove the title link from all posts queried via WP Show Posts
add_filter( 'wpsp_disable_title_link', '__return_true' );
Optionally @replace .entry-content
, <!-- START CONTRACT -->
, <!-- END CONTRACT -->
// Send all HTML content between contentStart and contentEnd comments into Gravity Form paragraph text field with class of `content_receiver`
<script>
jQuery(document).ready(function(){
const contentStart = '<!-- START CONTRACT -->';
const contentEnd = '<!-- END CONTRACT -->';
const contentFull = jQuery('.entry-content').html();
const contentSent = contentFull.substr(0,contentFull.indexOf(contentEnd)).substr(contentFull.indexOf(contentStart)).replace(contentStart,'');
jQuery('.content_receiver textarea').val(contentSent.replace(/\n/gm,' '));
});
</script>
/**
* Create a globally accessible counter for all queries
* Even custom new WP_Query!
*/
// Initialize your variables
add_action( 'init', function () {
global $cqc;
$cqc = -1;
} );
// At loop start, always make sure the counter is -1
// This is because WP_Query calls "next_post" for each post,
// even for the first one, which increments by 1
// (meaning the first post is going to be 0 as expected)
add_action( 'loop_start', function ( $q ) {
global $cqc;
$cqc = -1;
}, 100, 1 );
// At each iteration of a loop, this hook is called
// We store the current instance's counter in our global variable
add_action( 'the_post', function ( $p, $q ) {
global $cqc;
$cqc = $q->current_post;
}, 100, 2 );
// At each end of the query, we clean up by setting the counter to
// the global query's counter. This allows the custom $cqc variable
// to be set correctly in the main page, post or query, even after
// having executed a custom WP_Query.
add_action( 'loop_end', function ( $q ) {
global $wp_query, $cqc;
$cqc = $wp_query->current_post;
}, 100, 1 );
Format your email field(s) in notifications as {usernames:user1:user2}{emails:account@example.com}
or {usernames:user1:user2:user3}
or as usual.
// Allow Gravity Form notification email fields to use usernames and email
// Format your email fields in notifications as {usernames:user1:user2:user3} or {usernames:user1:user2}{emails:account@example.com}
add_filter( 'gform_notification', function ( $notification, $form, $entry ) {
// run all email fields in the notification through route translation
if ( $notification['toType'] == 'email' ) {
$notification['to'] = typewheel_gform_notification_translate_routes( $notification['to'] );
} else if ( $notification['toType'] == 'routing' ) {
foreach ( $notification['routing'] as $key => $route )
$notification['routing'][ $key ]['email'] = typewheel_gform_notification_translate_routes( $notification['routing'][ $key ]['email'] );
}
$notification['from'] = typewheel_gform_notification_translate_routes( $notification['from'] );
$notification['replyTo'] = typewheel_gform_notification_translate_routes( $notification['replyTo'] );
$notification['bcc'] = typewheel_gform_notification_translate_routes( $notification['bcc'] );
return $notification;
}, 10, 3 );
// reusable function for translating routes
function typewheel_gform_notification_translate_routes( $routes ) {
if ( strpos( $routes, '{usernames' ) !== false || strpos( $routes, '{emails' ) !== false ) {
// parse the username and email batches
$routes = str_replace( array( '} {', '},{' ), '}{', $routes );
$batches = explode( '}{', substr( $routes, 1, -1 ) );
foreach ( $batches as $key => $batch ) {
if ( strpos( $batch, 'usernames' ) !== false )
$usernames = explode( ':', $batch );
if ( strpos( $batch, 'emails' ) !== false )
$emails = explode( ':', $batch );
}
$to = array(); // initialize the to array
// loop through users and grab the email
if ( isset( $usernames ) ) {
unset( $usernames[0] );
foreach ( $usernames as $username ) {
$user = get_user_by( 'login', $username );
if ( $user !== false ) $to[] = $user->user_email;
}
}
// loop through the email addresses
if ( isset( $emails ) ) {
unset( $emails[0] );
foreach ( $emails as $email ) $to[] = $email;
}
// add all addresses to the notification
$routes = implode( ',', $to );
}
return $routes;
} // end typewheel_gform_notification_translate_routes()
@replace {{cpt-slug}}
add_action( 'pre_get_posts', function ( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', '{{cpt-slug}}' ) );
return $query;
} );
@replace {{footer-height}}
/* If a page's height is shorter than the viewport, this ensures the footer does not creep beyond the bottom of the viewport */
body {
position: relative;
min-height: 100vh;
padding-bottom: {{footer-height}};
}
.site-footer {
position: absolute;
width: 100%;
bottom: 0;
}
add_filter( 'generate_show_excerpt', function ( $show_excerpt ) {
if ( is_search() )
return false;
return $show_excerpt;
} );
@replace @int {{days}}
// Overrides the number of days until incomplete submissions (from Save & Continue) are purged
add_filter( 'gform_incomplete_submissions_expiration_days', function ( $expiration_days ) {
return {{days}};
} );