@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}};
} );
@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}};
} );
@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 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 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 );
@replace @int {{seconds}}
add_filter( 'auth_cookie_expiration', function ( $expiration, $user_id, $remember ) {
if ( $remember )
return {{seconds}};
return $expiration;
}, 10, 3 );
// 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 );
// 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 );
}
@replace {{element_id}}
add_filter( 'generate_header_element_display', function( $display, $element_id ) {
if ( {{element_id}} === $element_id ) {
if ( ! has_post_thumbnail() )
$display = false;
}
return $display;
}, 10, 2 );
/* 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);
}
@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 );
}
} );
// 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 );
// Remove the title link from all posts queried via WP Show Posts
add_filter( 'wpsp_disable_title_link', '__return_true' );
@replace {{img-src}}
// Set a custom image src for the spinner that runs when processing AJAX requests
add_filter( 'gform_ajax_spinner_url', function( $image_src, $form ) {
return '{{img-src}}';
}, 10, 2 );
/* Prevent sub-menu dropdown of the final item in right-aligned navigation from overflowing the viewport */
.dropdown-hover .main-navigation:not(.toggled) ul li:last-child:hover>ul {
right: 0;
}
.dropdown-hover .main-navigation:not(.toggled) ul li:last-child ul li:hover>ul {
left: -100%;
}
@replace font-slug, font[name]:@str, font[variants]:@arr, font[category]:@str
// Add Google Fonts to the typography font options in the customizer
add_filter( 'generate_typography_customize_list', function ( $fonts ) {
$fonts['monoton'] = array(
'name' => 'Monoton',
'variants' => array( '400' ),
'category' => 'cursive'
);
$fonts['fanwood_text'] = array(
'name' => 'Fanwood Text',
'variants' => array( '400', '400i' ),
'category' => 'serif'
);
return $fonts;
} );
// 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>';
}
} );