Skip to content

Instantly share code, notes, and snippets.

View petertwise's full-sized avatar

Peter Wise petertwise

View GitHub Profile
@petertwise
petertwise / admin.js
Last active June 2, 2020 01:03
Improve Data Entry and Accessibility when WordPress ACF after_title field group area is used. Tab order is now natural and overrides the core WP javascript that moves the focus to the_content after #title.
// Admin Functions
( function( $ ) {
// better accessiblity and data entry for ACF
$(document).ready( function() {
// if there is a an "after_title" field group
if ( $( '#acf_after_title-sortables' ).length ) {
// listen for keydown inside the main title field for any add/edit screen
$('body.post-new-php, body.post-php').on( 'keydown', '#title', function( e ) {
var keyCode = event.keyCode || event.which;
// if the key is tab
### Settings > Advanced > Stripe > Stripe Styles
#### Base Style
{
"color": "#333",
"fontWeight": "300",
"fontFamily": "Merriweather, serif",
"fontSize": "16px",
"letterSpacing": "0.5px",
@petertwise
petertwise / active-cpt-menu-trail.php
Last active May 6, 2020 07:35
On the single view of any WordPress custom post type item, make the archive menu item for that post type active
<?php
// on the single view of any custom post type item, make the archive menu item for that post type active
// set the global scope variables
$current_menu_parent = null;
$current_menu_item = null;
// STEP 1: loop through all the menu items and find the current and parent items
function squarecandy_active_items_prepare( $classes ) {
@petertwise
petertwise / sync-remote
Created October 23, 2019 21:02
Bash Script to pull down WordPress database and files from a remote server
#!/bin/bash
# BEFORE YOU START:
# replace all instances of exampleproject with your real project usernames and local and remote paths
# make a backup of current local db
wp db export --add-drop-table
echo "✅ Make a backup of your current database state."
@petertwise
petertwise / newsite.sh
Created October 23, 2019 19:47
A small script for quickly whipping up a new WordPress site on localhost
#!/bin/bash
# Don't forget to enter your own email on line 19 and user Sites dir path on line 20
# set the slug
read -p "Enter the slug for the new site:" SLUG
# set the mysql password
read -s -p "Enter a MySQL password:" MYSQLPASS
# setup the directory and basic settings
@petertwise
petertwise / kses-test.php
Last active August 28, 2019 19:55
WordPress kses default arrays
<?php
$allowed_html = wp_kses_allowed_html( 'strip' );
// empty array - strips all html
/*
Array();
*/
@petertwise
petertwise / squarecandy-test-event-filter.php
Last active August 9, 2019 16:59
test squarecandy ACF events filtering system
<?php
/*
Plugin Name: Test Event Filter
Plugin URI: https://squarecandy.net
Description:
Version: 1.0.0
Author: Square Candy Design
Author URI: http://squarecandydesign.com
Text Domain: squarecandy
*/
@petertwise
petertwise / favdates.md
Last active February 8, 2019 15:20
Favorite PHP Date Formats

U.S. clients with mostly U.S. users

long

Used whenever there is room to display a long form date. These are the prefered format whenever possible.

Sunday, January 10, 2010 - 9:30pm
l, F j, Y - g:ia

Sunday, January 10 - 9:30pm

@petertwise
petertwise / yikes-acf-diff.diff
Created December 18, 2018 16:48
Running a diff between categories admin screen with YIKES Simple Taxonomy Ordering with and without ACF
diff --git a/test-yikes-drag-drop.html b/test-yikes-drag-drop-withACF.html
index 90c9158..c3b6358 100644
--- a/test-yikes-drag-drop.html
+++ b/test-yikes-drag-drop-withACF.html
@@ -34,10 +34,15 @@ img.emoji {
padding: 0 !important;
}
</style>
-<link rel='stylesheet' href='http://testwp.localhost/wp-admin/load-styles.php?c=1&amp;dir=ltr&amp;load%5B%5D=dashicons,admin-bar,common,forms,admin-menu,dashboard,list-tables,edit,revisions,media,themes,about,nav-menus,wp-pointer,widgets&amp;load%5B%5D=,site-icon,l10n,buttons,wp-auth-check&amp;ver=5.0.1' type='text/css' media='all' />
+<link rel='stylesheet' href='http://testwp.localhost/wp-admin/load-styles.php?c=1&amp;dir=ltr&amp;load%5B%5D=dashicons,admin-bar,common,forms,admin-menu,dashboard,list-tables,edit,revisions,media,themes,about,nav-menus,wp-pointer,widgets&amp;load%5B%5D=,site-icon,l10n,buttons,wp-auth-check,wp-color-picker&amp;ver=5.0.1' type='text/css' media='all' />
@petertwise
petertwise / functions.php
Created November 13, 2018 19:37
Examples of extending WordPress Walker_Nav_Menu for sibling and subpage menus
<?php
/**
* Custom Walker to extract current sister-sub-menu
*/
class Custom_Walker_Nav_Sister_Menu extends Walker_Nav_Menu {
var $found_parents = array();
function start_el(&$output, $item, $depth, $args) {