Skip to content

Instantly share code, notes, and snippets.

@dougkeeling
dougkeeling / functions.php
Created November 20, 2023 17:13
[Set default "To", "From", "From Name" for Gravity Forms notifications] #wordpress #php #gravityforms #ACF
// Set the default notification email address for new forms
// ------------------------------------------------------------------------------
add_action( 'gform_after_save_form', 'rkt_set_default_notification_to', 10, 2 );
function rkt_set_default_notification_to( $form, $is_new ) {
// Using an ACF options field to allow the user to set this.
$admin_email = get_field( 'default_admin_email', 'option' );
@dougkeeling
dougkeeling / markup.html
Last active September 20, 2023 16:06
[HTML Sample Markup] For use testing page layouts. Paragraph tags are added by Wordpress if pasted into the WYSIWYG editor. Otherwise, they would need to be added manually. #html
<h1>This is the H1 Heading</h1>
Above this paragraph should be the H1 heading for your web page. If it is not visible, the design settings for the H1 tag is set to <code>display:none</code> which many WordPress Themes use to hide the blog title text and replace it with a graphic. Do not use H1 within your blog post area.
If the design in the H1 heading looks like your blog title or blog post title, then that is the style set for that HTML tag and you should not use it within your blog post area.
Inside of this test data section are most of the basic HTML and XHTML and CSS styles that you might use within your WordPress Theme. You need to know what that will look like as part of structuring your styles.
<h2>This is the H2 Heading</h2>
Above this paragraph should be the H2 heading for your web page. WordPress Themes use the h2 heading for various purposes. Logically, it should be either the post title or the first heading in the post content.
However, it is used all over WordPress Themes including the subtit
@dougkeeling
dougkeeling / scripts.js
Created May 9, 2023 13:08
[Copy Shipping/Billing Address] Copy addresses from billing to shipping in Gravity Forms #php #wordpress #javascript #gravityforms
// Then all you need to do is create a checkbox with the CSS class "fill-check," give the fields you want to fill from the class "fill-from," and give the fields you want to fill into the class "to-fill" (classes can be added under the "appearance" tab on forms). As long as the labels for the fields are the same, it should work.
//bind the click function
$(document).on('click', '.fill-check input', function() {
if($(this).is(':checked')) {
//put in the selectors we fill from
var fill_from = $('.fill-from, .fill-from .name_last, .fill-from .name_first, .fill-from .address_line_1, .fill-from .address_line_2, .fill-from .address_city, .fill-from .address_state, .fill-from .address_zip, .fill-from .address_country');
fill_from.each(function() {
@dougkeeling
dougkeeling / scripts.js
Created April 3, 2023 19:32
[ACF Video/Image Field] Displays background video or image. May have play buttons or not. Based on Vimeo's system. Relies on several functions for getting random strings and also the responsive image. #wordpress #acf #php #javascript #scss #css
let vimeoPlayers = {};
function initVideoPlayers(){
// console.log('initVideoPlayers called');
jQuery(function($) {
vimeoPlayers = {};
@dougkeeling
dougkeeling / functions.php
Created January 10, 2023 18:19
[Get markup for a responsive image] In Wordpress, pass an image (attachment) ID to this function to return responsive image markup. If you use Lazysizes, you can return appropriate markup (data-src, data-srcset). #wordpress #PHP #ACF
// Get a responsive image based on an attachment ID
// ------------------------------------------------------------------------------
function rkt_get_responsive_image($image_id, $image_size = 'large', $lazyload = false, $echo = true) {
if ( $image_id ) :
$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
$image_args = array(
@dougkeeling
dougkeeling / ajax.php
Created May 7, 2022 18:12
[AJAX Load Posts w/Pagination] Get posts via AJAX with custom pagination. Requires jQuery. #wordpress #ajax #php #javascript
<?php
add_action( 'wp_ajax_kdm-pagination-load-posts', 'kdm_pagination_load_posts' );
add_action( 'wp_ajax_nopriv_kdm-pagination-load-posts', 'kdm_pagination_load_posts' );
function kdm_pagination_load_posts() {
global $wpdb;
// Set default variables
$msg = '';
@dougkeeling
dougkeeling / import.txt
Created December 22, 2021 18:51
[mySQL Import SQL file via Terminal]
If you are using MAMP for your local WordPress or PHP development on a Mac, you likely need to import huge MySQL database dump files (more then 32Mb) in your local environment.
You could increase the size of maximum uploads in your php.ini file, however if the dump is really big (over 100Mb), the operation can take ages to complete.
It is more covenient to do this using the command line, expecially since it’s just a one liner.
mysql -u {DB_USER_NAME} -p {DB_NAME} < {PATH/TO/MYSQL/DUMP/FILE.SQL}
Keep in mind that the default user for MySQL as set by MAMP is root with a password of root, and that you need the full path to MAMP binaries to run the mysql command on a default installation. The command becomes:
@dougkeeling
dougkeeling / mixins.scss
Created August 31, 2021 17:31
[Define an aspect ratio for a <div>] Set the width and height and the aspect ratio will be determined automatically. #scss #css
@mixin aspect-ratio($width, $height) {
position: relative;
&:before {
display: block;
content: "";
width: 100%;
padding-top: ($height / $width) * 100%;
}
}
@dougkeeling
dougkeeling / mixins.scss
Created August 31, 2021 17:29
[Cover one <div> with another completely] Allows for a specific amount of padding/inset from the edge of the parent div. #scss #css
@mixin cover($pos:absolute,$inset:0px) {
position: $pos;
bottom: $inset;
left: $inset;
right: $inset;
top: $inset;
width: calc(100% - (#{$inset} * 2));
height: calc(100% - (#{$inset} * 2));
}
@dougkeeling
dougkeeling / mixins.scss
Created August 31, 2021 17:25
[Convert Font Size to Em] #scss #css
$browser-context: 16;
@function em($pixels, $context: $browser-context) {
@if (unitless($pixels)) {
$pixels: $pixels * 1px;
}
@if (unitless($context)) {
$context: $context * 1px;
}