Using WordPress core externally

Using WordPress Core externally can be quite useful when wanting to utilize WordPress functions from within another project/app. I’m setting up a cron job at server level, but I wanted to be able to leverage WordPress functionality. Because of how WP Cron works (initiated on page load, not time), I wanted to separate my cron process from the WordPress installation.

After a little digging around, I found this thread on StackExchange. It explains the setting up how to access WordPress core externally.

The following code will allow you to use all WordPress Core functionality!

<?php // All that is required to bootstrap into WordPress.
require('../wordpress/wp-load.php');

Test it

if( function_exists( 'update_option' ) )
echo 'We have WordPress support';
else
echo 'no WordPress support';

Use WordPress core externally!

Now that you have access to WordPress core functionality, the limit is the sky! (or at least the latest version of WordPress).

Determine if you are on the Static Posts page in WordPress

When using the Static Home Page option (and thus Static Home Page ) in WordPress, there are ways to check whether you are on the home static page, or the designated posts page.

Static Front Page

// If the current page is the blog posts index,
// but is NOT the site front page
if ( is_home() && is_front_page() ) {
    // do something
}

Continue reading Determine if you are on the Static Posts page in WordPress

Reading $_GET values from a URL String in PHP

Reading $_GET values from a URL String in PHP was something I had been interested in for a while. It was quite simple to read the $_GET values from the current page’s URL (obviously), but what if you were using AJAX and passing a URL to figure out what data needed to be passed/used? There’s several other reasons why you may need this, but I digress.

While looking for a way to read $_GET variables from a string in PHP, I stumbled across this forum post on Stack Exchange.

parse_str( parse_url( $url, PHP_URL_QUERY ), $array );

Continue reading Reading $_GET values from a URL String in PHP

Securely Renaming a Massive Amount of Files with PHP – Part 3

Part One: Reading a folder structure recursively.
Part Two: Renaming the files (uniquely) and storing new and old file paths.
Part Three: Copy the files into a sequenced folder system.

This is the third and final part of my tutorial regarding renaming and copying files with new secure names. In the first two sections we covered:
Continue reading Securely Renaming a Massive Amount of Files with PHP – Part 3

Securely Renaming a Massive Amount of Files with PHP – Part 2

Part One: Reading a folder structure recursively.
Part Two: Renaming the files (uniquely) and storing new and old file paths.
Part Three: Copy the files into a sequenced folder system.

This tutorial is a continuation of Securely Renaming a Massive Amount of Files with PHP. In Part 1, we covered:
Continue reading Securely Renaming a Massive Amount of Files with PHP – Part 2

Securely Renaming a Massive Amount of Files with PHP – The Non-Destructive Route

A recent project scope included renaming (literally) tens of thousands of documents for security purposes – it’s not too secure having files name “November-2011-Finances.doc” hosted online.

This tutorial will explain how to use PHP locally (without a web server like XXAMP, MAMP, or WAMP). Using one of these 3 services is fine, but we decided to go the system route!

I will break this tutorial down into multiple parts:
Continue reading Securely Renaming a Massive Amount of Files with PHP – The Non-Destructive Route

Form Validation in PHP – Simplified

I was created a form earlier today, when I had to add Phone Number validation to the existing validation. This form already included email validation, but I decided to go over it as well.

Email Validation

This is a very similar validation, but there is nothing needed to customize:

function valid_email( $str )
{
    // This checks for "[email protected]"
    return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}

if( ! valid_email( $_POST['email_address'] ) {
    echo "Please enter a valid email address."
}

Phone Number Validation

Edit: Please check out my new post on phone number validation, as it has a much more efficient regular expression pattern.

Phone Number validation is fairly straight forward, but has one major issue – formatting! There are many ways of putting in a phone number, and for usability’s sake, it’s best to supp
Continue reading Form Validation in PHP – Simplified