Author Box Adding Additional Contacts Hack

After posting about another app created by a developer in the Baby Steps: BB Dev BBM Group, I asked the group if anyone wanted to post an article on my blog about what is like to work with the BBM Group. Since the developers in the group are always thanking each other for help, I figured it would be good for developers outside of our group to know that there are groups who like to be helpful to each other when developing apps. And, since it is always good to get multiple opinions, I figured it would be good for some other people in the group to write some articles. Also, I wanted to help those guys by spreading the word about their app development efforts. This is where the Author Box came in.

I had messed with Author Boxes on other blogs before. They are very helpful when you have a blog with many authors, so that the new reader can get an idea of who is writing the article. For my blog, I didn’t need it, because, well, it was just my blog. Having added the feature before, I figured it would be a simple as grabbing the plug-in and installing it. It would have been simple, if I hadn’t made my blog into a multi-blog (which I still haven’t totally implemented yet), instead of a single blog. The first Author Box plug-in I found didn’t work. Nor did the second one. On my third try, I found Author Box After Post by Jeriff Cheng.
This plug-in seemed a bit more straight forward than the others, which is probably why it worked. It was so simple, that I thought I would modify it to add BlackBerry World Vendor (BBW Vendor) and BlackBerry Messenger Channel (BBM Channel) as two new contact methods. The reason I wanted to add those two, would be for the guest authors to help promote their apps and their app Channel. As I started working with the plug-in, I noticed that the Twitter link would show regardless if I had added a Twitter Username to my contact list. The issue was that the Twitter URL used “https” instead of “http”, which lead the plug-in writer to append the Twitter URL to the Twitter Username in the initial contact creation.

  if ( isset( $contactmethods['twitter'] ) )
    unset( 'https://twitter.com/'.$contactmethods['twitter'] );

Which meant that if you even if you didn’t have a Twitter account, it would still be saved with the value of the pre-URL. The later check for a value was useless, because it would always have a value.

if($abap_twitter_url)

I removed it from the initialize portion and added the pre-URL to the display code after the check for the value.

Also, I noticed that if you only had 1 contact, there was a  •  left after that one contact. That seemed a little bit odd, so I checked into and noticed that the code was there for all the contacts expect the last one. I decided to do a check first to see if the contact was the next contact and then append  •  in front of the link for the contact value.

$isNext = false;

if($abap_skype_url){
	if($isNext) {
		$abap_skype_url='&nbsp;&#8226;&nbsp;<a rel="me nofollow" href="skype:'.$abap_skype_url.'?call" target="_blank">Skype</a>';
	} else {
		$isNext = true;
		$abap_skype_url='<a rel="me nofollow" href="skype:'.$abap_skype_url.'?call" target="_blank">Skype</a>';
	}		
}else {
	$abap_skype_url='';
}

If if wasn’t the next contact, it was the first one, so I would set the isNext value at that point and not include the pre-code.

Finally, I added the code to add my two new contact values. Which basically consisted of initializing/de-initializing the values

//Remove user contact methods
 if ( isset( $contactmethods['bbmchannel'] ) )
    unset( $contactmethods['bbmchannel'] );	

 if ( isset( $contactmethods['bbwvendor'] ) )
    unset( $contactmethods['bbwvendor'] );
//Add user contact methods
  if ( !isset( $contactmethods['bbwvendor'] ) )
    $contactmethods['bbwvendor'] = __('BlackBerry World Vendor ID (ie. 12345)'); 

  if ( !isset( $contactmethods['abap_avatar'] ) )
    $contactmethods['abap_avatar'] = __('Custom Avatar Image URL');

Fetching the input values for the user

$abap_bbmchannel_id = get_the_author_meta( 'bbmchannel' );
$abap_bbwvendor_id = get_the_author_meta( 'bbwvendor' );

Creating the output display for the values

if($abap_bbmchannel_id){
	if($isNext) {
		$abap_bbmchannel_id='&nbsp;&#8226;&nbsp;<a  rel="me nofollow" href="http://www.pin.bbm.com/' . $abap_bbmchannel_id . '" target="_blank">BBM Channel</a>';
	} else {
		$isNext = true;
		$abap_bbmchannel_id='<a  rel="me nofollow" href="http://www.pin.bbm.com/' . $abap_bbmchannel_id . '" target="_blank">BBM Channel</a>';
	}
	
} else {
	$abap_bbmchannel_id='';
}	

if($abap_bbwvendor_id){
	if($isNext) {
		$abap_bbwvendor_id='&nbsp;&#8226;&nbsp;<a  rel="me nofollow" href="http://appworld.blackberry.com/webstore/vendor/' . $abap_bbwvendor_id . '" target="_blank">BlackBerry World Vendor Apps</a>';
	} else {
		$isNext = true;
		$abap_bbwvendor_id='<a  rel="me nofollow" href="http://appworld.blackberry.com/webstore/vendor/' . $abap_bbwvendor_id . '" target="_blank">BlackBerry World Vendor Apps</a>';
	}
	
} else {
	$abap_bbwvendor_id='';
}	

And then adding those output display values to the content values that is returned and displayed.

$content.= ($author_box.$abap_email_info.$abap_skype_url.$abap_facebook_url.$abap_twitter_url.$abap_linkedin_url.$abap_google_url.$abap_youtube_url.$abap_flickr_url.$abap_pinterest_url.$abap_instagram_url.$abap_quora_url.$abap_bbwvendor_id.$abap_bbmchannel_id.'</p></div>');

I sent the full code change to the plug-in author in hopes that he would include my new fields as a thank you for fixing a bug in his plug-in. Obviously, if he doesn’t keep the fields and updates the plug-in, then I will have to edit the plug-in file again to add my code. Having that flexibility is one of the nice things of WordPress.

If I am still using this plug-in, from now and into the future, you should see the results below.

About DeanLogic
Dean has been playing around with programming ever since his family got an IBM PC back in the early 80's. Things have changed since BASICA and Dean has dabbled in HTML, JavaScript, Action Script, Flex, Flash, PHP, C#, C++, J2ME and SQL. On this site Dean likes to share his adventures in coding. And since programming isn't enough of a time killer, Dean has also picked up the hobby of short film creation.

About DeanLogic

Dean has been playing around with programming ever since his family got an IBM PC back in the early 80's. Things have changed since BASICA and Dean has dabbled in HTML, JavaScript, Action Script, Flex, Flash, PHP, C#, C++, J2ME and SQL. On this site Dean likes to share his adventures in coding. And since programming isn't enough of a time killer, Dean has also picked up the hobby of short film creation.

Leave a Reply

Your email address will not be published. Required fields are marked *

*