Categories
Wordpress Development

How to Enable Multisite in WordPress 3

One of the most touted new features in WordPress 3 is the integration of WordPress MU into the main branch of WordPress.  What this allows you to do is run multiple WordPress sites or blogs, while only needing one install.  The only issue is that this functionality is not enabled by default.

To enable multisite in WordPress 3, you need to add the following line somewhere in wp-config.php. [Note:  Make sure you disable all of your plugins first.] 

define('WP_ALLOW_MULTISITE', true);

After you set WP_ALLOW_MULTISITE to true, you’ll get a new menu item called “Network” under the tools menu.


From there, you can experiment setting up new sites.

Categories
PHP Programming

Validate Email Addresses With PHP

If you’re a web programmer, there will come a time when you need to validate an email address. It’s going to happen, so just accept it. In newer versions of PHP, there is built in functionality for this. However, for those of us not lucky enough to be running the latest and greatest version, we can use regular expressions.

The following PHP function will validate email addresses using regular expressions. True is returned on success, and false is returned otherwise.

1
2
3
function validate_email($email) {
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email);
}
Categories
PHP Programming

PHP Validate Email

Every so often (ok, a lot more than that), you need to validate an email address. The obvious solution is to use regular expressions, however PHP provides a better method using the filter_var() function.

To validate an email address using PHP, simply do the following:

1
2
3
4
5
6
$email = "jack@re-cycledair.wploadtest.xyz";
if(filter_var($email, FILTER_VALIDATE_EMAIL) == TRUE) {
     echo "Valid Email.";
} else {
     echo "Email is not valid.";
}

Note: This only works for PHP >= 5.2

Categories
PHP Programming

PHP Function Of The Day: ob_end_clean()

Sometimes you get in to a situation where you are working in an environment that drops everything into an output buffer before it spits it out the browser. In most languages this is called “output buffering”. The problem with having EVERYTHING buffered is being able to do special stuff like dynamic XML documents.

My solution to this little pickle was to just drop everything from the current output buffer and then kill the process after I’m done with it. To do this, just execute “ob_end_clean()” right before the functions/objects/code you need to execute. What “ob_end_clean()” does is drops all information that is currently stored in the output buffer, and then stops the buffering anything after it.

One “gotch ya” moment I had using this function was that it doesn’t end ALL cases of output buffering. If for some strange reason there is nested buffering going on, you’ll need to call the function as many times as it takes to get to the top of the call stack.

http://us2.php.net/manual/en/function.ob-end-clean.php

Categories
PHP Programming

Converting MySQL dateTime to RFC-822 (RSS pubDate) in PHP

I had the need to convert a MySQL datetime time stamp into a format accepted by the RSS 2.0 specification. To get the first part, you can do a SQL query like the following:

1
SELECT DATE_FORMAT(dateTimeColumn, '%a, %d %b %Y %T') AS rssPubDate FROM yourTable

After that, you need to get the timezone, which can be accomplished by using this:

1
$timeZone = date('T');

So lets say you store the rssPubDate from MySQL in a variable called $rssPubDate, all you need to do is $rssPubDate .= ” {$timeZone}”;

That’s it! You now have a RFC-822 compliant time stamp.

Categories
PHP Programming

Showing All Errors in PHP

When I was first starting to create web sites with PHP, I struggled with getting error reporting turned on.  Turns out, that you can have it enable at the server, or in the document, or in both.  For development, it’s probably a good idea to have this at the top of script:

error_reporting(E_ALL);
ini_set('display_errors', '1');

This will allow php to display all errors, notices, and warnings.  Simple things like developing with error reporting full on like this help prevent security breaches and unknown application behavior.

Categories
PHP Programming

PHP Type Evaluation

Aside from grad school drama, I learned something new the other day about PHP.  In PHP, there are two ways to look for equality: “==” and “===”.

$a = “1”;
$b = 1;
if($a == $b) { echo “True”; } else { echo “False”; }
if($a === $b) { echo “True”; } else { echo “False”; }

The first if statement would evaluate to true because it only evaluates the value.  The second if statement would evaluate to false, because it evaluates both value AND type.

Categories
Other Other Programming

Epiphany of Development

I’ve been doing web development for a long time.  I made my first (crappy) web page in 6th grade using the then awesome Geocities.  After that, I graduated to Front Page express.  Throughout my development career, I’ve had a series of epiphanies that have brought my skills to the next level.  Bold entries are where they happened.

  • 1998 – First web page – I knew that the internet existed, but it never dawned on me to actually create content.  I didn’t realize it at the time, but this simple act has been the anchor for the rest of my life.
  • 1999 – Discover Front Page (Express) – With my new found web skills, I started to use more advanced WYSIWYG editors.  Frontpage is hardly advanced, but it allowed me to separate my menus from my content using frames.  It opened up numerous paths for me to take.
  • 1999 (late) – Dreamweaver – Not super important, but discovering Macromedia Dreamweaver really changed how I did web pages.  I stopped using frames to make menus and started using layers.  Little did I know that layers were actually “<div>” tags that were positioned by CSS.
  • 2000 – Flash – Flash was still rather immature at this point, however it showed me what could truely be accomplished on the web.  No longer did menus have to be boring images and text links.  We could have tweening!  It was around this time that I build my first web page with heavy flash components.
  • 2001 – Discover PHP, HTMl, and CSS – This was a big year for me.  I discovered PHP, HTML, and CSS all at the same time.  I had no idea how any of these worked though.  At the time, PHP was well beyond my grasp.  CSS and HTML seemed do-able though.
  • 2003 – HTML + CSS  Zen – I was a junior in high school at this point, and had been appointed to wor on the school’s web site.  Actually, it was the entire district’s domain.  My brain had matured enough for me to make a web site BY HAND using nothing more than HTML and CSS.  I still didn’t understand programming, but using markup languages like HTML and CSS because second nature to me.
  • 2004 – Servers – Around this time I discovered that I could make servers on my own!  Not really code them persay, but rather run server software.  I’m pretty sure my first server was an FTP server so that I could share files with my friends.  It was tedious though, since I was still using 56k dial-up at the time.
  • 2005 (Early) – First Computer Science Course – The biggest eye opener ever.  I never realized how deep the rabbit hole went.  I was only learning assignmen, logic, loops and a few other things, but it made my thirst for knowledge inquentiable.  I started to learn C++ here.
  • 2005 (Late) – Assembly Language & C – Taking a course in SPARC assembly and a bit of C is an eye opener for every Computer Science student.  You’re pretty much at the bottom of the rabbit hole, and you spend the rest of your career climbing back out.  Coding in low level languages made me a much better programmer though, because it forced me to think.
  • 2006-2007 – School & Languages – These years were spent diving into new languages, learning new programming styles and domains, and generally having a good time.  I didn’t spend a lot of time doing web development, but I did teach myself how to make a web server in Python.  Not especially helpful, but still fun.
  • 2008 – PHP, MySQL, LAMP – I had already learned Linux in 2006-2007, however I never really dove into Linux as a server.  That was at least, until I found out (again) about PHP.  Turns out PHP needed Apache to run.  And all the fun PHP stuff also needed a database server  (MySQL).  I set up a PHP + Apache + MySQL server and went from there.  It was at this time that I started development on the first edition of Wrestling Addix.  I made my own CMS for it (bad idea) and in general the site worked fine, however it was a bear to maintain.  I decided that the next version would use a pre-built CMS so that my life would be easier.
  • 2009 – Ajax, WordPress, OOP, CMS – This year I’ve learned lots of stuff.  Most of it revolved around web development though.  I’ve learned to bend WordPress to my will (it runs this site).  I’ve learned how to use Ajax to make my web apps for responsive.  I’ve learned how to use Object Oriented Programming in my web sites, and how using a CMS WILL make your life easier.