Sort by: Recently Added Likes

Send Footer to Bottom of Viewport on Short Posts

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

#

Prevent Submission When Pressing Enter

<?php // Disables form submission when pressing Enter, unless user has tabbed to a form button.
add_action( 'gform_pre_render', function ( $form ) { ?>

   <script type="text/javascript">
      jQuery(document).bind('gform_post_render', function() {
         jQuery(document).on( 'keypress', '.gform_wrapper', function (e) {
            var code = e.keyCode || e.which;
            if ( code == 13 && ! jQuery( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) ) {
               e.preventDefault();
               return false;
            }
         });
      });
   </script>

   <?php return $form;

} );

#

Route Notifications Via Username & Email

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()

#

Redirect After Login

@replace {{link}}

// Redirect a user after successful login
add_filter( 'login_redirect', function () {
  return '{{link}}';
} );

#

Add CPT(s) to Main Blog Feed

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

} );

Source

Capture Post Content in a Gravity Form Field

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>

Source

Staging and incremental backups for WordPress.

Customize Recovery Mode Email Recipient

@replace {{email}}

// Customize the email address to which recovery mode email is sent when site encounters a fatal error
add_filter( 'recovery_mode_email', function( $email ) {

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

    return $email;

} );

#

Customizing Your 404 Page Not Found

@replace {{title}}, {{text}}

// Set a custom title for the 404 page
add_filter( 'generate_404_title', function ( $title ) {
   return '{{title}}';
} );

// Set custom text for the 404 page
add_filter( 'generate_404_text', function ( $text ) {
   return '{{text}}';
} );

// Hide the search form from content area on the 404 page
add_filter( 'get_search_form', function ( $form ) {

   if ( is_404() && did_action( 'generate_after_entry_header' ) && ! did_action( 'generate_after_content' ) )
      return '';

   return $form;

} );

#

Show Field(s) Across Multiple Pages of Gravity Form

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

} );

Source

Set Default Customizer Color Palette

@replace @arr

// Set 8 colors that will be used to fill the color picker palette in the Customizer
add_filter( 'generate_default_color_palettes', function ( $palettes ) {
   return array(
      '#040404',
      '#5b5549',
      '#9b5c4d',
      '#d3ac58',
      '#296a7f',
      '#272727',
      '#adada8',
      '#f5f5f5',
   );
} );

Source

Dynamically Populate ACF Select Field With Existing Gravity Forms

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;

   } );

}

#

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

   }

} );

#

The smarter way to manage your WordPress sites.