Skip to content

Instantly share code, notes, and snippets.

View smchenrybc's full-sized avatar

Sean McHenry smchenrybc

View GitHub Profile
@mcaskill
mcaskill / acf-preview-changes-when-revisions-disabled.php
Created May 24, 2023 21:48
WP / ACF: Ensure ACF fields can be previewed when post revisions are disabled.
<?php
/**
* Ensure ACF fields can be previewed when post revisions are disabled
* (`WP_POST_REVISIONS`).
*
* @listens action:wp_revisions_to_keep
* Filters the number of revisions to save for the given post.
*/
add_filter( 'wp_revisions_to_keep', function ( int $num, WP_Post $post ) : int {
@pbrocks
pbrocks / install-phpcs-with-homebrew.md
Last active June 3, 2024 14:27
Install phpcs with Homebrew

Install phpcs with Homebrew

To set up php linting, you’ll want to install this PHP CodeSniffer repo and configure with this WordPress Coding Standards repo: . There are a number of ways to do this, whether direct download, Composer, Homebrew, Pear, etc. The following is what works for me on MacOS using Homebrew:

In a terminal window on your Mac, start by updating your Homebrew.

brew doctor

Then install the Code Sniffer:

@kingjmaningo
kingjmaningo / form-submit-admin-post.php
Last active January 9, 2024 13:44
Custom form submission using admin-post with wp_mail()
<!-- Sample custom form-->
<!-- We use admin-post.php provided to fully utilize the event driven nature of WordPress. -->
<form id="form-id" action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post">
<label for="first-name">First Name</label>
<input type="text" name="first-name" id="first-name" required>
<label for="last-name">Last Name</label>
<input type="text" name="last-name" id="last-name" required>
<label for="email">Email Address</label>
<input type="email" name="email" id="email" required>
<label for="birthday">Birthday:</label>
@dotherightthing
dotherightthing / migrating-from-gulp-391-to-402.md
Last active July 2, 2024 13:15
[Migrating a Gulpfile from Gulp 3.9.1 to 4.0.2] #gulp #es6 #babel

Migrating a Gulpfile from Gulp 3.9.1 to 4.0.2

Background

Via one of those mental leaps that one can only be achieved by working in two languages at once, I had found my way to Typescript.

I was excited about putting some rigour around my code. But as I sought to install the necessary dependencies, I started hitting versioning issues. I couldn't move forward with modern packages without addressing the dinosaur in the room, Gulp 3.9.1.

Migration Steps

@JoeyBurzynski
JoeyBurzynski / 55-bytes-of-css.md
Last active July 20, 2024 05:29
58 bytes of css to look great nearly everywhere

58 bytes of CSS to look great nearly everywhere

When making this website, i wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;
}
@premitheme
premitheme / README.md
Last active July 21, 2024 15:41
Recover MAMP MySQL database using .frm and .ibd files after InnoDB crash

Recover MAMP MySQL database using .frm and .ibd files after InnoDB crash

After a power faliur (also can be a sudden restart or system crash), I ended up with corrupted database and lost the access to my local hosted websites for development. Even the MAMP's MySQL server was not starting.

Preparation

You will need to find the databases folders, in case of MAMP they are located in Applications/MAMP/db/mysql56 (or mysql57 depending on MySQL version).

You will find folders containing the database name, inside them you will find .frm and .ibd files. Take a copy of the entire folder for backup in another place, the desktop for example.

@gagarine
gagarine / fish_install.md
Last active July 22, 2024 08:08
Install fish shell on macOS Mojave with brew

Installing Fish shell on MacOS (Intel and M1) using brew

Fish is a smart and user-friendly command line (like bash or zsh). This is how you can instal Fish on MacOS and make your default shell.

Note that you need the https://brew.sh/ package manager installed on your machine.

Install Fish

brew install fish

@robhrt7
robhrt7 / MySQL_5-7_macOS.md
Last active February 28, 2024 03:48 — forked from nrollr/MySQL_macOS_Sierra.md
Install MySQL 5.7 on macOS using Homebrew

This is a fork of original gist https://gist.github.com/nrollr/3f57fc15ded7dddddcc4e82fe137b58e, with slight changes on pointing to 5.7 version branch, instead of 8 (latest default of MySQL in Hombrew).

Install MySQL 5.7 on macOS

This procedure explains how to install MySQL using Homebrew on macOS (Sierra 10.12 and up)

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.
@chaance
chaance / wp-get-primary-tax-term.php
Last active September 11, 2020 08:13
Get the Yoast SEO primary term for a given taxonomy.
<?php
/**
* Get primary taxonomy term (YoastSEO).
*
* @param mixed $taxonomy Taxonomy to check for.
* @param boolean $term_as_obj Whether to return an object or the term name.
* @param int $post_id Post ID.
* @return mixed The primary term.
*/
function xx_get_primary_tax_term( $taxonomy = 'category', $term_as_obj = true, $post_id = 0 ) {
@cfxd
cfxd / filter.php
Last active May 7, 2022 07:13
Efficient Responsive Images in WordPress. See https://cfxdesign.com/efficient-responsive-images-in-wordpress
<?php
/*
* THE FILTER
*
*/
function custom_responsive_image_sizes($sizes, $img_name, $attachment_id) {
$sizes = wp_get_attachment_image_sizes($attachment_id, 'original');
$meta = wp_get_attachment_metadata($attachment_id);
$width = $meta['width'];