Skip to content

Instantly share code, notes, and snippets.

View GarySwift's full-sized avatar

Gary Swift GarySwift

  • Waterford City, Ireland
View GitHub Profile
@GarySwift
GarySwift / list_thumbnail_sizes.php
Last active December 17, 2020 10:25 — forked from twesolowski/list_thumbnail_sizes.php
Wordpress - get all defined thumbnail sizes
<?php
function list_thumbnail_sizes($type = 'all', $name = '') {
global $_wp_additional_image_sizes;
$sizes = array();
$rSizes = array();
foreach (get_intermediate_image_sizes() as $s) {
$sizes[$s] = array(0, 0);
if (in_array($s, array('thumbnail', 'medium', 'large'))) {
$sizes[$s][0] = get_option($s . '_size_w');
$sizes[$s][1] = get_option($s . '_size_h');
@GarySwift
GarySwift / acf-php-to-json.php
Created September 24, 2020 10:53 — forked from ollietreend/acf-php-to-json.php
Convert Advanced Custom Fields Pro configuration from PHP to JSON.
<?php
/**
* Plugin Name: Convert ACF PHP to JSON
* Description: Convert Advanced Custom Fields Pro configuration from PHP to JSON.
*/
namespace ConvertAcfPhpToJson;
/**
* Add submenu item under 'Custom Fields'
@GarySwift
GarySwift / register-post-type.php
Created January 21, 2020 11:00 — forked from justintadlock/register-post-type.php
Help file when registering post types.
<?php
# Register custom post types on the 'init' hook.
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 1.0.0
* @access public
@GarySwift
GarySwift / gist:b5cf408c30257dd7efc3c8cae633e0cd
Last active May 25, 2018 10:35 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
@GarySwift
GarySwift / custom_menu_admin.php
Last active May 22, 2018 15:08 — forked from carlodaniele/custom_menu_admin.php
A basic plugin showing how to add menu metaboxes to admin menu page
<?php
/**
* @package Custom_menu_admin
* @version 1.0
*/
/*
Plugin Name: Custom menu admin
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin
Author: Carlo Daniele
@GarySwift
GarySwift / gist:fee4b77a05afbba620b7f5c20f61c69f
Created November 7, 2017 11:42 — forked from dwoodard/gist:4348994
Javascript: isValidDate()
function isValidDate(value, userFormat) {
// Set default format if format is not provided
userFormat = userFormat || 'mm/dd/yyyy';
// Find custom delimiter by excluding the
// month, day and year characters
var delimiter = /[^mdy]/.exec(userFormat)[0];
// Create an array with month, day and year
@GarySwift
GarySwift / isValidDate.js
Created November 7, 2017 11:42 — forked from aaugustin/isValidDate.js
isValidDate in JavaScript
export const DAYS_IN_MONTH = [null, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
function daysInMonth(year, month) {
// isValidDate checked that year and month are integers already.
// February of leap years. Assumes that the Gregorian calendar extends
// infinitely in the future and in the past.
if (month === 2 && (year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0))) {
return 29
}
@GarySwift
GarySwift / custom-menu-panel.php
Created May 13, 2017 16:57 — forked from nikolov-tmw/custom-menu-panel.php
This registers a custom meta box for nav menus and renders it. Obviously $my_items would ideally be not hard-coded and instead it would come somewhere from the DB. The custom items add to the menu and save properly, but will probably not be displayed correctly. You might need to hook to the 'wp_setup_nav_menu_item' filter in order to fix the men…
<?php
function my_register_menu_metabox() {
$custom_param = array( 0 => 'This param will be passed to my_render_menu_metabox' );
add_meta_box( 'my-menu-test-metabox', 'Test Menu Metabox', 'my_render_menu_metabox', 'nav-menus', 'side', 'default', $custom_param );
}
add_action( 'admin_head-nav-menus.php', 'my_register_menu_metabox' );
/**
@GarySwift
GarySwift / 0_reuse_code.js
Created April 27, 2017 08:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console