Skip to content

Instantly share code, notes, and snippets.

@tjhole
tjhole / iThemes Exchange Postcode Zip
Created August 26, 2015 15:33
iThemes Postcode Zip State
/* ========================================================================================================================
iThemes Postcode
======================================================================================================================== */
function my_translated_text_strings( $translated_text, $untranslated_text, $domain ) {
$translated_text = $untranslated_text;
@tjhole
tjhole / WORDPRESS: Full Menu
Created February 21, 2014 16:21
WORDPRESS: Full Menu
<?php
$defaults = array(
'theme_location' => '',
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
@tjhole
tjhole / WORDPRESS: Menu Short
Created February 21, 2014 16:22
WORDPRESS: Menu Short
<?php
$defaults = array(
'theme_location' => 'primary',
'container' => 'false',
'menu_class' => 'menu',
'menu_id' => 'nav',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
);
@tjhole
tjhole / WORDPRESS: rename admin items
Created April 3, 2014 11:26
WORDPRESS: Rename admin items
add_filter('gettext', 'rename_admin_menu_items');
add_filter('ngettext', 'rename_admin_menu_items');
/**
* Replaces wp-admin menu item names
*
* @author Daan Kortenbach
*
* @param array $menu The menu array.
*
* @return $menu Menu array with replaced items.
@tjhole
tjhole / PHP: String to ID
Created April 9, 2014 11:41
PHP: String to ID
function toID($string) {
//Lower case everything
$string = strtolower($string);
//Make alphanumeric (removes all other characters)
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
//Clean up multiple dashes or whitespaces
$string = preg_replace("/[\s-]+/", " ", $string);
//Convert whitespaces and underscore to dash
$string = preg_replace("/[\s_]/", "-", $string);
return $string;
@tjhole
tjhole / WORDPRESS: Create safe ID from ACF title
Created April 19, 2014 13:15
WORDPRESS: Create safe ID from ACF title
function safeID( $string, $separator = '_' )
{
$accents_regex = '~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i';
$special_cases = array( '&' => 'and');
$string = mb_strtolower( trim( $string ), 'UTF-8' );
$string = str_replace( array_keys($special_cases), array_values( $special_cases), $string );
$string = preg_replace( $accents_regex, '$1', htmlentities( $string, ENT_QUOTES, 'UTF-8' ) );
$string = preg_replace("/[^a-z0-9]/u", "$separator", $string);
$string = preg_replace("/[$separator]+/u", "$separator", $string);
@tjhole
tjhole / WORDPRESS: Save GPS Meta on Upload
Created April 24, 2014 16:13
WORDPRESS: Save GPS Meta on Upload
function add_geo_exif($meta,$file,$sourceImageType) {
$exif = @exif_read_data( $file );
if (!empty($exif['GPSLatitude']))
$meta['latitude'] = $exif['GPSLatitude'] ;
if (!empty($exif['GPSLatitudeRef']))
$meta['latitude_ref'] = trim( $exif['GPSLatitudeRef'] );
if (!empty($exif['GPSLongitude']))
$meta['longitude'] = $exif['GPSLongitude'] ;
if (!empty($exif['GPSLongitudeRef']))
$meta['longitude_ref'] = trim( $exif['GPSLongitudeRef'] );
@tjhole
tjhole / WORDPRESS: Debug On
Created May 6, 2014 10:05
WORDPRESS: Debug On
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);
ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
@tjhole
tjhole / WORDPRESS: CDN Function
Created May 9, 2014 10:26
WORDPRESS: CDN Function
function my_cdn_upload_url() {
return 'http://static.mahtabhussain.com/content/uploads';
}
add_filter( 'pre_option_upload_url_path', 'my_cdn_upload_url' );
@tjhole
tjhole / WORDPRESS: Set Cookie Domain
Created May 12, 2014 07:22
WORDPRESS: Set Cookie Domain