Skip to content

Instantly share code, notes, and snippets.

View kjbrum's full-sized avatar
🤘

Kyle Brumm kjbrum

🤘
View GitHub Profile
@kjbrum
kjbrum / get_all_strings_between.php
Last active May 8, 2018 19:18
Get all of the strings between 2 strings.
<?php
/**
* Get all of the strings 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 array An array of all the string that were found between $start and $end
*/
<?php
/**
* Get the ID of an attachment image using the file URL.
*
* @param string $url The URL of the image
* @return int $attachment The attachment image ID
*/
function wp_url_to_attachmentid( $url ) {
// Split the $url into two parts with the wp-content directory as the separator
$parsed_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );
@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;
<?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 / 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 ) {
@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 / 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 / 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 / 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 / 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;