Sort by: Recently Added Likes

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

#

Staging and incremental backups for WordPress.

Auto-Link Twitter Usernames

// Automatically link Twitter usernames (i.e. any text in the form of @username)
add_filter( 'the_content', 'typewheel_link_twitter_username' );   
add_filter( 'the_excerpt', 'typewheel_link_twitter_username' );
add_filter( 'comment_text', 'typewheel_link_twitter_username' );

function typewheel_link_twitter_username( $content ) {
   return preg_replace( '/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', '$1<a href="https://twitter.com/$2" target="_blank" rel="nofollow">@$2</a>', $content );
}
 

Source

Numbered List Rows in Gravity Forms

/* Numbered List Rows in Gravity Forms */
body .gform_wrapper .gform_fields .gfield_list {
    counter-reset: gf-list-counter;
}
body .gform_wrapper .gform_fields .gfield_list .gfield_list_header::before {
    width: 1.5em;
    content: '';
}
body .gform_wrapper .gform_fields .gfield_list .gfield_list_group::before {
    width: 1.5em;
    line-height: 2.25;
    font-weight: bold;
    counter-increment: gf-list-counter;
    content: counter(gf-list-counter);
}

#

Disallow Specific Terms in WordPress Search

@replace @arr $restricted

// Disallow users from searching specific terms on your site
add_filter( 'pre_get_posts', function( $query ) {

   $restricted = array(
      'term-1',
      'term-2'
   );

   if ( $query->is_search && $query->is_main_query() ) {

      $stripped = trim( str_replace( $restricted, '', $query->get('s') ) );

      if ( $stripped == '' )
         $query->set( 'p', -1 );
      else
         $query->set( 's', $stripped );

   }

} );

Source

Order Form List Table By Most Recent

// Order form list table by most recent
add_filter( 'gform_form_list_forms', function( $forms, $search_query, $active, $sort_column, $sort_direction, $trash ) {

    if ( ! rgget( 'orderby' ) ) {

        usort( $forms, function( $a, $b ) {
            return $b->id <=> $a->id;
        } );

    }

	return $forms;

}, 10, 6 );

#