Category Archives: Development
WordPress Import Hack – Quick & Dirty
After finally convincing a client of mine to replace their existing 6 year old, custom built, extremely limiting & buggy blog software I’ve had to put in a bit of effort to transfer there 150+ blog posts from the MySQL table into WordPresses MySQL tables, which is pretty straight forward; the key here is to keep all of there featured images in place.
The following code does just that. It takes all the posts from the current blog, imports them into WordPresses tables, it inserts the featured image and then links it to the parent post. All thats then left to do is upload the images directory to WordPresses upload dir.
[php]
## DATABASE CONNECTION
// trololol you don’t get to see this :]
## CLEAN URLS PLEASE
function toAscii($str) {
$clean = preg_replace(“/[^a-zA-Z0-9\/_|+ -]/”, ”, $str);
$clean = strtolower(trim($clean, ‘-‘));
$clean = preg_replace(“/[\/_|+ -]+/”, ‘-‘, $clean);
return $clean;
}
## SELECT THE BLOG DATABASE TO IMPORT, ORDER IT BY ID ASC (OR BY DATE ASC W/E)
$blog_q = mysql_query(“SELECT * FROM `blog` ORDER BY `ID` ASC”);
while($blog = mysql_fetch_array($blog_q)):
## INSERT POST INTO WORDPRESS
mysql_query(“INSERT INTO `wp_posts` (
`post_author`,
`post_date`,
`post_date_gmt`,
`post_content`,
`post_title`,
`post_excerpt`,
`post_status`,
`comment_status`,
`ping_status`,
`post_password`,
`post_name`,
`to_ping`,
`pinged`,
`post_modified`,
`post_modified_gmt`,
`post_content_filtered`,
`post_parent`,
`guid`,
`menu_order`,
`post_type`,
`post_mime_type`,
`comment_count`) VALUES(
‘1’,
‘”.$blog[‘blogDATESUBMITTED’].”‘,
‘”.$blog[‘blogDATESUBMITTED’].”‘,
‘”.$blog[‘blogARTICLE’].”‘,
‘”.$blog[‘blogTITLE’].”‘,
”,
‘publish’,
‘open’,
‘open’,
”,
‘”.toAscii($blog[‘blogTITLE’]).”‘,
”,
”,
‘”.$blog[‘blogDATESUBMITTED’].”‘,
‘”.$blog[‘blogDATESUBMITTED’].”‘,
”,
‘0’,
”,
‘0’,
‘post’,
”,
‘0’
)”);
## INSERT IMAGE INTO POSTS FEATURED IMAGE
mysql_query(“INSERT INTO `wp_posts` (
`post_author`,
`post_date`,
`post_date_gmt`,
`post_content`,
`post_title`,
`post_excerpt`,
`post_status`,
`comment_status`,
`ping_status`,
`post_password`,
`post_name`,
`to_ping`,
`pinged`,
`post_modified`,
`post_modified_gmt`,
`post_content_filtered`,
`post_parent`,
`guid`,
`menu_order`,
`post_type`,
`post_mime_type`,
`comment_count`) VALUES(
‘1’,
‘”.$blog[‘blogDATESUBMITTED’].”‘,
‘”.$blog[‘blogDATESUBMITTED’].”‘,
”,
‘”.$blog[‘blogIMAGEALT’].”‘,
”,
‘inherit’,
‘open’,
‘open’,
”,
‘”.toAscii($blog[‘blogIMAGEALT’]).”‘,
”,
”,
‘”.$blog[‘blogDATESUBMITTED’].”‘,
‘”.$blog[‘blogDATESUBMITTED’].”‘,
”,
‘”.mysql_insert_id().”‘,
‘http://www.newdomain.com/wp-content/uploads/2012/03/”.$blog[‘blogIMAGE’].”‘,
‘0’,
‘attachment’,
‘image/jpeg’,
‘0’
)”);
## LINK IT TOGETHER IN THE POST_META
mysql_query(“INSERT INTO `wp_postmeta` (`post_id`, `meta_key`, `meta_value`) VALUES(‘”.mysql_insert_id().”‘, ‘_wp_attached_file’, ‘2012/03/”.$blog[‘blogIMAGE’].”‘)”);
## AND SPIT OUT ONCE DONEā¦.
echo $blog[‘ID’].’ —> ‘.$blog[‘blogTITLE’].’
‘;
endwhile; // end, select the blog database
[/php]
WooCommerce: Limiting Product Lists
Woocommerce limits the product listings in the shop in relation to the reading settings within WordPress, so if you only show 10 blog posts at a time then your woocommerce shop will only show 10 products per page. Not always a great idea, to fix add this to your functions.php file and change 20 to however many you want to show;
[php]
add_filter(‘loop_shop_per_page’, create_function(‘$cols’, ‘return 20;’));
[/php]
FaceBook Share
[php]
/*
Plugin Name: Very Simple FaceBook Share
Plugin URI: http://www.paulOr.net/facebook-share/
Description: A very simple shortcode plugin which will allow you to put a facebook sharecode on any page or post via [fbshare] – you can also style it any way with [fbshare style=”color:#ffffff; text-decoration: underline;”]
Author: Paul Fraser
Version: 1
Author URI: http://www.paulOr.net
*/
function FBShare($params, $content = null) {
extract(shortcode_atts(array(
‘style’ => ”
), $params));
return ‘<a ‘.($style == ” ? ” : ” style=\”$style\””).’ name=”fb_share”></a><script src=”http://static.ak.fbcdn.net/connect.php/js/FB.Share” type=”text/javascript”></script>’;
}
add_shortcode(‘fbshare’,’FBShare’);
[/php]
Very simple facebook share plugin which allows you to just add a shortcode to a page or post & style it via [fbshare style=”blah: blah;”]
Download: FBShare.php
iOS App Adventures – Part 1

I think it was just about a year ago now that I had an idea for an epic iPhone App that (I think) would be useful and more importantly an app that does something better than the current apps out there in this field at the moment. I sat down and drew out what I needed and my train of thought was NATIVE APPS.
I’ve recently been doing a lot of responsive HTML/CSS stuff so my thoughts have changed from native to mobile web however I still wanted a presence in the App Store because its the only way to truly deliver the product.
I had some free time over the past couple days, signed up for a iOS developer account and began.
24 Hours later & my app is ready :)!


You might say “Its ONLY a webview UI – thats nothing special.” and you’d be right, but that is all I need for this app since I’m making the interface on the web – It does however have these two little buttons at the bottom, Home & Settings which are like hotkeys to take you to these pages fast, which is slightly more than ‘ONLY a webview UI’.
I don’t care – Im pretty happy with what I’ve made & also with the end result. Watch this space!
Update!
iPad Version!

Add Product Images into Shopp Receipt
[php]
## ADD THIS INTO FUNCTIONS.PHP
add_filter(‘shopp_tag_purchase_item-image’,’purchased_image’,10, 3);
function purchased_image($result, $options, $Purchase) {
$item = current($Purchase->purchased);
$product = new Product($id=$item->product);
return $product->tag($property=’coverimage’);
}
## NOW YOU CAN SHOW THE IMAGES INSIDE THE PURCHASED ITEMS WHILE LOOP
shopp(‘purchase’,’item-image’);
[/php]
I’ve long said Shopp is a total bellend, they totally missed out putting the product image tags into half the hooks. The above, will allow you to show the product image in the receipt, after all – its always nice to show you what you have bought after you’ve paid good money.
Get a grip Shopp – I’m so moving to WooCommerce.