Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
#doworkson

Kodie Grantham kodie

💻
#doworkson
View GitHub Profile
View wordpress-core.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 Sep 21, 2021
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
View simple-mobile-navigation.js
/*
* 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 Apr 23, 2021
Use a datalist in place of a select dropdown for wp_dropdown_users in WordPress
View wp_dropdown_users_datalist.php
<?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 Apr 23, 2021
fancy-bottom-border SCSS mixin
View input.scss
@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 Apr 14, 2021
Require email verification for custom Wordpress registration
View functions.php
<?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 Oct 22, 2020
Array map function that allows you to change keys as well as values
View array_map_assoc.php
<?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 Oct 21, 2020
Adds an "image_size" argument to get_avatar_data so that avatar image sizes can be defined by the image size name in WordPress
View avatar_data_image_size_arg.php
<?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 Oct 21, 2020
Allows for custom avatars to be pulled from usermeta in WordPress
View custom_user_avatar_url.php
<?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);
}
@kodie
kodie / get_images_sizes.php
Created Oct 21, 2020
A function to get with, height, and if crop is available for all image sizes in WordPress regardless if they are built-in sizes or custom set ones
View get_images_sizes.php
<?php
// Get information about available image sizes
function get_image_sizes($size = null) {
$sizes = array();
$size_data = wp_get_additional_image_sizes();
$size_names = get_intermediate_image_sizes();
$default_sizes = array_diff($size_names, array_keys($size_data));
if ($size) $size_names = array($size);
View _grid.scss
@mixin grid($cols: 4, $gap: 2rem, $item: '> *') {
&:after {
clear: left;
content: '';
display: block;
}
#{$item} {
box-sizing: border-box;
float: left;