Sort by: Recently Added Likes

Change Header Logo HREF

@replace {{link}}

// Change the URL to which the header logo links
add_filter( 'generate_logo_href', function( $url ) {
    return '{{link}}';
});

#

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

#

Redirect Solitary Search Results to the Post

// If a search results returns only a single post, then redirect the user to that post
add_action( 'template_redirect', function () {

   if ( is_search() ) {

      global $wp_query;

      if ( $wp_query->post_count == 1 && $wp_query->max_num_pages == 1 ) {

         wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
         exit;

      }

   }

} );

Source

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

#

Remove Welcome Panel

// Remove the welcome panel for new WordPress installs
remove_action( 'welcome_panel', 'wp_welcome_panel' );

#

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;

} );

#

Replace Numbered Months with Named Months in Date Field

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

#

Auto-Link Caption to Same URL As the Image’s Link

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

   });

});

#

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

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

   }

} );

#