Archive for the 'PHP' category

Breadcrumbs for Taxonomy for a Custom Post type

Apr 30 2012 Published by under PHP, Wordpress

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

No responses yet

WP-o-Matic breaks WordPress Related Links

Nov 08 2011 Published by under PHP, Wordpress

function adminInit() {

		// 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('wpoadmin', $this->tplpath . '/admin.js', array('prototype'), $this->version);

		if ($this->section == 'list')

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

No responses yet

SlidePress Plugin Redirect Bug

Nov 22 2010 Published by under PHP, Wordpress

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
// modified [start]
$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]

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

No responses yet

is_home() not working in my WordPress plugin

Aug 04 2009 Published by under PHP, Wordpress

When using is_home(), is_category(), is_page() etc. in my WordPress plugin that displays category-based ads, they kept returning NULL.

My problem was that I was calling this these function directly in my plugin. I resolved this by adding these call to my adHeaderSetup() function and setting the hook add_action(‘wp_head’, ‘adHeaderSetup’);

No responses yet

USPS Web Tools

Mar 27 2009 Published by under PHP

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.


$request1 = <<< XMLREQUEST
<RateV2Request USERID="xxxxxxxxxxxxx">
<Package ID="0">
<Container>Flat Rate Box</Container>

$request = "" . 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);



2 responses so far

Displaying Child Page Links in A Template

Feb 22 2009 Published by under PHP, Wordpress


ID . '&echo=0'); if ($children) { ?>
', '

'); ?>

No responses yet

php turns SQL to Excel

Dec 22 2008 Published by under PHP

Thanks StarGeek for this code.

this php script will write data from php using text from an SQL table (MySQL, supply your own SQL query) to a microsoft excel (.xls) file. The Excel file is specified as such by a set of headers, defining content, using php’s header() function.

//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

$result = mysql_query(‘select * from excel_test’, $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
$header .= mysql_field_name($result, $i).“t”;

while($row = mysql_fetch_row($result)){
$line = ;
$row as $value){
$value) || $value == “”){
$value = “t”;
# important to escape any quotes to preserve them in the data.
$value = str_replace(‘”‘, ‘””‘, $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
$value = ‘”‘ . $value . ‘”‘ . “t”;
$line .= $value;
$data .= trim($line).“n”;
# this line is needed because returns embedded in the data have “r”
# and this looks like a “box character” in Excel
$data = str_replace(“r”, “”, $data);

# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == “”) {
$data = “nno matching records foundn”;

# This line will stream the file to the user rather than spray it across the screen
header(“Content-type: application/octet-stream”);

# replace excelfile.xls with whatever you want the filename to default to
header(“Content-Disposition: attachment; filename=excelfile.xls”);
header(“Pragma: no-cache”);
header(“Expires: 0”);

echo $header.“n”.$data;

No responses yet