Skip to content

Instantly share code, notes, and snippets.

View doubleedesign's full-sized avatar

Leesa Ward doubleedesign

View GitHub Profile
@doubleedesign
doubleedesign / user-join-date-column.php
Created December 22, 2020 10:14
Add a join date column to the users table in wp-admin
<?php
/**
* Add custom columns in Users area in the CMS
* @param $columns
*
* @return mixed
*/
function doublee_manage_users_columns($columns) {
$columns['join_date'] = 'Join date';
@doubleedesign
doubleedesign / current-menu-item.php
Created January 3, 2021 07:26
Add class to CPT archive link in menus when viewing a post of that type
<?php
// Add current-menu-item to post type archive link for this post's type
function doublee_menu_classes($classes, $item) {
global $post;
$id = (isset($post->ID) ? get_the_ID() : NULL);
if(isset($id) && $item->type == 'post_type_archive') {
$current_post_type = get_post_type($id);
$link_post_type = $item->object;
if($current_post_type == $link_post_type) {
@doubleedesign
doubleedesign / create-zip.php
Last active January 17, 2021 06:20
Add a "download all" option to emails for WooCommerce downloadable products. Zips all the files and stores the zip in a specified directory.
<?php
/**
* Utility function to create a zip file from an array of file URLs
* Used for download links in emails
* @param array $files
* @param string $filename
*
* @return string
*/
function doublee_zip_order_files(array $files, string $filename) {
@doubleedesign
doubleedesign / add-base-tier-option.php
Last active January 18, 2021 01:11
Automatically downgrade a WooCommerce subscription (to a free, no-expiry variation) instead of expiring it
<?php
/**
* Add base tier option to Advanced tab of subscription product
*/
function doublee_subscription_product_advanced_settings() {
$product = wc_get_product(get_the_id());
if($product->get_type() === 'variable-subscription') {
$variations = $product->get_available_variations();
$variation_options = array();
foreach ($variations as $variation) {
@doubleedesign
doubleedesign / convert-milliseconds.js
Last active April 22, 2021 01:34
Timed pop-up using Zurb Foundation Reveal (modal); stores whether the user has dismissed it or already subscribed in local storage. This example is built in WordPress using ACF to get values of what to store, when to show up etc (and Ninja Forms for the form but of course it doesn't have to be used for a form).
/**
* Convert milliseconds to the desired format
* @param milliseconds
* @param format
* @returns {*}
* @see https://gist.github.com/flangofas/714f401b63a1c3d84aaa
*/
function convertMilliseconds(milliseconds, format) {
var total_days, total_hours, total_minutes, total_seconds;
@doubleedesign
doubleedesign / functions.php
Created April 28, 2021 03:48
Log all WordPress hooks that run
<?php
function doublee_log_all_actions() {
foreach($GLOBALS['wp_actions'] as $action => $count) {
error_log(print_r($action, true));
}
}
add_action('shutdown', 'doublee_log_all_actions');
@doubleedesign
doubleedesign / javascript-delayed-event.js
Created December 9, 2018 09:16
How to delay a JavaScript event within an event listener
function myDelayedThing() {
var mySelectors = document.querySelectorAll('.something');
// Loop through mySelectors
for(var i = 0; i < menuLinks.length; i++) {
// Add 'open' class on mouseover
menuLinks[i].addEventListener('mouseover', function() {
this.classList.add('open');
@doubleedesign
doubleedesign / YearbookClasses.jsx
Last active November 23, 2022 15:49
InDesign Image Catalog for multiple folders at once (and multiple folders per page). Created for school yearbook projects (one folder per class, two classes per page) but could be adapted for other use cases where you want to lay out contact sheets of multiple folders automatically.
/**
* Custom Image Catalog script that runs for all subfolders in a selected folder.
* Lays out each folder of images in the specified number of rows and columns, 2 folders per page, shows an alert if there's more images than allowed for,
* labels each group with the folder name, creates paragraph styles for the captions and group headings, and saves the file.
*
* Based on the built-in Image Catalog script but modified and simplified (e.g. hard-coding the settings) for my use case.
* Could be modified to suit different numbers of folders per page, different image quantities etc by changing the settings at the top
* and making tweaks to other code as needed.
*
* Could also be extended to show one dialog for settings prior to the loop,
@doubleedesign
doubleedesign / excerpt-metabox-to-top.php
Created December 4, 2018 00:51
Move the WordPress Excerpt metabox to the top of post and page edit screens
/**
* Move the excerpt metabox to the top
* @param $post_type
*/
function doublee_custom_excerpt_metabox( $post_type ) {
if(in_array($post_type, array('post','page'))) {
add_meta_box(
'excerpt_meta', __( 'Excerpt' ), 'post_excerpt_meta_box', $post_type, 'temp', 'high'
);
}
@doubleedesign
doubleedesign / acf-tsf-integration.php
Last active December 9, 2022 13:06
Get meta descriptions in The SEO Framework from ACF flexible content fields
<?php
/**
* The SEO Framework + ACF flexible content integration
* TSF will look at the excerpt and then the content to generate the default meta description.
* If both of those are empty, this code looks for ACF flexible modules to get it from.
* // TODO: Make this work with archives as well as posts
* @param $description
* @param $args
*
* @return mixed|string