Skip to content

Instantly share code, notes, and snippets.

View kodie's full-sized avatar
💻
#doworkson

Kodie Grantham kodie

💻
#doworkson
View GitHub Profile
@kodie
kodie / updateModified.js
Last active April 15, 2024 07:02
A JavaScript function for Google Sheets that updates a specific cell with the current date/time when cell(s) are updated.
function getColumnNumberByName(name, sheet) {
if (!sheet) {
sheet = SpreadsheetApp.getActiveSheet()
}
var headers = sheet.getDataRange().offset(0, 0, 1).getValues()[0]
var column = false
for (var i = 0; i < headers.length; i++) {
if (headers[i].trim() === name) {
@kodie
kodie / parse_argv.php
Last active January 10, 2022 17:09
Parse $argv in PHP get the command, arguments, options, and flags
<?php
/**
* Parses $argv to get the command, arguments, options, and flags.
*
* @param array $args The $argv variable.
* @param array $short_opts Optional. An array with keys set to short options and their values set to the long option they're assigned to.
* @param array $flag_opts Optional. An array of options to be treated as flags. If a flag is not defined here, it will be treated as an option.
*
* @return array An array with the command, arguments, options, and flags keys.
*/
@kodie
kodie / wordpress-core.css
Created December 8, 2021 18:40
The WordPress Core CSS found at https://codex.wordpress.org/CSS
/* =WordPress Core
-------------------------------------------------------------- */
.alignnone {
margin: 5px 20px 20px 0;
}
.aligncenter,
div.aligncenter {
display: block;
margin: 5px auto 5px auto;
@kodie
kodie / simple-mobile-navigation.js
Created September 21, 2021 17:14
A simple mobile navigation jQuery plugin - Originally created by the good people over at PSD2HTML.com - Simply here so we can pull the code in remotely
/*
* Simple Mobile Navigation
*/
;(function($) {
function MobileNav(options) {
this.options = $.extend({
container: null,
hideOnClickOutside: false,
menuActiveClass: 'nav-active',
menuOpener: '.nav-opener',
@kodie
kodie / wp_dropdown_users_datalist.php
Created April 23, 2021 18:08
Use a datalist in place of a select dropdown for wp_dropdown_users in WordPress
<?php
// Use a datalist in place of a select dropdown for wp_dropdown_users
add_filter('wp_dropdown_users', 'wp_dropdown_users_datalist');
function wp_dropdown_users_datalist($html) {
preg_match("/name='(.*?)'/", $html, $name);
preg_match("/id='(.*?)'/", $html, $id);
$html = str_replace(array('<select', '/select>'), array('<datalist', '/datalist>'), $html);
$html = preg_replace("/id='$id[1]'/", "id='$id[1]-list'", $html);
$html = preg_replace("/name='$name[1]'/", '', $html);
@kodie
kodie / input.scss
Last active April 23, 2021 18:15
fancy-bottom-border SCSS mixin
@mixin fancy-bottom-border($border-color: 'blue', $border-size: 4px, $line-height: 1rem) {
$bg-stop: calc(#{$line-height} - #{$border-size});
background-image: linear-gradient(to bottom, transparent $bg-stop, $border-color $bg-stop, $border-color $line-height);
background-repeat: repeat-y;
background-size: 100% $line-height;
line-height: $line-height;
text-decoration: none;
}
@kodie
kodie / functions.php
Created April 14, 2021 20:20
Require email verification for custom Wordpress registration
<?php
// Generate an email verification code and send it to their email
add_action('user_register', 'send_new_user_email_verification', 10, 1);
function send_new_user_email_verification($user_id) {
$user = get_userdata($user_id);
$email = $user->user_email;
$site_name = get_bloginfo('name');
$code = wp_generate_password(32, false, false);
$hash = md5($code);
$link = add_query_arg(array(
@kodie
kodie / array_map_assoc.php
Last active April 24, 2024 12:04
Array map function that allows you to change keys as well as values
<?php
// Array map function that allows you to change keys as well as values
// Example: array_map_assoc(function($k, $v) { return array($k => $v); }, $array);
function array_map_assoc(callable $f, array $a) {
return array_merge(...array_map($f, array_keys($a), $a));
}
?>
@kodie
kodie / avatar_data_image_size_arg.php
Created October 21, 2020 20:16
Adds an "image_size" argument to get_avatar_data so that avatar image sizes can be defined by the image size name in WordPress
<?php
// Adds an "image_size" argument to get_avatar_data so that avatar image sizes
// can be defined by the image size name (requires the get_image_sizes function)
// (https://gist.github.com/kodie/19d027d2c0e2297d1e09b7b71505e774)
// Example: get_avatar_url($user_id, array('image_size' => 'thumbnail'));
add_filter('pre_get_avatar_data', 'avatar_data_image_size_arg', 10, 2);
function avatar_data_image_size_arg($args, $id_or_email) {
if (isset($args['image_size'])) {
if ($size = get_image_sizes($args['image_size'])) {
$args['height'] = $size['height'];
@kodie
kodie / custom_user_avatar_url.php
Last active October 21, 2020 20:19
Allows for custom avatars to be pulled from usermeta in WordPress
<?php
// Allows for custom avatars to be pulled from usermeta
add_filter('get_avatar_url', 'custom_user_avatar_url', 10, 3);
function custom_user_avatar_url($url, $id_or_email, $args) {
$image_url = false;
$user = false;
if (is_object($id_or_email) && isset($id_or_email->comment_ID)) {
$id_or_email = get_comment($id_or_email);
}