Skip to content

Instantly share code, notes, and snippets.

View kjbrum's full-sized avatar
🤘

Kyle Brumm kjbrum

🤘
View GitHub Profile
@kjbrum
kjbrum / object_to_array.php
Last active November 11, 2015 20:36
Convert an object to an array.
<?php
/**
* Convert an object to an array.
*
* @param array $object The object to convert
* @return array The converted array
*/
function object_to_array( $object ) {
if( !is_object( $object ) && !is_array( $object ) ) return $object;
return array_map( 'object_to_array', (array) $object );
@kjbrum
kjbrum / autoResizeInput.js
Last active June 2, 2016 14:09
Automatically resize input fields while typing
/**
* Automatically resize input fields while typing
*
* Usage: $('input.autoresize').autoResizeInput({ minWidth: 250, comfortZone: 0 });
*/
(function($){
$.fn.autoResizeInput = function(o) {
o = $.extend({
@kjbrum
kjbrum / wp_remove_h1_from_editor.php
Last active November 2, 2022 19:07
Remove h1 from the WordPress editor.
<?php
/**
* Remove the h1 tag from the WordPress editor.
*
* @param array $settings The array of editor settings
* @return array The modified edit settings
*/
function remove_h1_from_editor( $settings ) {
$settings['block_formats'] = 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;Preformatted=pre;';
return $settings;
@kjbrum
kjbrum / full_width_image.scss
Last active June 16, 2016 17:21
Make an article image the full width of the page.
.full-image {
position: relative;
left: calc(-50vw + 50%);
width: 100vw;
margin: 2rem 0;
img {
width: 100%;
}
}
@kjbrum
kjbrum / get_pretty_date_range.php
Last active November 11, 2015 20:34
Prettify a range of dates.
<?php
/**
* Prettify a range of dates.
*
* @param mixed $start The start date
* @param mixed $end The end date
* @param string $format A date() string for formatting if the dates match
* @param string $format_day A date() string for formatting if they are different days
* @param string $format_month A date() string for formatting if they are different months
* @param string $format_year A date() string for formatting if they are different years
@kjbrum
kjbrum / get_pretty_time_range.php
Last active November 11, 2015 20:34
Prettify a range of times.
<?php
/**
* Prettify a range of times.
*
* @param mixed $start The start date, with time
* @param mixed $end The end date, with time
* @return string A prettified date() string for the time range
*/
function get_pretty_time_range( $start='', $end='' ) {
$diff_meridiem = false;
@kjbrum
kjbrum / Google Map (WordPress).md
Last active October 13, 2015 16:57
Quick start instructions for setting up a Google Map in WordPress with the JavaScript API.

1. Get a Key for the JavaScript API

Visit the documentation and follow the instructions.

2. Include the JavaScript API

  • Copy your API key, and add the following snippet to your functions.php.
    • Replace YOUR_API_KEY with your key you copied.
@kjbrum
kjbrum / wp_allow_user_login_with_email.php
Last active May 21, 2016 02:14
Allow users to login to the site with their username or email.
<?php
/**
* Allow users to login to the site with their username or email.
*
* @param object $user WP_User object
* @param string $username_email The username or email entered for login
* @param string $password The users password
* @return object The authenticated WP_User object
*/
function wp_allow_user_login_with_email( $user, $username_email, $password ) {
<?php
/**
* Get a string between 2 strings.
*
* @param string $string The string to search
* @param string $start The string to start with
* @param string $end The string to end with
* @param boolean $case_sensitive Whether to make the search case sensitive or not
* @return string The string that was found between the start and end
*/
@kjbrum
kjbrum / remove_empty_values.php
Last active November 11, 2015 20:35
Remove empty values from an array.
<?php
/**
* Remove empty values from an array.
*
* @param array $arr The array to remove values from
* @return array The new array without the empty values
*/
function remove_empty_values( $arr ) {
if( ! is_array( $arr ) ) return $arr;