Sort by: Recently Added Likes

Set parent for post created with APC to embed post

@replace {{form_id}}

// Set parent for post created with APC to post on which form is embedded
add_action( 'gform_advancedpostcreation_post_after_creation_{{form_id}}',

    function( $post_id, $feed, $entry, $form ) {

        wp_update_post( array(
            'ID' => $post_id,
            'post_parent' => GFCommon::replace_variables( '{embed_post:ID}', $form, $entry )
        ) );

    },

10, 4 );

#

Remove inactive forms from form switcher

// Remove inactive forms from form switcher
add_filter( 'gform_form_switcher_forms', function( $forms ) {

    $forms = array_filter( $forms, function( $form ) {
        return rgobj( $form, 'is_active' );
    } );

    return $forms;

} );

#

Increase width of form editor sidebar

// Increase width of form editor sidebar
add_action( 'admin_print_styles', function() {

    if ( class_exists( 'GFCommon' ) && GFCommon::is_form_editor() ) {

        echo '<style>
                .gforms_edit_form .form_editor_fields_container { max-width: calc( 100% - 744px ); }
                .gforms_edit_form .form_editor_fields_container.droppable { padding-right: 712px; }
                .gforms_edit_form .editor-sidebar .sidebar,
                .gforms_edit_form .editor-sidebar .sidebar .sidebar__nav { width: 520px; }
                .gforms_edit_form .editor-sidebar .sidebar .add-buttons li { width: 25%; }
              </style>';

    }

} );

#

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

#

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

#

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

#

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

#

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

#

Everyone has their thing. Ours is domain names.

Perform Function On Any Site of Multisite Network

/**
 *  Perform any function on any site on the network
 *
 *  @param    integer         $site_id   site on which to perform the function
 *  @param    string|array    $action    function name to perform
 *  @param    array           $args      parameters passed as an indexed array
 *  @return
 */
function do_network_request( $site_id, $action, $args = array() ) {

   switch_to_blog( $site_id );

      if ( ( is_string( $action ) && function_exists( $action ) ) || ( is_array( $action ) && method_exists( ...$action ) ) )
         $result = call_user_func( $action, ...$args );
      else
         $result = NULL;

   restore_current_blog();

   return $result;

} // end do_network_request

#

Fix Center Alignment of Main Nav Menu Items With Children

@replace {{gp-layout-setting-menu-item-width}}

/* Fixes center alignment of main nav menu items that show children in a dropdown */
.main-navigation.mobile-header-navigation ul li.menu-item-has-children a {
   padding-right: {{gp-layout-setting-menu-item-width}};
}
.main-navigation.mobile-header-navigation ul li.menu-item-has-children span.dropdown-menu-toggle {
   position: absolute;
   right: 0;
}

#

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

A WordPress plugin for website & design feedback.