Category Archives: Coding

Breadcrumbs for Taxonomy for a Custom Post type

This is what I came up with to display the category, or rather a custom taxonomy, of a single posttype page of use in a breadcrumb. The taxonomy I used is ‘smg-logo-brand’ and the terms slug where ‘kcrg’, ‘the-gazette’ and ‘sourcemedia.’ I compared the terms associated with the post to that in the URL to determine which term belonged in the breadcrumb.

if (!is_tax() && get_post_type() == 'smg-logo' && has_term( array( 'kcrg', 'the-gazette', 'sourcemedia', 'other' ), 'smg-logo-brand' ) ) {
			$terms = get_the_terms( get_the_ID(), 'smg-logo-brand' );
			foreach ( $terms as $term ) {
				if ( strpos( $_SERVER["REQUEST_URI"], $term->slug ) !== false) {
					$breads['terms'] = '<a href="/logos/'. $term->slug . '/">' . $term->name . '</a>';
				}
			}
		}

WP-o-Matic breaks WordPress Related Links

function adminInit() {
		auth_redirect();

		// force display of a certain section
		$this->section = ($this->setup) ? ((isset($_REQUEST['s']) && $_REQUEST['s']) ? $_REQUEST['s'] : $this->sections[0]) : 'setup';
		
//    if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
//      die('Please switch to Firefox / Safari');

		wp_enqueue_script('prototype');
		wp_enqueue_script('wpoadmin', $this->tplpath . '/admin.js', array('prototype'), $this->version);

		if ($this->section == 'list')
			wp_enqueue_script('listman');

		//if ( WPOTools::isAjax() ) {
		if ( WPOTools::isAjax() &&  $this->section != 'home' ) { // Matt Thiessen 11/8/11
			$this->admin();
			exit;
		}
	}

SlidePress Plugin Redirect Bug

When clicking on settings links for the SlidePress plugin in a multi-user WordPress site the plugin would redirect to /wp-admin/?c=1 for each domain except the parent site.

[code lang=”php”]function get_current_user_role() {
global $current_user, $wp_roles;
$role_names = $wp_roles -> get_names();
/* UPDATED 11/2/2010 9:21 AM
* by matt.thiessen@sourcemedia.net
*/
// modified [start]
reset($current_user->roles);
$first_key = key($current_user->roles);
return preg_replace( “/\|.*/”, ”, $role_names[$current_user->roles[$first_key]]);
/*old*///return preg_replace( “/\|.*/”, ”, $role_names[$current_user->roles[0]]);
// modified [end]
}[\code]

Also, make sure if you are an admin user with super user privileges you are added at a admin user to the site you are using the SlidePress plugin.

This will add proper capabilities to the database in the wp_usermeta table.
meta_key: wp_25_capabilities
meta_value: a:1:{s:13:”administrator”;s:1:”1″;}

USPS Web Tools

I was trying to add the USPS API into osCommerce. I received the following error when adding this shipping module:

RateV3 is not a valid API name for this protocol

This is because when you create an account for the Web Tools at USPS you only have access to their test server. The USPS test server can only use RateV2, so test using this code below, then request to be switched to use the production server. Then you can use RateV3 on the production server and the USPS module for osCommerce will work.

<?php

$request1 = <<< XMLREQUEST
<RateV2Request USERID="xxxxxxxxxxxxx">
<Package ID="0">
<Service>PRIORITY</Service>
<ZipOrigination>10022</ZipOrigination>
<ZipDestination>20008</ZipDestination>
<Pounds>10</Pounds>
<Ounces>5</Ounces>
<Container>Flat Rate Box</Container>
<Size>REGULAR</Size>
</Package>
</RateV2Request>
XMLREQUEST;


$request = "http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&XML=" . rawurlencode($request1);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SLL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);


$response = curl_exec($ch);
curl_close($ch);

echo($response);

?>