Genesis 2 CPT Archive Settings

This is pretty cool.

Basically, you can add backend editing to the CPT archive with something like this:

function register_snippet_post_type(){
  
  // custom post type arguments
	$post_type_args = array(
		'label'		=> __( 'Snippet' ),
		'description'	=> __( 'Display code snippets' ),
		'public'	=> true,
		'show_ui'	=> true,
		'show_in_menu'	=> true,
		'has_archive'	=> true,
		'supports'	=> array( 'title', 'editor', 'genesis-cpt-archives-settings' )
	);
	
	// register the 'snippet' post type
	register_post_type( 'snippet', $post_type_args );
	
}

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

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;
}

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/

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.
}

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');
		}
	}

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()
	);
}