WordPress VIP: Unique Standards

By: Ryan Kienstra on: January 6, 2015  in: WordPress VIP   1 Comment

WordPress VIP Unique StandardsMany of the VIP coding standards are different from self-hosted WP standards.

The size and structure of VIP multi-sites often require different coding.


There’s a single database for all users in WordPress.com.

So you can’t do any CRUD operations on it: create, read, update, or delete.

To parse the users, call get_users() and operate on them with PHP.

“Site” Functions

get_site_*() and site_*() won’t work on the WordPress.com multi-site network.

You should be able to avoid get_site_url() or site_url() by using direct permalinks to pages or posts.


Calling admin-ajax.php on every page load isn’t allowed.

If you need JSON on every load, you might localize it into the JavaScript file with wp_localize_script.

Object Cache

This stores values between page loads.

But it’s different from the full-page caching of Batcache.

Once the object cache exceeds the 1 MB limit, all queries go to the database.

You can check the object cache size by using the Debug Bar plugin.

Click the red “Debug” button at the top of any page, and click “Request” on the left.

Object Cache Memory

The memory usage of each value is in parentheses on the right.

Don’t Use extract()

This isn’t allowed in WordPress VIP, though it’s never good to use.

It obscures where variables came from.

And this can cause security issues.

extract assigns key-value pairs in an array to variables.

For example, I used to have this code in my Adapter Responsive Video plugin:

function widget( $args , $instance ) {
        extract( $args ); 
        $video_source = isset( $instance[ 'video_source' ] ) ? $instance[ 'video_source' ] : "";
        $aspect_ratio_class = isset( $instance[ 'aspect_ratio_class' ] ) ? $instance[ 'aspect_ratio_class' ] : "";
        if ( $video_source ) {
                $bootstrap_responsive_video = get_bootstrap_responsive_video( $video_source , $aspect_ratio_class );
                echo $before_widget . $bootstrap_responsive_video . $after_widget;

The argument $args is an array:

array( "before_widget" => "foo_before_widget_markup" , 
       "after_widget"  => "foo_after_widget_markup" )

Calling extract( $args ) is the same as making these assignments:

$before_widget = $args[ 'before_widget' ];
$after_widget = $args[ 'after_widget' ];

But extract may assign variables that you don’t know about.

I deleted extract, and replaced the echo line with:

echo $args[ 'before_widget' ] . $bootstrap_responsive_video . $args[ 'after_widget' ];

Unfortunately, the extract function is common in the widget method of widget classes.

“Powered By” Link

This is required for all VIP sites.

The VIP Documentation states that most people place echo vip_powered_wpcom(); in the footer.php file.

This has two optional parameters.

The first is a number from 1 to 6 that can change the image.

Activating Original Plugins

VIP sites store custom plugins in the plugins/ directory of their theme file.

In your theme’s functions.php file, add:

require_once( __DIR__ , '/plugins/foo-plugin/foo-plugin.php' );

There’s no activation through the menu, so don’t use register_action_hook or register_deactivation_hook.

Query Limits

VIP sites may have tens of thousands of posts or images.

So when you query them, it’s important to limit the results.

VIP agency 10up noted this in their Engineering Best Practices.

For example, I used to have the following code in my Widget Live Editor plugin:

$images_query = new WP_Query( array( 'post_type' => 'attachment' , 
                                     'post_status' => 'inherit', 
                                     'post_mime_type' => 'image' , 
                                     'posts_per_page' => -1, // could crash the site
) );

The -1 value for posts_per_page means that there is no limit to this query.

And it wouldn’t take too many images to crash the site.

I changed the limit to 100.

VIP vs. WP.org

There are many similarities between VIP and wordpress.org coding standards.

But there are some important differences.

Many of these are from the size of multi-site VIP networks.

And some are to support caching of the large sites.

What are the biggest differences you’ve found with WordPress VIP sites?

  A comment   Comment

  1. 7 years ago  

    perdre du ventre

    I’m not that much of a online reader to be
    honest but your sites really nice, keep it up! I’ll ggo ahead and
    bookmark your website tto come back later. All the best

Leave a comment