When performing a search on the Codex, you’re presented with a slew of search results. However, not all of those results are within the Codex. The search portion of the Codex is powered by a Google custom search box which not only presents results from within the Codex, but from across WordPress.org as well, mainly the support forum.
While performing a search for Conditional Statements, the first result was the one I was looking for. However, if you want the results to strictly be within the Codex, I came across this link shared by Otto on the Documentation mailing list. While giving this method of searching the Codex a try, I found it difficult to find the Conditional Statements page I was looking for that was easily displayed by the Google Custom Search box. Even by checking each box, I failed at finding the page using both Conditional Statements and Conditional as my search terms.
My advice, stick to using the Search box that exists on the Codex page.
WordPress uses memory. Plugins and themes use memory. New versions of software may use more memory than before. When that happens and PHP on your server doesn’t have enough memory then PHP will stop with a fatal error like this:
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1203208 bytes) in /home/*****/public_html/wp-admin/includes/class-pclzip.php on line 4215
This happens quite a bit but it’s not a bug in WordPress or your new plugin or theme, you simply need to let PHP use more memory on your server. Thankfully WordPress makes it easy to do this. You must define a constant, WP_MEMORY_LIMIT in your server’s wp-config.php like this:
define(‘WP_MEMORY_LIMIT’, ’128M’);
The error message will give you an idea of how much memory is required. The error message says it tried to allocate 1203208 bytes or just over 1MB of memory. The limit here is 67108864 bytes, or 65536KB which is 64MB so here I’d need a WP_MEMORY_LIMIT of more than 66M. The error message will go away once PHP has enough memory but be sure to test it.
If you allocate too much memory your server could start eating into disk swap space. Also be aware that each Apache child process is allowed to use that much memory so if you had ten processes it could use ten times the memory limit in a worst case scenario. If that happens you’ll need more RAM or you’ll have to figure out what’s using so much memory.
There’s also a WP_MAX_MEMORY_LIMIT constant. By default it’s 256M and it’s currently only used when uploading images.
On the off chance that you don’t have WordPress installed and you came here from a search engine, then you’ll want to use ini_set() somewhere early in the PHP process to increase the memory limit:
In WordPress you are not always in the PHP world and so you have to pass settings and data from the database to scripts sometimes. In many Plugins you can find solutions in loading the wp-load.php and therefore access to all features of WordPress. Long ago Otto (Samuel Wood) already referred to this fact and this articles shows solutions. Questions still there and still there are Plugins that load the wp-load.php precisely because of such problems.
A similar problem arises when the source of the scripts is not just written in the footer area of WordPress, but outsourced to a file and via wp_enqueue_script() included. Only then WordPress can manage, compromises and optimizes these scripts for delivery. Therefore I would like to show two examples, how to pass data from PHP to JS.
The first snippet uses the pass of values via JSON to get the values from the database with the current resources in PHP and the script stores directly in the header of the page the values as an object.
add_action( 'admin_enqueue_scripts', 'fb_print_scripts' );
function fb_print_scripts() {
global $current_screen;
if ( isset( $current_screen -> id ) && ! in_array( $current_screen -> id, array( 'post', 'page' ) ) )
return;
if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) )
$options = get_site_option( 'my_options_id' );
else
$options = get_option( 'my_options_id' );
if ( ! $options )
return;
?>
<script type="text/javascript">
var my_json_object = <?php echo json_encode( $options ); ?>;
</script>
<?php
}
The above function gives the values from the database as a JSON object in the head of the backend, as the page was requested in the first step of the function. Via $current_screen it will be checked so it will be only delivered if you are on one of the defined pages (post, page).
The next step is common practice and best solution to include scripts in WordPress. Thereby I will include the JS file, which then has accesses to the JSON object.
It’s now much easier for you and your commenters to keep track of the conversations you’re involved in across WordPress.com. Some recent tests have shown that by subscribing commenters to new comments by default, they are more likely to stay engaged and come back and comment more on your blog. With that knowledge, we’ve changed the default comment following behavior to help you get more conversations going on your blog.
We made the initial changes last week and after great feedback from you we just launched an update. Here’s how it works:
By default, posting a comment will now subscribe you to receive follow-up comments via email for that specific post, keeping you updated on the conversation. This is indicated by the checked box in the comment form.
If you have a WordPress.com account, you now have a global setting to change this so that by default you will not be subscribed. If you don’t have an account, then you can create one over here.
If you don’t want email notifications for a thread, just uncheck the box when you post your comment. If you’ve disabled the feature, you can also subscribe to a specific thread by checking the box in the comment form.
There is also a link at the bottom of every notification email that will allow you to change your subscription options.
If you’d like to find out all of the details about how this works, we’ve also updated our support documentation about following comments.
Have Baby. Need Stuff! is a baby gear site that my wife and I just launched. I thought I’d share how I built it.
WordPress Core
WordPress is a Git submodule, with the content directory moved to the /content/ directory. This makes my Git repo smaller, as WordPress isn’t actually in it.
Underscores
For a theme base, I started with the Underscores starter theme by the theme team at Automattic. Underscores is not a theme itself… it’s a starting point for building your own theme.
Bootstrap
Next, I integrated Bootstrap, by Twitter, to handle the CSS base and the grid system. Bootstrap is a really powerful framework, and version 2.0 has great responsive design support, which allowed me to create a single design that scales up to big screens or down to tablet or phone screen sizes. Try resizing it in your browser to see the responsiveness in action!
The CSS for the site is authored using LESS, which plays well with Bootstrap. I’m compiling/minifying/concatenating the CSS and JS using CodeKit, an amazing Mac OS X app that makes development a breeze.
I needed some patterns to use on the site, but I was frustrated with the licensing terms on many pattern sites I was finding. And then I found Subtle Patterns. Gorgeous, subtle patterns, liberally licensed. And hey, their site is WordPress powered too!
Posts 2 Posts
The site has the concepts of Departments, Needs, and Products. Each Department has multiple Needs. Each Need has multiple Products. I used Scribu’s phenomenal Posts 2 Posts plugin to handle these relationships.
I created a Custom Post Type for each of Departments, Needs, and Products, and connected them all using Posts 2 Posts. The connection between a Need and a Product also contains description metadata, as seen here:
Since Posts 2 Posts was a required plugin for the site to function, I didn’t want there to be any possibility of accidental deactivation. So I wrote a quick mu-plugins drop-in to “lock” certain plugins on.
I’m using the Products post type in a slightly odd way. You don’t ever go to a product URL. You instead go the URL for the Need that the Product fulfills, and that page lists all of the connected Products. As such, I wanted to make it so that URLs for products pointed to their Need, and I wanted to add an admin bar Edit link for the primary product on its Need page.
<?php
/*
Plugin Name: Post Links
Version: 0.1
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
// Convenience methods
if(!class_exists('CWS_Plugin_v2')){class CWS_Plugin_v2{function hook($h){$p=10;$m=$this->sanitize_method($h);$b=func_get_args();unset($b[0]);foreach((array)$b as $a){if(is_int($a))$p=$a;else $m=$a;}return add_action($h,array($this,$m),$p,999);}private function sanitize_method($m){return str_replace(array('.','-'),array('_DOT_','_DASH_'),$m);}}}
// The plugin
class CWS_HBNS_Post_Links_Plugin extends CWS_Plugin_v2 {
public static $instance;
public function __construct() {
self::$instance = $this;
$this->hook( 'plugins_loaded' );
}
public function plugins_loaded() {
$this->hook( 'post_type_link' );
$this->hook( 'add_admin_bar_menus' );
}
public function add_admin_bar_menus() {
$this->hook( 'admin_bar_menu', 81 );
}
public function admin_bar_menu( $bar ) {
if ( is_single() && 'need' == get_queried_object()->post_type ) {
$primary_product = new WP_Query( array(
'connected_type' => 'needs_to_products',
'connected_items' => get_queried_object(),
) );
if ( $primary_product->have_posts() ) {
$bar->add_menu( array(
'id' => 'edit-primary-product',
'title' => 'Edit Primary Product',
'href' => get_edit_post_link( $primary_product->posts[0] ),
) );
}
}
}
public function post_type_link( $link, $post ) {
switch ( $post->post_type ) {
case 'product' :
$need = new WP_Query( array(
'connected_type' => 'needs_to_products',
'connected_items' => $post,
) );
if ( $need->have_posts() )
return get_permalink( $need->posts[0] );
break;
}
return $link;
}
}
new CWS_HBNS_Post_Links_Plugin;
For entering data about Products, I made a custom Meta Box that provided a simple interface for entering the Amazon.com link, the approximate price, and then a freeform textarea for key/value pairs and miscellaneous bullet points.
Misc
Because I’m using a Git-backed and Capistrano-deployed repo, I don’t want any local file editing. So I dropped this code in:
I was playing a lot with different Product thumbnail sizes, so Viper007Bond’s Regenerate Thumbnails plugin was invaluable, for going back and reprocessing the images I’d uploaded.
My server runs Nginx and PHP-FPM, in lieu of Apache and mod_php. My normal setup is to use Batcache with an APC backend to do HTML output caching, but I also have an Nginx “microcache” that caches anonymous page views for a short amount of time (5 seconds). But with this site, I wanted to cache more aggressively. Because there are no comments, the site’s content remains static unless we change it. So I cranked my microcache up to 10 minutes (I guess it’s not a microcache anymore!). But I wanted a way to purge the cache if a Product or Post was updated, without having to wait up to 10 minutes. So I modified the Nginx config to recognize a special header that would force a dynamic page load, effectively updating the cache.
Here’s the relevant part of the Nginx config:
location ~ \.php$ {
# Set some proxy cache stuff
fastcgi_cache microcache_fpm;
fastcgi_cache_key $scheme$host$request_method$request_uri;
fastcgi_cache_valid 200 304 10m;
fastcgi_cache_use_stale updating;
fastcgi_max_temp_file_size 1M;
set $no_cache_set 0;
set $no_cache_get 0;
if ( $http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $no_cache_set 1;
set $no_cache_get 1;
}
# If a request comes in with a X-Nginx-Cache-Purge: 1 header, do not grab from cache
# But note that we will still store to cache
# We use this to proactively update items in the cache!
if ( $http_x_nginx_cache_purge ) {
set $no_cache_get 1;
}
# For cached requests, tell client to hang on to them for 5 minutes
if ( $no_cache_set = 0 ) {
expires 5m;
}
# fastcgi_no_cache means "Do not store this proxy response in the cache"
fastcgi_no_cache $no_cache_set;
# fastcgi_cache_bypass means "Do not look in the cache for this request"
fastcgi_cache_bypass $no_cache_get;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
try_files $uri =404;
fastcgi_pass phpfpm;
}
Now I just needed to have WordPress ping those URLs with that header to refresh them when something changed. Here’s the “meat” of that code:
<?php
public function transition_post_status( $new, $old, $post ) {
if ( 'publish' !== $old && 'publish' !== $new )
return;
$post = get_post( $post );
$url = get_permalink( $post );
// Purge this URL
$this->purge( $url );
// Purge the front page
$this->purge( home_url( '/' ) );
// If a Product changes, flush its Need and that Need's Department
if ( 'product' === $post->post_type ) {
// Flush the connected need
$need = new WP_Query( array(
'connected_type' => 'needs_to_products',
'connected_items' => $post,
) );
if ( $need->have_posts() ) {
$this->purge( get_permalink( $need->posts[0] ) );
// Now this need's connected Department
$department = new WP_Query( array(
'connected_type' => 'departments_to_needs',
'connected_items' => $need->posts[0],
) );
if ( $department->have_posts() )
$this->purge( get_permalink( $department->posts[0] ) );
}
// If a Post changes, flush the main Blog page
} elseif ( 'post' === $post->post_type ) {
$this->purge( home_url( '/blog/' ) );
}
}
private function purge( $url ) {
wp_remote_get( $url, array( 'timeout' => 0.01, 'blocking' => false, 'headers' => array( 'X-Nginx-Cache-Purge' => '1' ) ) );
}
Boom. Now I get the benefit of long cache times, but with the ability to have updates go live quickly when I need to. The upshot here is that while I have Batcache installed, it’s not really going to get a lot of use, as the outer Nginx caching layer should handle everything. This doesn’t just mean that the site scales (Apache Bench has it handling many thousands of requests a second with ease), but that the site is really, really fast to browse. Your experience will vary according to network and geography, of course. But for me, I’m getting 34ms HTML delivery times for pages in the Nginx cache.
Questions?
So that’s how I did it. Let me know if you have any questions!
We’ve added a user showcase where you can view stunning customizations made by people just like you. From complete redesigns with CSS to adding pizzazz with Custom Fonts to clever use of options like background and header, this showcase will spark your imagination and inspire creativity.
Discover details about what each showcase blog is doing with WordPress.com themes and customizations by clicking a thumbnail to see a colophon-style list of credits on the left.
We’ve also updated footer links so blog owners can show off the types of customizations they’ve made and visitors can learn more by clicking the “Customized” link in WordPress.com footers. A “Customized” link will appear next to the theme name for blogs that are using Custom Design tools like fonts or CSS.
Things we like to see when looking for showcase-worthy customizations are blogs with good traffic, beautiful design, well-written articles or stunning images, recent content updates, and involvement helping out in our CSS Customization forum.
Be inspired, customize your blog and make it that perfect place for your creations.
Spring is in the air. With the weather warming up, now is a great time to get started on a photo blog. Creating a photo blog is a wonderful introduction to blogging on WordPress.com or an opportunity to refresh your current site. Ready to get started? You can sign up for a new blog right over here.
Getting started
Photo blogs, sometimes called phlogs, use pictures instead of words. While many photo bloggers choose a type of photo that they want to focus on, such as portraits, others use their photo blog to document their life’s events. Photo blogs come in a variety of styles, including those that focus on vacation photos or even snapshots of friends. With images, we can capture moments in our life in a way that sometimes words cannot.
When starting a photo blog, you’ll want to choose a theme with a wider content area to help to showcase your photos at full size. Similarly, choosing a theme that is minimalistic helps to reduce any noise that may detract from the focus on your photography. Popular photo blogging themes on WordPress.com include Nishita, Duotone, and Modularity Lite. Looking for some inspiration? Be sure to check out the photo blogs below or more of our recommended photo blogging sites for examples of photo-friendly layouts.
The Unknown Project, a WordPress.com photo blog using Anthem.
Tracey Capone Photography, a WordPress.com photo blog using Twenty Eleven.
Tomorrow Never Knows, a WordPress.com photo blog using Comet.
Want to add photo flair to your site without starting a whole new blog? Adding a photo blogging category to an existing blog is a great way to revamp your site. In fact, you may consider doing “Friday Phlogs” or a similar weekly special to help incorporate these tips consistently into your current site.
Tools of the Trade
What do you need to get started? Nothing but a camera and an internet connection. Photo blogging with a smart phone is growing increasingly simple, particularly with the Quick Photo button in the WordPress for iOS and Android apps where you can point, shoot, and publish. If you’re already a pro at the WordPress apps, you may be interested in taking a look at Camera+ and Flickr, which allow you to automatically share your photos to your WordPress.com blog.
On the left, QuickPhoto in WordPress for Android and on the right, QuickPhoto in WordPress for iOS.
If you choose to use a more traditional camera, there are few tips to keep in mind when uploading your photos to ensure they represent the full quality of your original picture.
Don’t resize your photos after uploading them to WordPress.com. Instead, leave your images at full size so we can see your work in all of it’s glory. WordPress.com will automatically generate the appropriate dimensions for you.
Make edits to your photos before uploading them.
Save your photos as JPEGs. JPEGs are the best format for photos online. You can also use PNG if you’re looking to add a transparent image to your site.
Welcome to our series on photo blogging! Stay tuned for more tips and tricks over the next few weeks.
First off, I want to offer my sincere apologies to the WordPress Foundation. In a previous article, I incorrectly labeled the foundation as harming WordCamps. My main gripe was with the fact that some WordCamp organizers were being denied the ability to have high sponsorship caps and thus, it sometimes adversely affected the event either in terms of it’s size or type of venue they could hold the event in. As time has gone by, I’ve learned that the biggest mistake I made was contributing the organizing and running of WordCamps to the WordPress Foundation which is incorrect. WordCamp Central is the group responsible for all things WordCamp related while the WordPress Foundation oversees the use of the WordPress and WordCamp trademarks. Unfortunately in the original discussion, WordCamp Central and the WordPress Foundation were used interchangeably which muddied the conversation.
Perhaps I should have known better, but even though I’ve been apart of the WordPress community for two years, the project has grown far beyond just being publishing software. There is the foundation, WordCamp Central, Automattic, WordPress.com, various Automattic owned services, Audrey.co, etc. It’s hard to place blame or hold anyone accountable when you have no idea who that person is or what project or group they belong to. It’s frustrating for me but I wonder if many people simply don’t care, just as long as WordPress remains awesome, easy to use publishing software? I’ve often felt that there should be some sort of WordPress White Pages so that the public can know who is responsible for what within the WordPress project. But since so many individuals mingle with various parts, that project would soon be a waste of time.
WP Super Cache 1.0 came out several months ago and while it worked fine for most people there’s always room for improvement and bug fixes. Here are some of the bug fixes and improvements coming in the next version which I plan on releasing next week.
There are a lot of changes there so if you have a self hosted blog I would really appreciate if you download the development version, wp-super-cache.zip and install it in your plugins folder.
Use $_SERVER[ 'SERVER_NAME' ] to create cache directories.
Only create blogs cached directories if valid requests and blogs exist.
Only clear current blog’s cache files if navigation menu is modified
Added clean_post_cache action to clear cache on post actions
Removed garbage collection details on Contents tab
Added wp_cache_check_mobile cacheaction filter to shortcircuit mobile device check.
Don’t delete cache files for draft posts
Added action on wp_trash_post to clear the cache when trashed posts are deleted
Show a warning when 304 browser caching is disabled (because mod_rewrite caching is on)
New check for safe mode if using less that PHP 5.3.0
Added wp_supercache_remove_cookies filter to disable anonymous browsing mode.
Fixed garbage collection schedule dropdown
Fixed preload problem clearing site’s cache on “page on front” sites.
Fix for PHP variable not defined warnings
Fixed problem refreshing cache when comments made as siteurl() sometimes didn’t work
Preloading of taxonomies is now optional
Domain mapping fixes.
Better support for https sites. Remove https:// to get cache paths.
Added AddDefaultCharset .htaccess rule back in and added an option to remove it if required.
Added multisite plugin that adds a “Cached” column to Network->Sites to disable caching on a per site basis.
Added WPTouch plugin to modify browser and prefix list in mobile detection code. Added support for that plugin’s exclude list.
Fixed cache tester
Filter the tags that are used to detect end-of-page using the wp_cache_eof_tags filter.
The title says it all — this one-liner CSS will hide the home item from your navigation menu, when you’re on the home page:
body.home .current-menu-item { display: none; }
If you’re not yet using wp_nav_menu to build your navigation menus, then, uhm, wake up! Also, the snippet relies on the body_class usage in your theme, and if your theme doesn’t use one, uhm, wake up! :)
I also want to avoid the discussion about how the primary navigation should be consistent through each and every page on the website, if at all possible :)
Is comment spam one of the things that gets you down? Are you taking it personally? Are you confused by comment spam and how to handle it? I’ve been speaking at a variety of meetups lately on web publishing, blogging, and podcasting, and the topics often turn to managing comments and comment spam. “I’ve started [...]
“Sharepoint is a plague upon the American workforce. This ubiquitous piece of collaboration software has taught millions of people that Intranets are destined to be places where you can’t find anything[, but it] doesn’t have to be this way, despite what Microsoft may have you believe.”
It’s has been confirmed that WP Late Night, the new podcast I’m a Co-Host on, has become the #1 WordPress Podcast! I’m really excited, especially since we are just getting started. Last night we recorded the 8th episode of WP Late Night and are having a great time!
We’re trying to make this podcast different from the rest. We stream live video of the show using Spreecast. You can watch the video recording of our past shows on our WP Late Night Spreecast channel.
Another reason I think the show is so successful is the synergy between the hosts. I’ve known Ryan and Dre for a few years now. We’ve hung out at many WordCamps (and after parties!) and have become really good friends. Being friends with your co-hosts makes a big difference in the harmony of the show and I think that really comes across in each episode.
If you haven’t tuned in yet I highly recommend you give us a spin. You can listen to all of our episodes by visiting WPLateNight.com. You can also catch us live every Wednesday @ 8pm EDT on the WPCandy.com Stream.
Happy Thursday! We’ve added some exciting new themes to our ever-growing collection, and we’re happy to tell you all about them.
First out of the oven is…Just Desserts. Yep, that’s a theme! Designed by Andy Rutledge, Just Desserts is a deliciously stylish premium theme that’s perfect for blogs centered on food.
With its responsive, single-column layout and unique presentation of images and posts on the front page, Just Desserts gives you a delectable canvas on which your mouthwatering photos and text can really shine — even when viewed on smaller mobile devices such as tablets and smartphones.
If all of the dessert goodness left you breathless, we can supply you with some…Oxygen. Yep, that’s also a theme. Although, it may also leave you breathless because it’s simply stunning.
Designed by DevPress, Oxygen is a minimal yet beautifully crafted free magazine theme. With the help of your amazing images, the crisp and well-balanced design will transform your blog into an online magazine that looks sharp and professional.
Oxygen contains many features and customization options, including a showcase page template with a featured slider, featured images, seven widget areas, and a carefully tailored responsive layout. To read about these features and more, you know where to head — the Theme Showcase.
Happy blogging! We look forward to seeing what you bake, photograph, and write, armed with these great new themes.
Clients often ask for fuzzy, non-standard, maybe weird and not always logical permalink structure for their sites. If you’re now working with such a client, consider yourself lucky, because the brand new Rewrite Rules Inspector plugin is here! Props to the WordPress.com VIP team :)
Today countless teams are using WordPress to drive collaboration and facilitate inter-team communication. This presentation — given at the May WordPress DC Meetup — showcases some of the creative ways companies and organizations are using WordPress as the central hub of their day-to-day workflow: To organize and collaboratively edit documents and other non-web content, track and communicate their team’s progress with one another, and extend WordPress to work with their existing tools and practices
Click on the slides below to begin, then press the left/right keyboard arrows to navigate
WordCamp San Francisco 2012 is set for August 4 this year at the Mission Bay Conference Center. A developer hack day is scheduled for August 5th, and a survey looking for the best WordCamp speakers is open for recommendations. I know it’s me, but who’s counting. Honestly, if you have attended a WordCamp in the [...]
Now and then little snippets are pretty useful. For a fix in a Premium-Theme, I needed a kind of evaluation, where I am in the site structure and with little effort I was able to expand the classes and react with CSS.
The following code shows the basic for it and get_pages() is the key from the core of WordPress to get to these results. This function provides the necessary result of using the parameter and the output via the parameter sort_order provides the sequence and identification of the first page, which is then either the first or last page in this structure.
// First post in structure
// simple, but usefull
global $post;
$page_childs = get_pages( 'child_of=' . $post->post_parent . '&sort_order=ASC' );
$first_child = $page_childs[0];
if ( get_the_ID() === (int) $first_child->ID )
echo 'First Child';
// Last post in structure
global $post;
$page_childs = get_pages( 'child_of=' . $post->post_parent . '&sort_order=DESC' );
$last_child = $page_childs[0];
if ( get_the_ID() === (int) $last_child->ID )
echo 'Last Child';
Did you know that you could get the best WordPress.com features in your self hosted WordPress blog just by adding a WordPress plug-in. WordPress.com has some amazing features which are missing in WordPress.org installations, and the Jetpack WordPress plugin is the best way to incorporate all these amazing features in your WordPress blog.
Firstly I was apprehensive to install this WordPress plugin, since it was a collection of multiple WordPress plug-ins in one large plugin and I was concerned about the server load and how it would affect my site speed. I was using the WordPress stats plug-in for several years, and a large banner on top of my WordPress installation kept nagging me to upgrade to the new version which is available only in the JetPack.
JetPack WordPress Plugin
I have been a fan of several useful WordPress.com features lplugindPress stats, contact form, WordPress short links, subscriptions etc. so I decided to install Jet Pack and try out the new plug-in features. And to my surprise it was a collection of very powerful and useful features.
Subscriptions – it enables your site visitors to subscribe to your posts and comments and get updates via e-mail. It proved a quick replacement to my earlier amazing subscribe to comments plug-in.
WordPress.com stats – I have been using this WordPress plug-in for several years and it provides a quick snapshot of your site statistics. Jet pack includes the latest version of this plug-in, and all future versions of the stats plug-in will now only be available through the Jet Pack. Of course now the data provided by the plug-in is much more detailed than before.
Spelling and grammar – helps to improve your writing by contextual spell checking, advanced style checking and intelligent grammar checking of your articles. It is powered by After the Deadline open source technology.
Social sharing – powered by ShareDaddy, this plug-in provides an array of custom social sharing buttons which are then placed beneath your articles and improve the social engagement of your visitors.
VaultPress – this is a useful WordPress backup plug-in which we have been using for several years and is a useful tool in case your WordPress database crashes or you need to restore your site. Read our VaultPress review about this real-time backup and security scanning plug-in. It is highly recommended.
Contact form – is a useful plug-in to insert a contact form on any page or post you like, and is a good replacement for any contact form WordPress plug-in you might be using.
Gravatar Hovercards – if you support Gravatar profiles in your comments, then this plug-in will show pop-up business cards of these users from their gravatar profiles.
WP.me short links – creates a short link for all your pages and posts which can be easily shared on social media sites like Twitter.
Short code embeds – allows you to use short codes to embed videos from YouTube, Vimeo, slide share etc.
Beautiful math – allows you to use specialised markup language to post complex maths equations.
Sidebar widgets – some new widgets appear in your WordPress blog which allow you to add images, Twitter updates and RSS feed links in your sidebar.
Enhanced distribution- allows better sharing of your post articles and comments in real-time by distributing them quickly to search engines. A good pinging tool.
At first I had difficulty in deciding which plug-ins I should use. I also found it difficult to deactivate a few plug-ins since they were all activated by default and I did not need all these features. I learnt that you need to click on “Learn more” button, to make the “Deactivate” button appear! Then I could choose which plug-ins I actually needed to use.
Right now I am using the Subscriptions, WordPress.com stats, spelling, Vaultpress, Contact form and Enhanced distribution. The main advantage is that this is created by Automattic, the official WordPress team, so it promises to be tightly integrated in your WordPress.org installation easily.
So if like me, you decide to use some of the amazing WordPress.com features on your WordPress.org blog, then try the JetPack plug-in and you will find it useful.
After reading this article, readers liked these articles
Note: Everything I’m talking about here, including the code, is in beta mode. It will be subject to change. I’ll update this post after release to fix any code changes that may occur between now and then. I’m releasing this post now so that theme authors can start looking at their themes and thinking about how they might want to change the way they do options pages.
So, WordPress 3.4 has this nifty new feature you can find on the main Theme selection page. It’s a link next to each theme labeled “Customize”. This is the new Theme Customizer, and it’s way cool.
In fact, you can’t see what it does with a simple picture, so here’s a video. It’s available in HD if you want to go full screen.
So, now you know what it does, and if you’re a theme author, you’ve probably just gotten some great ideas. Here’s how you can implement those ideas in your theme.
First, note that if you already support the built in Custom Header and Custom Background functionality the WordPress core provides, then those will magically show up and work in the theme customizer. No extra code needed on your part.
Existing Options
Now, the first thing you’ll probably want to do is to take note of how your existing settings in the theme work. You have three main options for theme settings, realistically. I’ll go over them briefly.
1. “Theme mod”. This uses the set_theme_mod and get_theme_mod functions. It’s rare that themes actually use these since I wrote about the Settings API, but it is there and if you use these normally then it is supported by the Theme Customizer (in fact it’s the default).
2. Individual Settings. If you store your theme’s settings in the options table as individual rows, one per setting, then that works fine with the customizer. This is not the preferred way of doing things in themes, however, and not the most common. Still, some themes do this, so if you’re one of them, it’s supported as well.
3. Serialized Settings. This is the way I explained in my Settings API Tutorial and the method recommended by the Theme Review guidelines, as well as the way Chip described in his own tutorial for theme settings. Essentially, you store your settings in an array, then store that array using set_option or get_option, as one row in the database. This method is supported and it’s the way I’ll primarily cover in this article. I’ll briefly mention the other two methods when appropriate.
Once you know how your settings are stored, then you’ll know what to fill in at certain spots in the code. More on this when we get to it.
Object Orientation
Now, the Theme Customizer is very object oriented, and while you don’t necessarily need to understand this to implement the basics of it, you might need to understand it if you’re going to make something completely custom. Just a warning.
First, we’ll look at the left hand side of the customizer screen. Notice that the left hand side is divided into sections. Actually, that’s their name: WP_Customize_Section. In each of these sections is one or more controls; or rather, WP_Customize_Control. Finally, each of these controls one of more settings on the page: aka WP_Customize_Setting.
The Sections organize the controls. The Controls get input and pass it to the settings. The Settings interface with your existing options in the theme.
To make new stuff here for your own custom options, you need to know where to add it. That place is the customize_register action hook.
add_action( 'customize_register', 'themename_customize_register' );
function themename_customize_register($wp_customize) {
// ... do stuff ...
The function gets a parameter of the main $wp_customize object. This is the interface point where you will do everything like adding sections and controls and such.
Sections
So, first thing to do is to add a section. Here’s one way to do it:
The first parameter is a unique ID for the section that you’ll need later (when you’re putting controls into it). The second parameter is an array of options for the section. Sections don’t have a lot of options, really. You can give them a title, you can give them a “description” if you need some explanatory text in them. The priority setting determines their order in the list.
You can also give sections a “capability” if you have a special case. Generally speaking, most sites require the “edit_theme_options” capability to have users edit this sort of thing, and this is the default capability that the sections use. However, if you have options that anybody can edit, or which should only be managed by administrators, changing this capability will prevent the section from appearing to users who can’t change those settings anyway.
One final thing you can add to a section is a “theme_supports” option. This will make the menu not appear unless the theme supports something. If you’re putting this code in a theme itself, then you already know what the theme supports, so it doesn’t make much sense. The core uses this to not show the header and background options if the theme doesn’t support them.
Settings
Next, let’s configure some settings. Yes, the settings, not the controls. See, the controls need to know what settings they’re changing, so we have to attach the settings up first.
In this case, I’ve declared that the setting I’m interested in is in an option, the option is named “themename_theme_options” in the database, and it’s serialized, and the actual array key in there is “color_scheme”. Remember that talk we had before about the Settings API and how you store your settings? This was method 3.
This setting basically tells the theme customizer where the option is stored, and how to change it’s value so that your theme displays with the changed option.
Here’s the good bit about this: You’re telling the theme customizer where the option is. You don’t have to change the way the existing option works at all.
You already have a theme options page, right? So somehow, you’re saving those options. And in the theme, it’s reading those options using get_theme_mod or get_option, right? The way the theme customizer works is that it intercepts that call using a filter, changes the option for the previewer case only, and then passes the new option along to the theme. So the theme has no idea that the value it’s getting isn’t in the database, but one the user just selected. That’s the magic trick and why themes don’t have to dramatically change to support this sort of thing. All they have to do to make custom sections is to tell the theme customizer code what options they’re using and how, and it changes those options directly for the previewer.
(Note of clarification here: The “default” setting above should be a default value, not the current value. The difference is a subtle one, but the point is that you don’t actually need to get the current value of the option from the DB and put it in here. The WP_Customize_Setting takes care of all that jazz for you. The “default” is what should be used if the value doesn’t exist in the DB at all.)
There’s one more bit to the add_setting call that we’ll come back to later when I get around to explaining postMessage.
Controls
Finally, we come to the controls. Controls can look one of a lot of ways, obviously. The simplest controls are just checkboxes, or text fields. However, colors are something that change a lot, so there’s color wheel controls too. In fact, WordPress defines a number of possible controls. Let’s go over a few:
Pretty simple. It’s referencing the section it’s in, the setting that it’s going to change, and then it has the radio type and the list of choices along with their associated values.
How about a checkbox instead? This one comes straight from core:
The default type of control is actually type = ‘text’, and it creates a text box control. One more type of control is the “dropdown-pages” type, which creates a dropdown list of the WordPress Pages.
But that’s not all. There’s actually several more, but because they’re so custom, they’re declared differently. Here’s where we get all object oriented on ya…
Whoa, what’s with the new class? The WP_Customize_Color_Control is a class that is extending the built in WP_Customize_Control class. It adds the color wheel jazz to places where color selection is needed. Note that the class is being created here with new, and so it has to get the $wp_customize passed to it directly, so it knows where to hook in. (Note: This may change before final 3.4 release.)
Other controls of note:
WP_Customize_Upload_Control – This gives you an upload box, for allowing file uploads. However, you probably won’t use this directly, you’ll extend it for other things… like:
WP_Customize_Image_Control – This gives the image picker and the uploader box. It extends the upload controller. You can see it in action on the custom background piece, where a user can upload a new file to be the background image.
WP_Customize_Header_Image_Control – Because of the resizing action of the header piece, it needs a bit of special handling and display, so the WP_Customize_Header_Image_Control extends the WP_Customize_Image_Control to add that functionality. You can see it in action on the custom header piece, where a user can upload a new file to be the header image.
So, the way to create a custom controller to do whatever you want is to make a new class of your own which extends WP_Customize_Control and adds the bits you want. How to do that is a bit complex, so I’ll save that for another tutorial. For now, you’ve got image handling, color wheels, text boxes, radios, dropdowns, and checkboxes. I think that should be enough to get started with.
End of tutorial?
Not quite. Everything I went over above is enough to add new sections to the customizer, put controls in them, and then to have the preview show your changes after a slight delay when the page refreshes. All you have to do is to call those functions with the proper parameters, in the proper place, and it’ll work.
However, note that I said “when the page refreshes”… C’mon… this is the year 2012. We don’t have flying cars, and we still have to wait a whole second or two?
Nope.
Enter postMessage
Back when I mentioned the $wp_customize->add_setting function call, I mentioned “one more bit”. That one more bit is the option called “transport”.
Transport defines how your setting change gets from the place where you changed it into the preview pane. The default setting for this is “refresh”. An alternative setting is named “postMessage”.
The postMessage transport makes it such that the setting is instantly sent into the other frame, where javascript can adjust the page on-the-fly using this new information.
An example:
Let’s say we have a setting to change the colors of the titles. All the titles on the page are in some tag that has a class of posttitle, perhaps. The option normally just saves the HTML color chosen, then outputs some inline CSS in the header.php to basically do this:
.posttitle {
color: #abcdef;
}
Or whatever the option actually is for that color.
We have hooked our setting to that option, and hooked our WP_Customize_Color_Control up to it, and now when we change it, it works and we can see the color change. Note that this is easiest to do with already working customizer options, so the best way to do it is to get it working normally first, then add on this next bit.
Now, we have the working option in the customizer, so to take away that refresh delay, we’ll add this new option to the add_setting call:
'transport' => 'postMessage',
This tells the customizer that the setting will be sent directly to the frame via javascript. However, for that setting to work, we need javascript in the frame itself to receive it.
So, back in our main function… remember that? It started like this:
add_action( 'customize_register', 'themename_customize_register' );
function themename_customize_register($wp_customize) {
// ... do stuff ...
Right at the end of that function, we’re going to add this code:
This is going to add a new function call to our preview frame’s footer. It only gets added with the preview frame, so the live site and others won’t see it, because they don’t need to see it. This is where we’re going to output our javascript to make things happen in real-time.
Here’s our function:
function themename_customize_preview() {
?>
<script type="text/javascript">
wp.customize('setting_name',function( value ) {
value.bind(function(to) {
jQuery('.posttitle').css('color', to ? '#' + to : '' );
});
});
</script>
<?php
}
As you can see, it just outputs a bit of javascript. This code won’t change much, ever, so let’s go over just two pieces of importance:
‘setting_name’ is the name of the setting, as added by the $wp_customize->add_setting call.
The entire line starting with jQuery(‘.posttitle’) is our custom bit of code. It gets the “to” variable, which will be the color chosen by the user, and it sets the posttitles on the page to have that color, using the css modifying functionality of jquery.
Those are the only two bits you need to change, really. The rest is pretty copy-pasta. For each real-time setting, you can dupe this bit of code in the script.
Here’s another thing: You can change pre-existing refresh settings to be postMessage ones. Take the Site Title and Tagline elements in the Header section, for example. These are refresh settings, and the reason they are is because each theme implements them differently. There’s no way for the core to know the javascript code needed for any particular theme.
But if you’re a theme author, then you’re not writing for a generic theme. You’re writing for your particular theme. You know how the site title and tagline are displayed. There’s no reason you can’t make those update in real time. And while you’re at it, the header_textcolor setting can be real time too, since you know the theme code.
In your main function again, add these three lines of code:
That changes the transport on those core settings to be postMessage. Now you need to add the javascript code to actually do the refreshing in your theme. Here’s an example of TwentyEleven doing this (with the patch I wrote for it):
function twentyeleven_customize_preview() {
?>
<script type="text/javascript">
wp.customize('blogname',function( value ) {
value.bind(function(to) {
jQuery('#site-title a').html(to);
});
});
wp.customize('blogdescription',function( value ) {
value.bind(function(to) {
jQuery('#site-description').html(to);
});
});
wp.customize( 'header_textcolor', function( value ) {
value.bind( function( to ) {
jQuery('#site-title a, #site-description').css('color', to ? '#' + to : '' );
});
});
</script>
<?php
}
For the blogname, it changes the HTML inside the “#site-title a” link. For the description, it changes the tag with #sitedescription. For the color of those, it simply targets both of them and alters their CSS.
Core has to try to be generic across all themes. But themes have more knowledge of how they work and can change things to target themselves in better ways. A theme adding controls knows what those controls change, so if it’s something simple like CSS or even something more complex like HTML, if you can write javascript code to make that modification in real time, then you can use postMessage and eliminate that refresh delay.
Hopefully this explains some of the theme customizer. Was it as clear as mud? Take a look at my patch to Twenty Eleven to add some of the theme options from its existing options screen into the customizer. You can find it on this ticket: http://core.trac.wordpress.org/ticket/20448.
Speaking of defaults, NEVER SET DEFAULTS IN THE DATABASE. Not ever. The theme options you store in the DB should always, always, *always* be something the user has selected. If the user selects the default, then that’s fine to set in the DB. but you don’t set it in the DB just because it’s not set at all. get_theme_mod has a second option for the default value. So does get_option for that matter. Use this.
When cleaning up hacked sites and testing .htaccess tricks, it’s nice to have a list of WordPress directory and file names for checking patterns and finding strings directly via Search/Find. Especially when working remotely, having a complete list of WordPress files available online can help expedite the attack-recovery process.
The official Codex page lists some important files, but only for WP version 2.x and doesn’t seem to list files located in all sub-directories. Sure it’s not the most exciting topic in the world, but it’s always good practice to know thy files. You get to see the bigger picture and gain a better understanding of how much stuff actually is included in WordPress — especially if you start digging around in the /wp-includes/ directory.. bring a snack, knife, and some flint to improve your chances.
We’re looking at default download/unzip of WordPress version 3.3.2 — a complete list of all files in all directories in alphabetical order. Here’s the roadmap:
This one’s self-explanatory, but a lot has changed so I thought I’d poll one up to see what people think. It seems there are a lot more sites these days without the www. in their canonical URLs, but a lot of big sites continue to include the “www” subdomain (think Google home page). Which one is best? Let’s find out..
In this poll, you’re asked whether you prefer URLs with or without the extra www. subdomain. But you have to choose one or the other — no “other/undecided” votes allowed on this one ;)
One of our users asked how do other sites show number of queries and page load time in the footer. You will often see this in the footer of sites and it may say something like: “64 queries in 1.248 seconds”. In this article, we will show you how to show number of queries and page load time in WordPress.
Simply paste the following code anywhere you like in your theme files (such as footer.php).
<?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?> seconds.
And refresh the page. You will see the number of queries and the execution time.
This is feed aggregator that keeps track of bloggers who contribute to
WordPress, mostly by writing plugins. Every few hours are aggregated here their writing about WordPress.
Syndicate
You can add this planet feeds to your feed reader:
Join in ?
Have a blog? Write with, about and for WordPress? If you want to see your own blog added to this planet,
check the "rules" and apply here
Jump off ?
For some reason, you're not happy about being aggregated here ?
Send me an email and I'll remove you.