Sort by: Recently Added Likes

Move Navigation Below Page Header

// Renders the navigation below the page header instead of before
add_action( 'after_setup_theme', function () {

   remove_action( 'generate_after_header', 'generate_add_navigation_after_header', 5 );
   add_action( 'generate_after_header', 'generate_add_navigation_after_header', 15 );

} );

Source

Custom Merge Tags

<?php // Introduce additional merge tags for use throughout Gravity Forms
add_filter( 'gform_replace_merge_tags', function ( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {

   $custom_merge_tags = array(
      '{date_ymd}'  => date( 'Y.m-M.d', strtotime( $entry['date_created'] ) ),
      '{timestamp}' => time(),
      '{site_url}'  => get_site_url(),
      '{site_name}' => get_bloginfo( 'name' )
   );
    
   return str_replace( array_keys( $custom_merge_tags ), array_values( $custom_merge_tags ), $text);

}, 10, 7 );

// Add our custom merge tags to the dropdown
add_action( 'admin_print_scripts', function () {

   if ( method_exists( 'GFForms', 'is_gravity_page' ) && GFForms::is_gravity_page() ) { ?>

      <script type="text/javascript">
         gform.addFilter('gform_merge_tags', function (mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option) {
             mergeTags["custom"].tags.push({ tag: '{date_ymd}', label: 'Entry Date (Y.m-M.d)' });
             mergeTags["custom"].tags.push({ tag: '{timestamp}', label: 'Current Time (UNIX Timestamp)' });
             mergeTags["custom"].tags.push({ tag: '{site_url}', label: 'Site URL' });
             mergeTags["custom"].tags.push({ tag: '{site_name}', label: 'Site Name' });
             return mergeTags;
          } );
      </script>

   <?php }

 } );

#

Remove Comment Form URL Field

// Remove the URL field from the WordPress comment form
add_filter( 'comment_form_default_fields', function ( $fields ) {

   unset( $fields['url'] );

   return $fields;

} );

Source

Notification Interception

@replace {{_formID}}, {{email}}

// Sends all Gravity Form notifications to the specified email address
add_filter( 'gform_notification{{_formID}}', function ( $notification, $form, $entry ) {

   $notification['toType'] = 'email';
   $notification['to'] = '{{email}}';

   return $notification;

}, 10, 3 );

#

Sync Roles Across Multisite Network

@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 :filename Modifier to Single File Upload Field

// adds :filename modifier to the single file upload field
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value, $format ) {

   if ( $merge_tag != 'all_fields' && $field->type == 'fileupload' && $modifier == 'filename' ) {

      $value    = str_replace( ' ', '%20', $raw_value );
      $pathinfo = pathinfo( $value );
      $value    = rgar( $pathinfo, 'basename' );

   }

   return $value;

}, 10, 6 );

#

Reposition Gravity Forms Menu Item

@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}};
} );

Source

Limit Countries

@replace {{_formID}}

// Filter the countries that are selectable in an address field
add_filter( 'gform_pre_render{{_formID}}', 'typewheel_limit_countries' );
add_filter( 'gform_pre_validation{{_formID}}', 'typewheel_limit_countries' );
add_filter( 'gform_pre_submission_filter{{_formID}}', 'typewheel_limit_countries' );
add_filter( 'gform_admin_pre_render{{_formID}}', 'typewheel_limit_countries' );

function typewheel_limit_countries( $form ) {

  add_filter( 'gform_countries', function( $countries ) {
    return array( 'Brazil', 'United States', 'Netherlands', 'United Kingdom' );
  });

  return $form;

}

#

Better Style for Gravity Forms Survey Rating Field

/* Better Survey Rating Styles */
 :root {
    --gsurvey-star-size: 48px;
    --gsurvey-star-color: #3b7ca8;
 }
 body .gform_wrapper.gravity-theme .gsurvey-rating > label {
    margin-right: .25em;
 }
 body .gform_wrapper.gravity-theme .gsurvey-rating > label::before {
    display: inline-block;
    background-color: #ececec;
    border-radius: 50%;
    padding: .25em;
 }
 body .gform_wrapper.gravity-theme .gsurvey-rating > label:hover::before {
    color: var(--gsurvey-star-color);
    box-shadow: inset 0px 0px 0px 3px var(--gsurvey-star-color);
 }
 body .gform_wrapper.gravity-theme .gsurvey-rating:not(:checked) > label {
    width: calc( var(--gsurvey-star-size) + .5em + 3px );
    font-size: var(--gsurvey-star-size) !important;
    line-height: var(--gsurvey-star-size);
    background-image: none;
    background-size: var(--gsurvey-star-size) var(--gsurvey-star-size);
 }
 body .gform_wrapper.gravity-theme .gsurvey-rating:not(:checked) > label::before {
    content: '☆';
 }
 body .gform_wrapper.gravity-theme .gsurvey-rating > input:checked ~ label {
    background-image: none;
    background-size: var(--gsurvey-star-size) var(--gsurvey-star-size);
 }
 body .gform_wrapper.gravity-theme .gsurvey-rating > input:checked ~ label::before {
    content: '★';
    color: var(--gsurvey-star-color);
 }
 body .gform_wrapper.gravity-theme .gsurvey-rating:not(:checked) > label:hover,
 body .gform_wrapper.gravity-theme .gsurvey-rating:not(:checked) > label:hover ~ label {
    background-image: none;
    background-size: var(--gsurvey-star-size) var(--gsurvey-star-size);
 }

#

Create Globally Accessible Counter in Queries

/**
 * 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 );

Source

Add Account Handle Input Mask

// Provide an Account Handle input mask to receive Twitter and Instagram account handles
add_filter( 'gform_input_masks', function( $masks ) {

  $masks['Account Handle'] = '@*?**************************';
    return $masks;
  } );

add_filter( 'gform_input_mask_script', function( $script, $form_id, $field_id, $mask ) {

  if ( $mask == '@*?**************************' ) {
     $script = "jQuery.mask.definitions['*'] = '[A-Z,a-z,0-9,_]';   jQuery('#input_{$form_id}_{$field_id}').mask('" . esc_js( $mask ) . "',{placeholder:' '}).on('keypress', function(e){if(e.which == 13){jQuery(this).blur();}});";
  }

  return $script;

}, 10, 4 );

#