Sep 2, 2013 - git    Comments Off on Untracking tricksy files from git repos

Untracking tricksy files from git repos

# Do this on all machines
echo "FILE_NAME" >> .gitignore
git rm --cached FILE_NAME
git add -u
git commit -m "removing files from version control"
# Sync with your git server, pull to sync and push to register your local change
git pull
git push

Source

Jul 18, 2013 - WordPress    Comments Off on Combo image function

Combo image function

I created this to stack two images horizontally together, to make before and after images into one image. Designed for WordPress, but could be tweaked for other systems.

/**
 * use two images to create one image
 */
function msdlab_combine_images($params){
	extract(
		array_merge(
			array(
				'images' => array(),
				'orientation' => 'horizontal',
				'output_format' => 'jpg'
			)
		,$params)
	);
	//get info on each image
	foreach($images AS $key => $url){
		$imgs[$key]['url'] = $url;
		$imgs[$key]['path'] = $path = realpath(preg_replace('@'.site_url().'@i','.',$url));
		$imgs[$key]['file'] = $file = basename($path);
		$imgs[$key]['filename'] = $filename = preg_replace('/\.(?:jpg|jpeg|bmp|png|gif)/i','',$file);
		$imgs[$key]['info'] = $info = getimagesize($path);
		$comboname .= $filename;
		switch($orientation){
			case 'horizontal':
				$combowidth = $combowidth + $info[0];
				$comboheight = $info[1]>$comboheight?$info[1]:$comboheight;
				break;
			case 'vertical':
				$combowidth = $info[0]>$combowidth?$info[0]:$combowidth;
				$comboheight = $comboheight + $info[1];
				break;
		}
	}
	$comboname .= '.'.$output_format;
	$upload_dir = wp_upload_dir();
	//check if it exists
	if(file_exists($upload_dir['basedir'].'/'.$comboname)){
		return $upload_dir['baseurl'].'/'.$comboname;
	}
	//create a holding image
	$newimg = @imagecreatetruecolor($combowidth, $comboheight);
	foreach($imgs AS $key => $img){
		switch($img['info']['mime']){
			case 'image/jpeg':
				$src = @imagecreatefromjpeg($img['path']);
				break;
			case 'image/png':
				$src = @imagecreatefrompng($img['path']);
				break;
			case 'image/gif':
				$src = @imagecreatefromgif($img['path']);
				break;
			default:
				return 'unsupported file type';
		}
		//copy things
		switch($orientation){
			case 'horizontal':
				imagecopy($newimg, $src, $imgs[$key-1]['info'][0], 0, 0, 0, $img['info'][0], $img['info'][1]);
				break;
			case 'vertical':
				imagecopy($newimg, $src, 0, $imgs[$key-1]['info'][1], 0, 0, $img['info'][0], $img['info'][1]);
				break;
		}
		// free up memory
		imagedestroy($src);
	}
	// Save the image
	imagejpeg($newimg, $upload_dir['basedir'].'/'.$comboname);

	// Free up memory
	imagedestroy($newimg);

	//return the image
	return $upload_dir['baseurl'].'/'.$comboname;
}
Jun 25, 2013 - Admin Area, WordPress    Comments Off on Custom Login Page

Custom Login Page

Putting a custom login logo (or any other custom login styling) in place:

//Logo for login page
function custom_login_logo() {
	echo '<style type="text/css">
		#login h1 a { background-image: url('.INSERTLOGOHERE.') !important; }
	</style>';
}
add_action('login_head', 'custom_login_logo');
May 22, 2013 - Notes    Comments Off on Boilerplate TAR

Boilerplate TAR

Just a quick note on the command I use to make my boilerplate into a package.

export COPYFILE_DISABLE=true
tar -czf msd_wp_install_base.tar.gz -X exclude.txt msd_wp_install_base/
May 6, 2013 - PHP    Comments Off on Down and Dirty PHP mailer with backup CSV

Down and Dirty PHP mailer with backup CSV

<?php
if($_POST){
	//set up variables
	$to = '';
	$from = '';
	$cc = '';
	$bcc = '';
	$subject = '';
	$backup_filename = '';
	//loop through fields
	foreach($_POST AS $k => $v){
		$message .= '<li>'.$k.': '.$v."</li>\n";
		$csv_header .= $k.',';
		$csv_record .= $v.',';
	}
	//clean up for csv
	$csv_header .= "\n";
	$csv_record .= "\n";
	//htmlize message
	$message = '<html>
	<head>
	  <title>'.$subject.'</title>
	</head>
	<body>
	  <ul>'.$message.'</ul>
	</body>
	</html>';
	// To send HTML mail, the Content-type header must be set
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	// Additional headers
	//$headers .= 'To:' . $to . "\r\n";
	$headers .= 'From:' . $from . "\r\n";
	$headers .= 'Cc:'. $cc . "\r\n";
	$headers .= 'Bcc:'. $bcc . "\r\n";
	// Mail it
	mail($to, $subject, $message, $headers);
	//store backup data
	if (!file_exists($backup_filename)) {
		$csv_record = $csv_header.$csv_record;
	}
	if (!$handle = fopen($backup_filename, 'a')) {
		exit;
	}
	if (fwrite($handle, $csv_record) === FALSE) {
		exit;
	}
	fclose($handle);
	//done.
}
Apr 9, 2013 - Admin Area    Comments Off on Change Title Entry Text on CPT

Change Title Entry Text on CPT

The hook:

		add_filter( 'enter_title_here', array(&$this,'change_default_title') );

The actual filter:

	function change_default_title( $title ){
		$screen = get_current_screen();
		if  ( $screen->post_type == 'msd_team' ) {
			return __('Enter Team Member (FirstName Lastname) Here','msd_roster');
		}
	}
Mar 16, 2013 - WordPress    1 Comment

Allow all Embeds

add_action('init','msd_allow_all_embeds');
function msd_allow_all_embeds(){
	global $allowedposttags;
	$allowedposttags["iframe"] = array(
			"src" => array(),
			"height" => array(),
			"width" => array()
	);
	$allowedposttags["object"] = array(
			"height" => array(),
			"width" => array()
	);

	$allowedposttags["param"] = array(
			"name" => array(),
			"value" => array()
	);

	$allowedposttags["embed"] = array(
			"src" => array(),
			"type" => array(),
			"allowfullscreen" => array(),
			"allowscriptaccess" => array(),
			"height" => array(),
			"width" => array()
	);
}
Feb 13, 2013 - Admin Area, WordPress    Comments Off on Move meta box above editor

Move meta box above editor

add_action('admin_footer','subtitle_footer_hook');
function subtitle_footer_hook()
{
	?><script type="text/javascript">
	jQuery('#titlediv').after(jQuery('#_speaker_title_metabox'));
	jQuery('#_speaker_title_metabox').after(jQuery('#_speakers_metabox'));
	</script><?php
}
Jan 7, 2013 - CSS    Comments Off on Handy HTML entities

Handy HTML entities

 &#9658;
 &#9660;

Others in this range also probably useful.