Sticky Items & Upcoming Tampa Wordpress Events

Feb 08 2012

Tampa WordPress Meetup – Security Measures & Good Practices

Posted by: Jason Ferguson

That’s right folks, it’s that time of the month again. Tonight the fine folks of Tampa Bay have a WordPress Meetup to attend. This month we should have around 33 members attending (give or take).

Location:
CDB’s Southside
3671 S. Westshore Blvd., Tampa, FL

Summary:
Trish, a member of our group will be discussing what she has learned about php security and WordPress. Jason Ferguson will also be chiming in to append about third party themes and plugins. Discussions are encouraged as security is a very important aspect of running a website.

 
Jan 30 2012

How to Reposition the WordPress “More” Tag

Posted by: Jason Ferguson

I came across a situation today where I wanted to show different links based on whether or not the <!–more–> was present in a WordPress Post. By default WordPress will automatically append something similar to “more…” directly after your posts content. WordPress presents multiple options for changing the more tag text1 , even as simply as just defining the text inline with the existing tag:
(e.g: <!–more Click here for more Information –>).

But what if you don’t want this appended directly to the end of your post, maybe you want to display this somewhere else on your posts page. In my case, I wanted to add a little more logic and display different options based on if the more tag actually existed in the post or not. If it did exist, I wanted to show a button link saying something along the generic lines of “Read the Full Post”, and if no more tag was in use I simply wanted to show a different button link saying “Permalink”. Here’s a simple modification that will let us pull this off.

First, find in your theme where you are currently outputting the_content(); (or get_the_content();). This would usually be in index.php, home.php, loops.php, or somewhere similar depending on the actual theme you are using. Change this line to read:

echo the_content('');

Take note of the apostrophe’s (), this is telling WordPress NOT to output the default more text along with the post content. Then, wherever we want to actually show our custom read more, we would do something like this:

	<?php if ($pos=strpos($post->post_content, '<!--more-->')): ?>
		<a href="<?php the_permalink() ?>#more-<?php the_id() ?>" class="button"><span>READ FULL POST</span></a>
	<?php else : ?>
		<a href="<?php the_permalink() ?>" class="button"><span>PERMALINK</span></a>
	<?php endif; ?>

What we are doing here is looking through the content of post_content using strpos2 to see if the default more tag exists within the post. If it does, we take action and show our custom Read More button. If the tag does NOT exist, we are going to simply display a similar output with different text, indicating that specific post is already being showed in its entirety and proving a Permalink button. They both lead to the same place, the only thing changing is the indicator for that post.

  1. WordPress Codex : Customizing_the_Read_More []
  2. PHP.net: strpos []
 
Jun 08 2011

Tampa WordPress Meetup 6/8/11

Posted by: Jason Ferguson

Alison Foxall, sent the following message to some members of TampaBay WordPress:

This meeting snuck up on us! So this month do some homework and come prepared to talk about a useful plugin for your site or blog or a plugin that you thought was really “cool.” We’ll all take part in this discussion and enjoy some Italian food while we’re at it.

These are the plugins I generally find myself using on various sites time and time again, most of them are pretty common, but users new to wordpress may not know of them and find them pretty handy. I only included the plugins gauranteed to work with the most current version of wordpress, there are a few other plugins I love, but haven’t confirmed they are all stable with the latest version yet.

Feb 17 2011

Not yet possible to assign complex types to properties.

Posted by: Jason Ferguson

Came across something new (for me anyway) today. I was using PHP5′s SimpleXML functions to grab youtube video data so I could make automatic posts (and attach youtube comments) in wordpress based off a video’s ID. At some point I was passing what I thought was a variable into an array that was then later being manipulated by a native wordpress function during the comment post processing. While the code itself was actually working and attaching the comments to the posts, I was getting a weird error on each insert that was warning me about assigning complex types to properties, something I had never seen before.

A stackoverflow post on Forcing a SimpleXML Object to a String was the guiding light I needed.

The Error

Warning: It is not yet possible to assign complex types to properties in wp-includes\formatting.php on line 1234

The Solution

Typecast the object as a string before attempting to manipulate it.

$foo = array( (string) $xml->channel->item->title );

 
Dec 13 2010

Web Developer Toolbar wont Display – Firefox Fix

Posted by: Jason Ferguson

Today I was working on a cleaning up some CSS when suddenly a plugin I use for Firefox, Web Developer Toolbar, suddenly disappeared. I found a couple older posts with people having a similar problem, but then I stumbled across voodish.co.uk1 and it seemed to do the trick for me.

The Problem

Firefox Web Developer Toolbar addon is not showing icons or text, or both.

The Solution

A very very easy solution, as long as your Firefox toolbar positioning isn’t extremely customized. A few quick steps and you will be able to display the toolbar again.

  1. Right-click on the Toolbar and choose ‘Customize’
  2. Click ‘Restore Default Set‘ or Drag any missing buttons from the ‘Customize Toolbar’ window to the toolbar.
  3. Click ‘Done.’

And that’s it, make sure Icons and Text are selected from the drop down menu if you require both and your all set.

  1. source: Web Developer Toolbar Broken / Empty / not showing, Fixed []
 
Aug 20 2010

Code Poetry Redeux, Ryans Response

Posted by: Jason Ferguson

As usual, ryan wins this round.

<?php
//jackandjill.php
$kidsnames = $_SERVER['PHP_SELF'];
$kidsnames = basename($kidsnames, ".php");
$firstkid = substr($kidsnames,0,4);
$joinword = substr($kidsnames,4,3);
$secondkid = substr($kidsnames,7,4);
$kidsnames = $firstkid . " " . $joinword . " " . $secondkid;
function makewherecode($whereto){
if($whereto == "halibel"){
$newplace = substr($whereto,0,1);
$newplace = $newplace . substr($whereto,3,1);
$newplace = $newplace . substr($whereto,2,1);
$newplace = $newplace . substr($whereto,2,1);
return $newplace . "\n";
}
}
function hextostr($hex)
{
    $string='';
    for ($i=0; $i < strlen($hex)-1; $i+=2)
    {
        $string .= chr(hexdec($hex[$i].$hex[$i+1]));
    }
    return $string;
}
$rhyme =  nl2br($kidsnames . " went &uarr; a " . makewherecode("halibel"));
$getting = array("pail","water");
$line = "to fetch a " . $getting[0] . " of " . $getting[1];
$rhyme = $rhyme . $line . "<br>";
$line = $firstkid . " fell &darr; <br>";
$rhyme = $rhyme . $line;
$brokewhat = "63726f776e";
if (hextostr($brokewhat) == "crown"){
$line = $joinword . " broke his " . hextostr($brokewhat);
}
$rhyme = $rhyme . $line . hextostr("3c62723e");
$line = $joinword . " " . $secondkid . " came tumbling after.";
$rhyme = $rhyme . $line;
echo $rhyme;
?>
 
Aug 19 2010

Code is Poetry example? Ryan is Challenged!

Posted by: Jason Ferguson

The gauntlet has been dropped, Ryan has been challenged!

<?php
//im-a-little-teapot.php
$whatami = $_SERVER['PHP_SELF'];
$whatami = basename($whatami);
$whatami = basename($whatami, '.php');
$im = str_replace("-", " ", $whatami);
function what_do_i_do($var, $poem) {
	if (strripos($var, "teapot")) {
		return nl2br($mypoem = $poem . "when i get all worked up");
	}
}
$im != "im a little teapot" ? die : $mypoem = $im . "\n short and stout\n"; $teapot = "me";
$container = array("handle", "spout");
foreach ($container as $part) {
	$mypoem = $mypoem . "here is my " . $part . "\n";
}
echo what_do_i_do($im, $mypoem);
if (empty($error)) {
	trigger_error("YOU BETTER WATCH OUT!", E_USER_WARNING);
	$mypoem = "TOOOOOOT! \n";
}
echo nl2br($mypoem . "tip " . $teapot . " over and pour " . $teapot . " out");
?>
 
Aug 15 2010

Tumblr Style Chat Posts for WordPress

Posted by: Jason Ferguson

The problem with Tumblr, for me anyway, is the loss of direct control over the code and ability to host my submissions locally. I know tumblr has been around for a while and it doesn’t look like it’s going anywhere, but anyone who has been on the net for a while knows that just because a site is here today, that doesn’t mean it will still be here tomorrow. Tumblr doesn’t have an export option, so needless to say I’m a little wary about posting anything I might want to be able to look at or back reference a few years from now. Does anyone remember scribble.nu, run by Dustin Vannatter1 of the then OHHELLO network (Swank Army!). It was one of the first blogging platforms, before blog’s were even called blog’s and they were still just called journals. For a time everyone who was anyone had a scribble.nu journal running inline with their current site. The same goes for sites like MODblog2, from Mike Pacific and Gorman of DeskMOD3 fame. I’m sure everyone has sites they have used at one time that just couldn’t handle the traffic or for one reason or another just died a unfortunate death.

I’ve have been toying around with Tumblr a little bit recently though and I am enjoying how it automatically handles different types of content and formats it without any thought on my part. Right now this is something that is still lacking in WordPress, which I touched base in a round-about way on my last post.4

Tumblr makes it incredibly easy to post different types of submissions and have them styled automatically without any per-entry coding, not forcing us to remember which posts require what custom fields like we have to do in WordPress. I had thought WordPress 3.0 was going to help solve some of these problems by introducing Custom Post Types, but unfortunately it’s still not quiet there yet and Custom Post Types aren’t quiet what some of us expected them to be (although the new functions are extremely useful if you use them in the way they were designed for).

So, as part of a larger project I have been working on, here is a quick and easy way to implement tumblr-esque “chat” posts into your site. The following code will take any content between the [chat] and [/chat] shortcodes, automatically format it and apply a specific style. Currently it sorts anything that matches into relevant DL and DT html tags, and applies a highlight class to every other row. So very quickly I can turn this:

Fight Club (1999)
Narrator: You’re making a big mistake, fellas!
Police Officer: You said you would say that.
Narrator: I’m not Tyler Durden!
Police Officer: You told us you’d say that, too.
Narrator: All right then, I’m Tyler Durden. Listen to me, I’m giving you a direct order. We’re aborting this mission right now.
Police Officer: You said you would definitely say that.

Into something a little prettier, like this:

Fight Club (1999)

Narrator:
You’re making a big mistake, fellas!
Police Officer:
You said you would say that.
Narrator:
I’m not Tyler Durden!
Police Officer:
You told us you’d say that, too.
Narrator:
All right then, I’m Tyler Durden. Listen to me, I’m giving you a direct order. We’re aborting this mission right now.
Police Officer:
You said you would definitely say that.
function tumblr_chat_post_shortcode($atts, $content=null) {
$chatoutput = "<dl class=\"chat-transcript\">\n";
$split = preg_split("/(\r?\n)+|(<br\s*\/?>\s*)+/", $content);
	foreach($split as $haystack) {
		if (strpos($haystack, ":")) {
			$string = explode(":", trim($haystack), 2);
			$who = strip_tags(trim($string[0]));
			$what = strip_tags(trim($string[1]));
			$row_class = empty($row_class)? " class=\"chat-highlight\"" : "";
			$chatoutput = $chatoutput . "<dt$row_class><strong>$who:</strong></dt> <dd>$what</dd>\n";
		}
		else {
			// the string didn't contain a needle. Displaying anyway in case theres anything additional you want to add within the transcript
			$chatoutput = $chatoutput . $haystack . "\n";
		}
	}
// print our new formated chat post
$content = $chatoutput . "</dl>\n";
return $content;
}
add_shortcode("chat", "tumblr_chat_post_shortcode");

If shortcodes just aren’t your style and you want something to work on posts transparently, that’s not very difficult either. All we have to do is create a new category (in this example we are using “chats”), and the code posted below will automatically process and format any submissions. Using the built in add_filter functions wordpress provides, it’s easy to modify content before it gets displayed to the browser, allowing us a way to format posts differently based on the category they are in.

function tumblr_chat_post($content) {
global $post;
	//$content = $post->post_content;
	if ($post->post_type == 'post') {
		$postcats = wp_get_object_terms($post->ID, 'category');
		foreach ($postcats as $mycat) {
			if ($mycat->name == "chats") {
			remove_filter ('the_content',  'wpautop');
				$chatoutput = "<dl class=\"chat-transcript\">\n";
				$split = preg_split("/(\r?\n)+|(<br\s*\/?>\s*)+/", $content);
					foreach($split as $haystack) {
						if (strpos($haystack, ":")) {
							$string = explode(":", trim($haystack), 2);
							//list($who, $what) = explode(":", $haystack, 2);
							$who = strip_tags(trim($string[0]));
							$what = strip_tags(trim($string[1]));
							$row_class = empty($row_class)? " class=\"chat-highlight\"" : "";
							$chatoutput = $chatoutput . "<dt$row_class><strong>$who:</strong></dt> <dd>$what</dd>\n";
						}
						else {
						// the string didn't contain a needle. Displaying anyway in case theres anything additional you want to add within the transcript
							$chatoutput = $chatoutput . $haystack . "\n";
						}
					}
					// print our new formated chat post
					$content = $chatoutput . "</dl>\n";
					return $content;
			}
			else {
			add_filter ('the_content',  'wpautop');
			// I don't exist in the defined category, so no processing is needed
			return $content;
			}
		}
	}
	else {

		// I'm not a regular post, so no processing is needed.
		return $content;
	}
}
add_filter( "the_content", "tumblr_chat_post", 9);

Either of these functions can be placed in your themes function.php file and will work automatically as long as your chat transcripts are formatted in a Name: Message structure. This is a fairly simple example on how to use wordpress hooks and shortcodes to modify your post before it gets outputted to the browser, which provides us with some interesting ways to implement specific styled post types without hacking apart the “Custom Post Type” functions WordPress released with version 3.0, something that is just not suited very well or meant for for these type of tasks.

  1. Dustin.Vannater.com : Things I’ve Done []
  2. Interview of Mike Pacific from DeskMOD.com []
  3. Stamford Advocate: Danbury man manages Web Site from his bedroom []
  4. The Problem with WordPress Custom Post Types []
 
Aug 12 2010

The Problem with WordPress Custom Post Types

Posted by: Jason Ferguson

Xzibit Moddin My WordPress!

A lot of “names” in wordpress on the net are politely bashing people because they are trying to use Custom Post Types in the wrong way, but really in my (and clearly a lot of other users) opinions, what they are trying to do is what should be defaultly working in the first place.

Custom post types should be exactly that, custom post types. It should give me the ability to define a custom submission area with specific meta content completely separated from the normal “Submit New Post” area. If you have ever built something for a client, and not just for personal use, you would see how extremely useful this would be. But what we have now with this new feature isn’t custom “post” types like it’s named, it’s actually custom “content” types.

Right now we are stuck with using custom fields and trying to explain to clients in explicitly detailed instructions how to properly define key pairs for specific post types that all still need to be displayed inline with the regular “blog”. Why is it so hard for people to understand that being able to use custom post types as an ability to specifically define certain REAL post submission meta boxes and separate them out in the dashboard is a useful thing.

Aug 09 2010

Transparent PNG background turns into a Gradient in IE8 – Fixed

Posted by: Jason Ferguson

While cross checking between Firefox and IE8 I came across an odd bug on a site I was working on. Whenever I tried to apply Internet Explorers gimped css opacity settings to a block level element that was wrapped by another div with a Alpha Transparent PNG background, the container background would gradient/fadeout from left to right, rather than displaying the alpha transparent png in it’s normal state. For example:

PNG Trasparency shows correctly in Firefox

PNG Trasparency shows correctly in Firefox

Alpha Transparent PNG shows as Gradient in IE8

Alpha Transparent PNG shows as Gradient in IE8