Skip to content

Instantly share code, notes, and snippets.

View SleeplessByte's full-sized avatar
💎
💎 💎 💎

Derk-Jan Karrenbeld SleeplessByte

💎
💎 💎 💎
View GitHub Profile
@SleeplessByte
SleeplessByte / helper_array_to_listing.php
Last active April 28, 2024 09:26
Creates a human readable list of an array, implodes all items, but combines last two first.
<?php
/**
* Creates a human readable list of an array
*
* @param string[] $ranges array to list items of
* @param string $glue normal glue between items
* @param string $last glue between last two items
*
* @remarks works with 0, 1, 2 or 3+ items
* @returns string 'item1, item2, item3 or item4'
@SleeplessByte
SleeplessByte / wp_custom_login.php
Last active December 10, 2015 22:38
Changes the login logo to a theme based one.
<?php
/**
* Changes the login logo and sets the appropiate sizes
*/
function custom_login_logo() {
$path = '/images/logo_login.png';
$size = getimagesize( get_template_directory() . $path );
if ( $size ) :
echo '<style type="text/css">
.login h1 a {
@SleeplessByte
SleeplessByte / wp_plugin_i18n.php
Last active December 10, 2015 22:28
Loads the textdomain for a plugin.
<?php
/**
* Preferably the plugin is (in) a class, so use:
* add_action( array( &$this, 'textdomain_init');
*/
add_action( 'plugins_loaded', 'textdomain_init' );
/**
* Initializes the textdomain for this plugin
*/
@SleeplessByte
SleeplessByte / wp_thumbnail_base_size.php
Last active December 10, 2015 22:18
Missing function to get the defined thumbnail size metadata and a check to see if an attachment's thumbnail is actually of that defined size.
<?php
/**
* Gets the thumbnail resize sizes.
*
* These are the sizes defined by the media options page or custom added sizes, rather than the actual
* thumbnail image sizes. Falls back to thumbnail if size does not exist. Put your size parameter first
* through the 'post_thumbnail_size' filter if you want WordPress get_post_thumbnail behaviour.
*
* @size either string with thumbnail name size or array with dimensions
* @returns array with width, height and crop parameters
@SleeplessByte
SleeplessByte / helper_get_current_url.php
Last active December 10, 2015 22:18
Gets the current displayed url for a page. key <> value pairs can be stripped from the url by key.
<?php
/**
* Gets the current displayed url
* @strip array of key names to be stripped from the url
* @returns the url
*/
protected function get_current_url( $strip = NULL ) {
$url = isset( $_SERVER["HTTPS"] ) && $_SERVER['HTTPS'] == "on" ? 'https://' : 'http://';
$url .= ( strlen( $_SERVER["SERVER_NAME"] ) ? $_SERVER["SERVER_NAME"] : $_SERVER['HTTP_HOST']);
$url .= ( !in_array( strval( $_SERVER["SERVER_PORT"] ), array( "80", "443" ) ) ) ? $_SERVER["SERVER_PORT"] : '';