Category Archives: WordPress

25+ Must-Have Cheat Sheets for Web Developers

Who wants to go to Google or break out the library of programming books every single time you get stuck on something? Below is a compilation of extremely useful cheat sheets, which can be printed, laminated and placed nearby for easy reference while doing your web development and design. Everyone has moments where a function cannot be remembered, and that is where these cheat sheets can be lifesavers. Bookmark this page for an easy portal to all of the cheat sheets, or an individual page if you find it helpful. Please don’t hesitate to post any cheat sheets we neglected to include, for this is about sharing knowledge.

1. PHP

PHP Cheat Sheet Continue reading 25+ Must-Have Cheat Sheets for Web Developers

eAccelerator reduces WordPress memory usage

In my quest to minimize the memory usage of our beloved blogging platform, WordPress, I came across eAccelerator.  After using Zend Server, and experiencing the performance boost their caching mechanism created, I started looking for something that would work easily with cPanel/WHM.  Lo and behold, there exists a program called eAccelerator which is quoted as being “a free open source PHP accelerator, optimizer, and dynamic content cache.”

eAccelerator in EasyApache
eAccelerator in EasyApache (Go to WHM > Click EasyApache under Software > Choose eAccelerator in the Short or Exhaustive Options screen)

Immediately, I saw the average WordPress memory usage go from 14MB to less than 8MB.  That is roughly 57% percent of the original memory usage.  Needless to say, I was quite pleased with the results!

Thoughts: In other languages, such as C# and Java, one has the ability to introduce libraries as needed without the extra burden of loading every last file, like in WordPress.  Would it be possible to come up with a custom autoload function to do the same sort of thing?  I believe Joomla uses a similar idea with the jimport() function.

WordPress: Zend Server CE vs. cPanel & Apache stacks

I recently decided to install Zend Server CE on my machine to use as a local development environment.  I chose the PHP 5.3 installation so I could update my PHP code to fit the new version.  I was intrigued and excited to find that WordPress used a mere 2 MB of memory compared with 12-13 MB on my production installation.

Zend Server CE cPanel/Other Stacks
Memory usage 1.5-2 MB 12-14 MB
OS Windows XP
Windows Server 2003
Windows XP
Windows Server 2003
Installation PHP 5.2.10/5.3
Apache 2.2.12
PHP 5.2.10
Apache 2.2.xx
WordPress Version 2.8.4 2.8.4
WordPress Plugins Same Same

My primary testing was done on Windows Server 2003. Before installing Zend Server CE, WordPress was taking up what I would call an average amount of memory, 12 MB. After installing Zend Server CE with PHP 5.2.10, I found that peak memory usage went down to around 4 MB. After I found PHP 5.2.10 worked, I upgraded to 5.3, which resulted in yet another performance increase, bringing us to 2 MB peak memory usage.

WordPress Memory Usage on Zend Server CE
WordPress Memory Usage on Zend Server CE
WordPress Memory Usage on cPanel/WHM
WordPress Memory Usage on cPanel/WHM

Thoughts: I can’t find anything drastically different about the two installations, but I could be missing something. If anyone can solve this mystery, please comment!

How to do Ajax calls within the WordPress administration panels

To complete a simple Ajax call within the administration panels, we will need a minimum of three functions. Here are the functions used in the sample code:

  • _wp_display_content() — responsible for displaying the form or content, and the nonce field.
  • _wp_display_content_js() — displays the JavaScript code for our Ajax call in the footer.
  • _wp_sample_ajax_call() — completes security check for the Ajax request, processes the request, and returns a response.

Continue reading How to do Ajax calls within the WordPress administration panels

TPC! Memory Usage released!

The very first version of TPC! Memory Usage has been released to the public, and we received WordPress approval to be placed in the plugin directory.  TPC! Memory Usage allows WordPress administrators to track current and peak memory usage.  It’s an extremely useful tool that can help any admin, especially those who use plugins, language files, and other modifications.

The WordPress $wpdb class explained

The WordPress MySQL database class is quite powerful.  This database class can be used for other projects with some very simple modifications, and is actually based on/borrowed from another project called ezSQL by Justin Vincent.

The WordPress database class code is located in <WordPress root>/wp-includes/wp-db.php.  The $wpdb object is created at the very bottom using the following lines of code (comments removed):

if ( ! isset($wpdb) ) {
	$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

Below, I listed a few of the main functions in the $wpdb object.  These functions will help make your job easier when creating plugins and extending the WordPress core, or even working on a completely different project.  I did not include functions used for debugging/error reporting, as that could easily be its own lesson.

  • set_prefix($prefix) — used to set table prefix for WordPress tables, can be used to override prefix at any time.
  • prepare($query) — safely prepares an SQL query for execution with sprintf()-like syntax.
  • query($query) — perform a MySQL database query with current connection
  • insert($table, $data, $format) — insert a row into a table via arrays.
  • update($table, $data, $where, $format, $where_format) — update a row in a table via arrays.
  • get_var($query, $x, $y) — retrieve a single variable from the database.
  • get_row($query, $output, $y) — retrieve a single row from the database.
  • get_col($query, $x) — retrieve a single column from the database in array format.
  • get_results($query, $output) — retrieve SQL result set from database… one or more rows.
 * Insert a new option into the $wpdb->options table.
 * @uses $wpdb WordPress Database Object
$wpdb->insert( $wpdb->options, array('option_name', 'new_option_key', 'option_value' => 'New Option Value', 'autoload' => 'yes') );

 * Update an existing option in the $wpdb->options table.
 * @uses $wpdb
$wpdb->update( $wpdb->options, array('option_value' => 'Newer Option Value'), array('option_name' => 'new_option_value') );

 * Get a single post_id from the $wpdb->postmeta database.
 * The $wpdb->prepare() function ensures that the query is
 * safe for use in the database.  The %d refers to an integer
 * and is replaced by $post_ID in a way that makes it query-safe.
 * The %s refers to a string and is also escaped.
 * @uses $wpdb
$post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '&') );

 * Delete a record from the $wpdb->options database.
 * @uses $wpdb
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'");

Feel free to leave comments and ideas on what could make this tutorial better or clearer.

Optimize your WordPress 2.8.4 installation

Large traffic spikes can put an enormous amount of strain on the typical web server, especially low-level hosting plans.  These often occur after appearing on the front page of a social media site (Digg).  While WordPress is well-equipped and can handle these requests, it was designed to be a quick easy install, and is not fully optimized out-of-the-box.  WordPress can be used for high traffic sites, but some features should be implemented to keep your web server running smoothly, and also as a precautionary measure for smaller sites.

Use WP Minify

WP Minify will consolidate and minify and compress JS and CSS files, reducing the number of HTTP requests and decreasing the overall size of the downloaded file.

Use WP Super Cache

WP Super Cache generates static HTML files based on your blog/site content and serves that instead of processing the PHP scripts each time someone visits the site.  This drastically speeds up most WordPress installations.

Remove unnecessary database queries

Themes are built so that they can be applied to mostly any WordPress installation, though chances are you will initially set the title and description and leave them the same.  A typical theme will contain the following lines of code within the header.php file:

<title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

The aforementioned bloginfo() functions can be replaced with static values, which will prevent the overhead from PHP and any additional database queries. For example, bloginfo(‘name’) could be replaced with My Blog Name. You’ll want to check the other theme files too.

Use Google FeedBurner

Using Google’s feed service will help reduce the load on your server.  It basically works like this:

  1. User visits your feed URL.
  2. User is redirected to the Google feed URL by the WordPress FeedBurner plugin.
  3. Content is served from their servers instead of yours.
  4. …also has the added bonus of including MANY other features, including e-mail subscriptions, formatting for every major RSS platform, pinging, etc.

Install and use Google Gears

WordPress comes with Google Gears support, an application that allows files to be stored locally. Google Gears is integrated with newer versions of Google Chrome, Mozilla Firefox, and Internet Explorer.  While this won’t speed up the front-end of the site, it will reduce the number of HTTP requests on the back-end, drastically speeding up the administration panels, and indirectly helping to reduce the overall load on the server.

Remember, WordPress uses their own software on to serve content to over 170,000 bloggers and many, many more visitors.  This is proof that WordPress works at the enterprise level, although they have very advanced servers and configurations in order to achieve this.  While the average person does not have a need for that sort of environment, some tweaking should still be done to keep server loads down, and keep our carbon footprint at a minimum.