Constants

A8C_PROXIED_REQUEST

A8C_PROXIED_REQUEST = false : \constant

CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS

CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS = $internal_cron_events

FS_METHOD

FS_METHOD = 'direct'

VIP_GO_ENV

VIP_GO_ENV = false

VIP_GO_IS_CLI_CONTAINER

VIP_GO_IS_CLI_CONTAINER = false !== strpos(gethostname(), '_wpcli_') || false !== strpos(gethostname(), '_wp_cli_')

VIP_JETPACK_CONNECTION_PILOT_SHOULD_RECONNECT

VIP_JETPACK_CONNECTION_PILOT_SHOULD_RECONNECT = false

VIP_JETPACK_CONNECTION_PILOT_SHOULD_RUN

VIP_JETPACK_CONNECTION_PILOT_SHOULD_RUN = false

WP_ENVIRONMENT_TYPE

WP_ENVIRONMENT_TYPE = $environment_type

WPCOM_IS_VIP_ENV

WPCOM_IS_VIP_ENV = false

WPCOM_SANDBOXED

WPCOM_SANDBOXED = false !== strpos(gethostname(), '_web_dev_')

WPCOM_VIP_CLIENT_MU_PLUGIN_DIR

WPCOM_VIP_CLIENT_MU_PLUGIN_DIR = WP_CONTENT_DIR . '/client-mu-plugins'

WPCOM_VIP_CUSTOM_CATEGORY_BASE

WPCOM_VIP_CUSTOM_CATEGORY_BASE = true

WPCOM_VIP_CUSTOM_TAG_BASE

WPCOM_VIP_CUSTOM_TAG_BASE = true

WPCOM_VIP_DISABLE_SHARED_PLUGINS

WPCOM_VIP_DISABLE_SHARED_PLUGINS = true

WPCOM_VIP_MACHINE_USER_EMAIL

WPCOM_VIP_MACHINE_USER_EMAIL = 'donotreply@wordpress.com'

WPCOM_VIP_MACHINE_USER_ID

WPCOM_VIP_MACHINE_USER_ID = $user->ID

WPCOM_VIP_MACHINE_USER_LOGIN

WPCOM_VIP_MACHINE_USER_LOGIN = 'vip'

WPCOM_VIP_MACHINE_USER_NAME

WPCOM_VIP_MACHINE_USER_NAME = 'VIP'

WPCOM_VIP_MACHINE_USER_ROLE

WPCOM_VIP_MACHINE_USER_ROLE = 'administrator'

WPCOM_VIP_MAIL_TRACKING_KEY

WPCOM_VIP_MAIL_TRACKING_KEY = false

WPCOM_VIP_PRIVATE_DIR

WPCOM_VIP_PRIVATE_DIR = $private_dir_path

Functions

_vip_admin_gallery_css_extras()

_vip_admin_gallery_css_extras() 

Helper function for vip_admin_gallery_css_extras()

_vip_contrib_add_upload_cap()

_vip_contrib_add_upload_cap() 

Helper function for vip_contrib_add_upload_cap() to change the user roles

_vip_crossdomain_redirect()

_vip_crossdomain_redirect() 

Helper function for vip_crossdomain_redirect(); serves up /vip/your_theme/crossdomain.xml

_wpcom_vip_allow_more_html_in_comments()

_wpcom_vip_allow_more_html_in_comments() 

Helper function for wpcom_vip_allow_more_html_in_comments()

_wpcom_vip_call_on_hook_or_execute()

_wpcom_vip_call_on_hook_or_execute(\function  $function, string  $hook,   $priority = 99) 

Utility function to trigger a callback on a hook with priority or execute immediately if the hook has already been fired previously.

Parameters

\function $function

Callback to trigger.

string $hook

Hook name to trigger on.

$priority

_wpcom_vip_filter_category_base()

_wpcom_vip_filter_category_base(string  $category_base) : string

Applies the new category base to the option value

Parameters

string $category_base

New category base prefix

Returns

string —

The category base prefix

_wpcom_vip_filter_permalink_structure()

_wpcom_vip_filter_permalink_structure(string  $permastruct) : string

Applies the new permalink structure to the option value

Parameters

string $permastruct

The new permastruct

Returns

string —

The new permastruct

_wpcom_vip_filter_tag_base()

_wpcom_vip_filter_tag_base(string  $tag_base) : string

Applies the new tag base to the option value

Parameters

string $tag_base

New tag base prefix

Returns

string —

The tag base prefix

_wpcom_vip_include_plugin()

_wpcom_vip_include_plugin(string  $file) : true

Include a plugin and its helper, handling variable scope in the process

Parameters

string $file

Plugin file to load

Returns

true

_wpcom_vip_load_plugin_sanitizer()

_wpcom_vip_load_plugin_sanitizer(string  $folder) : string

Helper function for wpcom_vip_load_plugin(); sanitizes plugin folder name.

You shouldn't use this function.

Parameters

string $folder

Folder name

Returns

string —

Sanitized folder name

_wpcom_vip_maybe_refresh_current_user_caps()

_wpcom_vip_maybe_refresh_current_user_caps(string  $role) 

Force refreshes the current user's capabilities if they belong to the specified role.

This is to prevent a race condition where the WP_User and its related caps are generated before or roles changes.

Parameters

string $role

Role name

delete_user_attribute()

delete_user_attribute(integer  $user_id, string  $meta_key, mixed  $meta_value = '') : boolean

Remove user attribute data.

Parameters

integer $user_id

User ID.

string $meta_key

Metadata key.

mixed $meta_value

Optional. Metadata value.

Returns

boolean —

True deletion completed and false if user_id is not a number.

disable_autosave()

disable_autosave() 

Disable post autosave

disable_right_now_comment_count()

disable_right_now_comment_count() 

Disable comment counts in "Right Now" Dashboard widget as it can take a while to query the data.

do_sitemap_pings()

do_sitemap_pings(  $job) 

Ping all registered HTTP endpoints for sitemap URIs

Parameters

$job

es_api_search_index()

es_api_search_index(array  $args) : boolean|string

Executes an elasticsearch query via our REST API.

Requires setup on our end and a paid addon to your hosting account. You probably shouldn't be using this function. Questions? Ask us.

Valid arguments:

Parameters

array $args

Returns

boolean|string —

False if WP_Error, otherwise JSON string

get_blog_lang_code()

get_blog_lang_code(  $blog_id) 

Parameters

$blog_id

get_top_posts()

get_top_posts(integer  $number = 10, integer  $days = 2) : array

Gets the data used by the "Top Posts" widget.

Our Top Posts widget (http://en.support.wordpress.com/widgets/top-posts-widget/) uses a display_top_posts() function to display a list of popular posts. You can use this function in your themes. The function uses data from WordPress.com Stats (http://en.support.wordpress.com/stats/) to generate the list.

If you would like more control over the output of display_top_posts(), use the get_top_posts() function.

Note: in the results, post_ID = 0 is used to track home page views.

Parameters

integer $number

Optional. At least 10 posts are always returned; this parameter controls how many extra you want. Valid values: 1-10 (default is 10).

integer $days

Optional. How many days of stats should be used in the calculation; defaults to 2.

Returns

array

get_user_attribute()

get_user_attribute(integer  $user_id, string  $meta_key) : mixed

Retrieve user attribute data.

If $user_id is not a number, then the function will fail over with a 'false' boolean return value. Other returned values depend on whether there is only one item to be returned, which be that single item type. If there is more than one metadata value, then it will be list of metadata values.

Parameters

integer $user_id

User ID

string $meta_key

Optional. Metadata key.

Returns

mixed

is_automattician()

is_automattician(integer  $user_id = false) : boolean

Is the given user an Automattician?

This does a relatively weak check that the user has an Automattic email address, and that they have verified that email address. It's possible to fake that data (it's just user meta and user_email), so don't use this for protecting sensitive info or performing sensitive tasks.

This does NOT guarantee the current user is proxied. Use is_proxied_automattician() for that.

Parameters

integer $user_id

A WP User id

Returns

boolean —

True, if user is an Automattician, otherwise false

is_proxied_automattician()

is_proxied_automattician() : boolean

Is the current user an Automattician, authenticated via the Automattic proxy.

Determine if the current request is made via the Automattic proxy, which is only available to Automatticians, AND if the current user is an Automattician.

Returns

boolean —

True, if the current request is made via the Automattic proxy

is_proxied_request()

is_proxied_request() : boolean

Is the current request made using the Automattic proxy.

Returns

boolean —

True if the current request is made using the Automattic proxy

make_tags_local()

make_tags_local() 

Keeps category and tag links local to the blog instead of linking to http://en.wordpress.com/tags/

news_sitemap_uri()

news_sitemap_uri() 

Absolute URL of the current blog's news sitemap

sitemap_cache_key()

sitemap_cache_key() 

Common definition of sitemap cache key for use in getters, setters and clears

sitemap_content_type()

sitemap_content_type() : string

Return the content type used to serve a Sitemap XML file Uses text/xml by default, possibly overridden by sitemap_content_type filter

Returns

string —

Internet media type for the sitemap XML

sitemap_discovery()

sitemap_discovery() 

Output the master sitemap URLs for the current blog context

sitemap_handle_update()

sitemap_handle_update(integer  $post_id) 

Clear the sitemap cache when a sitemap action has changed Add a job to the pings queue to send out update notifications

Parameters

integer $post_id

unique post identifier. not used.

sitemap_uri()

sitemap_uri() : string

Absolute URL of the current blog's sitemap

Returns

string —

sitemap URL

update_user_attribute()

update_user_attribute(integer  $user_id, string  $meta_key, mixed  $meta_value) : boolean

Update a user's attribute

There is no need to serialize values, they will be serialized if it is needed. The metadata key can only be a string with underscores. All else will be removed.

Will remove the attribute, if the meta value is empty.

Parameters

integer $user_id

User ID

string $meta_key

Metadata key.

mixed $meta_value

Metadata value.

Returns

boolean —

True on successful update, false on failure.

vary_cache_on_function()

vary_cache_on_function(  $function) 

Parameters

$function

vip_admin_gallery_css_extras()

vip_admin_gallery_css_extras() 

Un-hide the extra size and alignment options in the gallery tab of the media upload box

vip_contrib_add_upload_cap()

vip_contrib_add_upload_cap() 

Allows users of contributor role to be able to upload media.

Contrib users still can't publish.

vip_crossdomain_redirect()

vip_crossdomain_redirect() 

Responds to a blog.wordpress.com/crossdomain.xml request with the contents of a crossdomain.xml file located in the root of your theme.

vip_disable_tag_suggest()

vip_disable_tag_suggest() 

Disables the tag suggest on the post screen.

vip_doubleclick_dartiframe_redirect()

vip_doubleclick_dartiframe_redirect() 

Responds to a blog.wordpress.com/DARTIframe.html request with the contents of a DARTIframe.html file located in the root of your theme.

vip_get_random_posts()

vip_get_random_posts(integer  $number = 1, string  $post_type = 'post', boolean  $return_ids = false, integer  $category_id) : array

Get random posts; a simple, more efficient approach.

.

MySQL queries that use ORDER BY RAND() can be pretty challenging and slow on large datasets. This function is an alternative method for getting random posts, though it's not as good but at least it won't destroy your site :).

Parameters

integer $number

Optional. Amount of random posts to get. Default 1.

string $post_type

Optional. Specify the post_type to use when randomizing posts. Default 'post'.

boolean $return_ids

Optional. To just get the IDs, set this to true, otherwise post objects are returned (the default).

integer $category_id

Optional. Limit to a specific category

Returns

array

vip_is_jetpack_request()

vip_is_jetpack_request() : boolean

Is the current request being made from Jetpack servers?

NOTE - This checks the REMOTE_ADDR against known JP IPs. The IP can still be spoofed, (but usually an attacker cannot receive the response), so it is important to treat it accordingly

Returns

boolean —

Bool indicating if the current request came from JP servers

vip_main_feed_redirect()

vip_main_feed_redirect(string  $target) 

Redirect http://blog.wordpress.com/feed/ to $target URL

Don't redirect if a feed service user agent, because that could result in a loop.

This can be executed before WP init because it checks the URI directly to see if the main feed is being requested.

Parameters

string $target

URL to direct feed services to

vip_multiple_moderators()

vip_multiple_moderators(array  $emails) 

Send comment moderation emails to multiple addresses

Parameters

array $emails

Array of email addresses

vip_powered_wpcom()

vip_powered_wpcom(string  $display = 'text', string  $before_text = 'Powered by ') : string

Returns the "Powered by WordPress.com VIP" widget's content.

Parameters

string $display

Optional. Either: 1-6 or "text"*. If an integer, wrap an image in the VIP link. Otherwise, just return the link.

string $before_text

Optional. Text to go in front of the VIP link. Defaults to 'Powered by '.

Returns

string —

HTML

vip_powered_wpcom_img_html()

vip_powered_wpcom_img_html(integer  $image) : string

Returns a link the WordPress VIP site wrapped around an image (the VIP logo).

Parameters

integer $image

Which variant of the VIP logo to use; between 1-6.

Returns

string —

HTML

vip_powered_wpcom_url()

vip_powered_wpcom_url() : string

Returns the URL to the WordPress VIP site

Returns

string

vip_redirects()

vip_redirects(array  $vip_redirects_array = array(), boolean  $case_insensitive = false) 

Simple 301 redirects

Parameters

array $vip_redirects_array

Optional. Elements should be in the form of '/old' => 'http://wordpress.com/new/'

boolean $case_insensitive

Optional. Should the redirects be case sensitive? Defaults to false.

vip_regex_redirects()

vip_regex_redirects(array  $vip_redirects_array = array(), boolean  $with_querystring = false) 

Advanced 301 redirects using regex to match and redirect URLs.

Warning: Since regex is expensive and this will be run on every uncached pageload, you'll want to keep this small, lean, and mean.

Some examples:

Redirecting from /2011/12/dont-miss-it-make-live-holiday-giveaway.html (extra .html at the end) '|/([0-9]{4})/([0-9]{2})/([0-9]{2})/([^/]+).html|' => '|/$1/$2/$3/$4/|'

Redirecting from /archive/2011/12/dont-miss-it-make-live-holiday-giveaway '|/archive/([0-9]{4})/([0-9]{2})/([^/]+)/?|' => '|/$3/|' // since we don't have the day, we should just send to /%postname% then WordPress can redirect from there

Redirecting from /tax-tips/how-to-get-a-tax-break-for-summer-child-care/04152011-6163 (/%category%/%postname%/%month%%day%%year%-%post_id%) '|/([^/]+)\/([^/]+)/([0-9]{1,2})([0-9]{1,2})([0-9]{4})-([0-9]{1,})/?|' => '|/$5/$3/$4/$2/|'

Parameters

array $vip_redirects_array

Optional. Array of key/value pairs to redirect from/to.

boolean $with_querystring

Optional. Set this to true if your redirect string is in the format of an absolute URL. Defaults to false (just the path).

vip_remove_enhanced_feed_images()

vip_remove_enhanced_feed_images() 

Do not display the images in enhanced feeds.

Helper function for wpcom_vip_disable_enhanced_feeds().

vip_reset_db_query_log()

vip_reset_db_query_log() 

Reset the WordPress DB query log

vip_reset_local_object_cache()

vip_reset_local_object_cache() 

Reset the local WordPress object cache

This only cleans the local cache in WP_Object_Cache, without affecting memcache

vip_safe_wp_remote_get()

vip_safe_wp_remote_get(  $url,   $fallback_value = '',   $threshold = 3,   $timeout = 1,   $retry = 20,   $args = array()) 

This is a convenience method for vip_safe_wp_remote_request() and behaves the same

Note that like wp_remote_get(), this function does not cache.

Parameters

$url
$fallback_value
$threshold
$timeout
$retry
$args

vip_safe_wp_remote_request()

vip_safe_wp_remote_request(string  $url, string  $fallback_value = '', integer  $threshold = 3, integer  $timeout = 1, integer  $retry = 20,   $args = array()) : string|\WP_Error|array

This is a sophisticated extended version of wp_remote_request(). It is designed to more gracefully handle failure than wpcom_vip_file_get_contents() does.

Note that like wp_remote_request(), this function does not cache.

Parameters

string $url

URL to request

string $fallback_value

Optional. Set a fallback value to be returned if the external request fails.

integer $threshold

Optional. The number of fails required before subsequent requests automatically return the fallback value. Defaults to 3, with a maximum of 10.

integer $timeout

Optional. Number of seconds before the request times out. Valid values 1-5; defaults to 1.

integer $retry

Optional. Number of seconds before resetting the fail counter and the number of seconds to delay making new requests after the fail threshold is reached. Defaults to 20, with a minimum of 10.

$args

Returns

string|\WP_Error|array —

Array of results. If fail counter is met, returns the $fallback_value, otherwise return WP_Error.

vip_substr_redirects()

vip_substr_redirects(array  $vip_redirects_array = array(), boolean  $append_old_uri = false) 

Wildcard redirects based on the beginning of the request path.

This is basically an alternative to vip_regex_redirects() for when you only need to redirect /foo/bar/* to somewhere else. Using regex to do this simple check would add lots of overhead.

Parameters

array $vip_redirects_array

Optional. Elements should be in the form of '/some-path/' => 'http://wordpress.com/new/'

boolean $append_old_uri

Optional. If true, the full path past the match will be added to the new URL. Defaults to false.

vip_wp_file_get_content()

vip_wp_file_get_content(string  $url, boolean  $echo_content = true, integer  $timeout = 3) : string|null

This is the old deprecated version of wpcom_vip_file_get_contents(). Please don't use this function in any new code.

Parameters

string $url

URL to fetch

boolean $echo_content

Optional. If true (the default), echo the remote file's contents. If false, return it.

integer $timeout

Optional. The timeout limit in seconds; valid values are 1-10. Defaults to 3.

Returns

string|null —

If $echo_content is true, there will be no return value.

w3cdate_from_mysql()

w3cdate_from_mysql(string  $mysql_date) : string

Convert a MySQL datetime string to an ISO 8601 string

Parameters

string $mysql_date

UTC datetime in MySQL syntax of YYYY-MM-DD HH:MM:SS

Returns

string —

ISO 8601 UTC datetime string formatted as YYYY-MM-DDThh:mm:ssTZD where timezone offset is always +00:00

widont()

widont(string  $str = '') : string

Eliminates widows in strings by replace the breaking space that appears before the last word with a non-breaking space.

This function is defined on WordPress.com and can be a common source of frustration for VIP devs. Now they can be frustrated in their local environments as well :)

Parameters

string $str

Optional. String to operate on.

Returns

string

wp_endswith()

wp_endswith(  $haystack,   $needle) 

Parameters

$haystack
$needle

wp_flush_get_term_by_cache()

wp_flush_get_term_by_cache(  $term_id,   $taxonomy) 

Parameters

$term_id
$taxonomy

wp_flush_term_exists()

wp_flush_term_exists(  $term,   $tt_id,   $taxonomy,   $deleted_term) 

Parameters

$term
$tt_id
$taxonomy
$deleted_term

wp_in()

wp_in(  $needle,   $haystack) 

Parameters

$needle
$haystack

wp_startswith()

wp_startswith(  $haystack,   $needle) 

Parameters

$haystack
$needle

wpcom_disable_mobile_app_promotion()

wpcom_disable_mobile_app_promotion() 

Removes the mobile app promotion from the bottom of the default mobile theme.

Example: "Now Available! Download WordPress for iOS"

wpcom_do_sandbox_bar()

wpcom_do_sandbox_bar() 

wpcom_initiate_flush_rewrite_rules()

wpcom_initiate_flush_rewrite_rules() 

wpcom_invite_force_matching_email_address()

wpcom_invite_force_matching_email_address() 

Force a site invitation to a user to only be accepted by a user who has the matching WordPress.com account's email address.

The default behavior for invitations is to allow any WordPress.com user accept an invitation regardless of whether their email address matches what the invitation was sent to. This helper function forces the invitation email to match the WordPress.com user's email address.

wpcom_is_vip()

wpcom_is_vip() 

Technically this function used to return whether or not the given site was flagged as VIP.

..though most VIP clients used it as a way to determine if the code was in production vs. dev, before WPCOM_IS_VIP_ENV was introduced

For back compat with that usage, we return the value of WPCOM_IS_VIP_ENV so that v1 client code works as expected

wpcom_print_news_sitemap()

wpcom_print_news_sitemap(  $format) 

Parameters

$format

wpcom_print_sitemap()

wpcom_print_sitemap() 

Print an XML sitemap conforming to the Sitemaps.org protocol Outputs an XML list of up to the latest 1000 posts.

wpcom_print_sitemap_item()

wpcom_print_sitemap_item(  $data) 

Parameters

$data

wpcom_print_xml_tag()

wpcom_print_xml_tag(  $array) 

Parameters

$array

wpcom_search_api_query()

wpcom_search_api_query(array  $args, string  $stat_app_name = 'blog-search') : boolean|string

A wrapper for es_api_search_index() that accepts WP-style args

This is a copy/paste, up to date as of WP.com r65003 (Jan 7th, 2013)

Parameters

array $args
string $stat_app_name

Optional.

Returns

boolean|string —

False if WP_Error, otherwise JSON string

wpcom_search_api_wp_to_es_args()

wpcom_search_api_wp_to_es_args(array  $args) : array

Converts WP-style args to ES args

Parameters

array $args

Returns

array

wpcom_sitemap_array_to_simplexml()

wpcom_sitemap_array_to_simplexml(array  $data, \SimpleXMLElement  $tree) : \SimpleXMLElement

Convert an array to a SimpleXML child of the passed tree.

Parameters

array $data

array containing element value pairs, including other arrays, for XML contruction

\SimpleXMLElement $tree

A SimpleXMLElement class object used to attach new children

Returns

\SimpleXMLElement —

full tree with new children mapped from array

wpcom_sitemap_initstr()

wpcom_sitemap_initstr(  $charset) 

Parameters

$charset

wpcom_sitemap_n_to_news_namespace()

wpcom_sitemap_n_to_news_namespace(mixed  $url) 

Transitionary solution in migration from n to news namespace

While we get all the VIP clients that have filters that changing the namespace would impact we will convert n: to news: as late as possible.

Parameters

mixed $url

wpcom_sitemap_namespaces()

wpcom_sitemap_namespaces() : array

Define an array of attribute value pairs for use inside the root element of an XML document.

Intended for mapping namespace and namespace URI values. Passes array through sitemap_ns for other functions to add their own namespaces

Returns

array —

array of attribute value pairs passed through the sitemap_ns filter

wpcom_uncached_get_post_by_meta()

wpcom_uncached_get_post_by_meta(string  $meta_key, string  $meta_value, string  $post_type = 'post', array  $post_stati = array('publish', 'draft', 'pending', 'private'), integer  $limit = 1) : array|\WP_Error

Queries posts by a postmeta key/value pair directly from the master database.

This is not intended for front-end usage. This purpose of this function is to avoid race conditions that could appear while the caches are primed. A good scenario where this could be used is to ensure published posts are not syndicated multiple times by checking if a post with a certain meta value already exists.

Parameters

string $meta_key

Post meta key to query

string $meta_value

Post meta value to check for

string $post_type

Optional; post_type of the post to query. Defaults to 'post'.

array $post_stati

Optional; array of the post_stati that are supposed to be included. Defaults to: publish, draft, pending, private.

integer $limit

Optional. Amount of possible posts to receive; not more than 10. Default is 1.

Returns

array|\WP_Error —

Array with post objects or a WP_Error

wpcom_uncached_get_post_meta()

wpcom_uncached_get_post_meta(integer  $post_id, string  $key, boolean  $single = false) : mixed

Reads a postmeta value directly from the master database.

This is not intended for front-end usage. This purpose of this function is to avoid race conditions that could appear while the caches are primed. A good scenario where this could be used is to ensure published posts are not syndicated multiple times by checking a postmeta flag that is set on syndication.

Note: this looks complicated, but the intention was to use API functions rather than direct DB queries for upward compatibility.

Parameters

integer $post_id

The ID of the post from which you want the data.

string $key

A string containing the name of the meta value you want.

boolean $single

Optional. If set to true then the function will return a single result as a string. If false (the default) the function returns an array.

Returns

mixed —

Value from get_post_meta

wpcom_vip_add_loaded_plugin()

wpcom_vip_add_loaded_plugin(string  $plugin) 

Store the name of a VIP plugin that will be loaded

Parameters

string $plugin

Plugin name and folder

wpcom_vip_add_role()

wpcom_vip_add_role(string  $role, string  $name, array  $capabilities) 

Add a new role

Usage: wpcom_vip_add_role( 'super-editor', 'Super Editor', array( 'level_0' => true ) );

Parameters

string $role

Role name

string $name

Display name for the role

array $capabilities

Key/value array of capabilities for the role

wpcom_vip_add_role_caps()

wpcom_vip_add_role_caps(string  $role, array  $caps) 

Add capabilities to an existing role

Usage: wpcom_vip_add_role_caps( 'contributor', array( 'upload_files' ) );

Parameters

string $role

Role name

array $caps

Capabilities to add to the role

wpcom_vip_add_uri_to_newrelic()

wpcom_vip_add_uri_to_newrelic() 

Add the exact URI to NewRelic tracking but only if we're not in the admin

wpcom_vip_allow_full_size_images_for_real()

wpcom_vip_allow_full_size_images_for_real() 

Overrides a theme's $content_width to remove the image constraint.

wpcom_vip_allow_more_html_in_comments()

wpcom_vip_allow_more_html_in_comments() 

Allows non-author users to submit any tags allowed via $allowedposttags instead of just $allowedtags

wpcom_vip_attachment_cache_key()

wpcom_vip_attachment_cache_key(  $url) 

Parameters

$url

wpcom_vip_attachment_url_to_postid()

wpcom_vip_attachment_url_to_postid(  $url) 

Parameters

$url

wpcom_vip_audio_player_colors()

wpcom_vip_audio_player_colors(  $colors) 

Override default colors of audio player.

Colors specified in the shortcode still can override.

Parameters

$colors

wpcom_vip_bulk_user_management_whitelist()

wpcom_vip_bulk_user_management_whitelist(array  $users) 

Helper function to enable bulk user management on a per-user basis

Parameters

array $users

Array of user logins

wpcom_vip_cache_delete()

wpcom_vip_cache_delete(string  $key, string  $group = '') : boolean

Drop in replacement for wp_cache_delete().

Wrapper for WPCOM Stampedeless_Cache class.

Parameters

string $key

Cache key.

string $group

Optional. Cache group.

Returns

boolean —

True on successful removal, false on failure.

wpcom_vip_cache_full_comment_counts()

wpcom_vip_cache_full_comment_counts(  $counts = false,   $post_id) : boolean|false|mixed|string

Use this function to cache the comment counting in the wp menu that can be slow on sites with lots of comments use like this:

Parameters

$counts
$post_id

Returns

boolean|false|mixed|string

wpcom_vip_cache_get()

wpcom_vip_cache_get(string  $key, string  $group = '') : mixed

Drop in replacement for wp_cache_get().

Wrapper for the WPCOM Stampedeless_Cache class.

Parameters

string $key

Cache key.

string $group

Optional. Cache group.

Returns

mixed —

Returns false if failing to retrieve cache entry or the cached data otherwise.

wpcom_vip_cache_set()

wpcom_vip_cache_set(string  $key, string|integer|array|object  $value, string  $group = '', integer  $expiration) : boolean

Drop in replacement for wp_cache_set().

Wrapper for the WPCOM Stampedeless_Cache class.

Parameters

string $key

Cache key.

string|integer|array|object $value

Data to store in the cache.

string $group

Optional. Cache group.

integer $expiration

Optional. Cache TTL in seconds.

Returns

boolean —

This function always returns true.

wpcom_vip_can_use_shared_plugin()

wpcom_vip_can_use_shared_plugin(string  $plugin) : boolean

Determine if a plugin can be used or not

Parameters

string $plugin

plugin name

Returns

boolean

wpcom_vip_check_site_url()

wpcom_vip_check_site_url(array|string  $site_urls) : boolean

Checks if the current site_url() matches from a specified list.

Parameters

array|string $site_urls

List of site URL hosts to check against

Returns

boolean —

If current site_url() matches one in the list

wpcom_vip_count_user_posts()

wpcom_vip_count_user_posts(  $user_id) 

Cached version of count_user_posts, which is uncached but doesn't always need to hit the db

count_user_posts is generally fast, but it can be easy to end up with many redundant queries if it's called several times per request. This allows bypassing the db queries in favor of the cache

Parameters

$user_id

wpcom_vip_cron_for_newrelic()

wpcom_vip_cron_for_newrelic() 

Name cron correctly in New Relic and do not count it as part of the Apdex score.

We don't want to count cron as part of the apdex because it is not a user facing function and if cron tasks are slow it doesn't imply that the site's performance is impacted. Without removing these, long running cron tasks could flag the site as having performance problems, which would cause false positives in the monitoring.

wpcom_vip_crop_small_thumbnail()

wpcom_vip_crop_small_thumbnail() 

Makes the smallest sized thumbnails be cropped (i.e. the ones used in [gallery]).

We've removed the checkbox from Settings -> Media on WordPress.com, so this re-enables the feature.

wpcom_vip_debug()

wpcom_vip_debug(  $type,   $data) 

Parameters

$type
$data

wpcom_vip_did_elasticsearch_query()

wpcom_vip_did_elasticsearch_query(  $query) 

Parameters

$query

wpcom_vip_disable_custom_customizer()

wpcom_vip_disable_custom_customizer() 

Disables the WordPress.com-specific Customizer and Custom Design

wpcom_vip_disable_default_subscribe_to_comments()

wpcom_vip_disable_default_subscribe_to_comments() 

Sets the default for subscribe to comments to off

wpcom_vip_disable_devicepx_js()

wpcom_vip_disable_devicepx_js() 

Remove devicepx.js from pageloads

devicepx.js loads retina/HiDPI versions of certain files (Gravatars, etc) for devices that run at a higher resolution (such as smartphones), and is distributed inside Jetpack.

wpcom_vip_disable_enhanced_feeds()

wpcom_vip_disable_enhanced_feeds() 

Completely disable enhanced feed functionality

wpcom_vip_disable_geolocation_output()

wpcom_vip_disable_geolocation_output() 

Disables output of geolocation information in "public" locations--post content, meta tags, and feeds.

wpcom_vip_disable_global_terms()

wpcom_vip_disable_global_terms() 

Allow VIP themes to disable global terms on WordPress.com.

wpcom_vip_disable_hovercards()

wpcom_vip_disable_hovercards() 

Allow VIP themes to disable hovercard functionality and removes the scripts.

wpcom_vip_disable_instapost()

wpcom_vip_disable_instapost() 

Diables Instapost functionality

wpcom_vip_disable_likes()

wpcom_vip_disable_likes() 

Disables Jetpack Likes for Posts and Custom Post Types

Sharing can also be disabled from the Dashboard (Settings > Sharing).

This function is primarily for programmatic disabling of the feature, for example when working with custom post types.

wpcom_vip_disable_new_relic_js()

wpcom_vip_disable_new_relic_js() 

Disable New Relic's browser metrics

Removes NR's JavaScript for tracking browser metrics, including page load times, Apdex score, and more.

Must be called at or before the template_redirect action.

wpcom_vip_disable_post_flair()

wpcom_vip_disable_post_flair() 

Disables Jetpack Post Flair entirely on the frontend.

This removes the filters and doesn't allow the stylesheet to be enqueued.

wpcom_vip_disable_postpost()

wpcom_vip_disable_postpost() 

Disable the post-post screen

wpcom_vip_disable_sharing()

wpcom_vip_disable_sharing() 

Disables Jetpack Sharing in Posts and Pages.

Sharing can be disabled in the dashboard, by removing all buttons from Enabled Services.

This function is primary for automating sharing when you have numerous sites to administer. It also assists having consistent CSS containers between development and production.

wpcom_vip_disable_sharing_resources()

wpcom_vip_disable_sharing_resources() 

Disable CSS and JS output for Jetpack Sharing.

Note: this disables things like smart buttons and share counts displayed alongside the buttons. Those will need to be handled manually if desired.

wpcom_vip_disable_smilies()

wpcom_vip_disable_smilies(mixed  $smilies_to_disable) 

Give themes the opportunity to disable WPCOM-specific smilies.

Note: Smilies disabled by this method will not fall back to core smilies.

Parameters

mixed $smilies_to_disable

List of strings that will not be converted into smilies. A single string will be converted to an array & work

wpcom_vip_disable_zemanta_for_all_users()

wpcom_vip_disable_zemanta_for_all_users() 

Helper function to disable the WordPress.com wide Zemanta Tools for all users.

wpcom_vip_download_image()

wpcom_vip_download_image(string  $image_url,   $post_id, string  $description = '', array  $post_data = array()) : \$thumbnail_id

Downloads an external image and optionally attaches it to a post.

Contains most of core's media_sideload_image() but returns an attachment ID instead of HTML.

Note: this function does not validate the domain that the image is coming from. Please make sure to validate this before downloading the image. Should only pull down images from trusted sources.

Parameters

string $image_url

URL of the image.

$post_id
string $description

Description of the image that should be added on upload.

array $post_data

Array of data to be passed to media_handle_sideload.

Returns

\$thumbnail_id —

id of the thumbnail attachment post id

wpcom_vip_duplicate_role()

wpcom_vip_duplicate_role(string  $from_role, string  $to_role_slug, string  $to_role_name, array  $modified_caps) 

Duplicate an existing role and modify some caps

Usage: wpcom_vip_duplicate_role( 'administrator', 'station-administrator', 'Station Administrator', array( 'manage_categories' => false ) );

Parameters

string $from_role

Role name

string $to_role_slug

Role name

string $to_role_name

Display name for the role

array $modified_caps

Key/value array of capabilities for the role

wpcom_vip_email_has_gravatar()

wpcom_vip_email_has_gravatar(string  $email) : boolean

Checks to see if a given e-mail address has a Gravatar or not.

You can use this function to only call get_avatar() when the user has a Gravatar and display nothing (rather than a placeholder image) when they don't.

Parameters

string $email

Email to check for a gravatar

Returns

boolean —

Returns true if $email has a gravatar

wpcom_vip_enable_cache_full_comment_counts()

wpcom_vip_enable_cache_full_comment_counts() 

wpcom_vip_enable_likes()

wpcom_vip_enable_likes() 

Disables Jetpack Likes for Posts and Custom Post Types

This feature is on by default, so the function is only useful if you've also used wpcom_vip_disable_sharing().

wpcom_vip_enable_maybe_skip_old_slug_redirect()

wpcom_vip_enable_maybe_skip_old_slug_redirect() 

wpcom_vip_enable_old_slug_redirect_caching()

wpcom_vip_enable_old_slug_redirect_caching() 

wpcom_vip_enable_opengraph()

wpcom_vip_enable_opengraph() 

Outputs Open Graph tags to various pages on the site

wpcom_vip_enable_sharing()

wpcom_vip_enable_sharing() 

Enables Jetpack Sharing in Posts and Pages.

This feature is on by default, so the function is only useful if you've also used wpcom_vip_disable_sharing().

wpcom_vip_enable_sharing_resources()

wpcom_vip_enable_sharing_resources() 

Enable CSS and JS output for WPCOM sharing.

Note: if resources were disabled previously and this is called after wp_head, it may not work as expected.

wpcom_vip_enable_term_order_functionality()

wpcom_vip_enable_term_order_functionality() : boolean

Deprecated function. This used to work around a term ordering issue on a very old version of WordPress. No longer needed.

Returns

boolean —

Always returns false

wpcom_vip_file_get_contents()

wpcom_vip_file_get_contents(string  $url, integer  $timeout = 3, integer  $cache_time = 900, array  $extra_args = array()) : string

Fetch a remote URL and cache the result for a certain period of time.

This function originally used file_get_contents(), hence the function name. While it no longer does, it still operates the same as the basic PHP function.

We strongly recommend not using a $timeout value of more than 3 seconds as this function makes blocking requests (stops page generation and waits for the response).

The $extra_args are:

Parameters

string $url

URL to fetch

integer $timeout

Optional. The timeout limit in seconds; valid values are 1-10. Defaults to 3.

integer $cache_time

Optional. The minimum cache time in seconds. Valid values are >= 60. Defaults to 900.

array $extra_args

Optional. Advanced arguments: "obey_cache_control_header" and "http_api_args".

Returns

string —

The remote file's contents (cached)

wpcom_vip_flaptor_related_posts()

wpcom_vip_flaptor_related_posts(integer  $max_num = 5, array  $additional_stopwords = array(), boolean  $exclude_own_titles = true) : string

VIP Legacy Related Posts (HTML formatted results)

Don't use for new projects, just use WPCOM_RelatedPosts directly, since it has hooks like jetpack_relatedposts_filter_args, jetpack_relatedposts_filter_filters

Parameters

integer $max_num

Optional. Maximum number of results you want (default: 5).

array $additional_stopwords

No longer used, we leave the stopwords magic to ES which knows more about word frequencies across articles.

boolean $exclude_own_titles

No longer used.

Returns

string —

Returns an HTML unordered list of related posts from the same blog.

wpcom_vip_flush_get_page_by_path_cache()

wpcom_vip_flush_get_page_by_path_cache(string  $new_status, string  $old_status, \WP_Post  $post) 

Flush the cache for published pages so we don't end up with stale data

Parameters

string $new_status

The post's new status

string $old_status

The post's previous status

\WP_Post $post

The post

wpcom_vip_flush_get_page_by_title_cache()

wpcom_vip_flush_get_page_by_title_cache(string  $new_status, string  $old_status, \WP_Post  $post) 

Flush the cache for published pages so we don't end up with stale data

Parameters

string $new_status

The post's new status

string $old_status

The post's previous status

\WP_Post $post

The post

wpcom_vip_flush_wp_old_slug_redirect_cache()

wpcom_vip_flush_wp_old_slug_redirect_cache(  $post_id,   $post,   $post_before) 

Parameters

$post_id
$post
$post_before

wpcom_vip_get_adjacent_post()

wpcom_vip_get_adjacent_post(boolean  $in_same_term = false,   $excluded_terms = '', boolean  $previous = true, string  $taxonomy = 'category',   $adjacent = '') : null|string|\WP_Post

Retrieve adjacent post.

Can either be next or previous post. The logic for excluding terms is handled within PHP, for performance benefits. Props to Elliott Stocks

Parameters

boolean $in_same_term

Optional. Whether post should be in a same taxonomy term. Note - only the first term will be used from wp_get_object_terms().

$excluded_terms
boolean $previous

Optional. Whether to retrieve previous post.

string $taxonomy

Optional. Taxonomy, if $in_same_term is true. Default 'category'.

$adjacent

Returns

null|string|\WP_Post —

Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.

wpcom_vip_get_category_by_slug()

wpcom_vip_get_category_by_slug(string  $slug) : object|null|boolean

Cached version of get_category_by_slug.

Parameters

string $slug

Category slug

Returns

object|null|boolean —

Term Row from database. Will return null if $slug doesn't match a term. If taxonomy does not exist then false will be returned.

wpcom_vip_get_flaptor_related_posts()

wpcom_vip_get_flaptor_related_posts(integer  $max_num = 5, array  $additional_stopwords = array(), boolean  $exclude_own_titles = true) : array

VIP Legacy Related Posts (get post_id, title, url)

Don't use for new projects, just use WPCOM_RelatedPosts directly, since it has hooks like jetpack_relatedposts_filter_args, jetpack_relatedposts_filter_filters

For backwards compatability, this function finds related posts on the current blog using Elasticsearch, then converts the results to match the original sphere results format.

Parameters

integer $max_num

Optional. Maximum number of results you want (default: 5).

array $additional_stopwords

No longer used.

boolean $exclude_own_titles

No longer used.

Returns

array —

of related posts.

wpcom_vip_get_home_host()

wpcom_vip_get_home_host() : string

Returns the HTTP_HOST for the current site's home_url()

Returns

string

wpcom_vip_get_loaded_plugins()

wpcom_vip_get_loaded_plugins() : array

Get the names of VIP plugins that have been loaded

Returns

array

wpcom_vip_get_meta_desc()

wpcom_vip_get_meta_desc() : string

Filter this function to change the meta description value set by wpcom_vip_meta_desc().

Can be configured to use either first X chars/words of the post content or post excerpt if available Can use category description for category archive pages if available Can use tag description for tag archive pages if available Can use blog description for everything else Can use a default description if no suitable value is found Can use the value of a custom field as description

Usage: // add a custom configuration via filter function set_wpcom_vip_meta_desc_settings( $settings ) { return array( 'length' => 10, 'length_unit' => 'char|word', 'use_excerpt' => true, 'add_category_desc' => true, 'add_tag_desc' => true, 'add_other_desc' => true, 'default_description' => '', 'custom_field_key' => '' ); } add_filter( 'wpcom_vip_meta_desc_settings', 'set_wpcom_vip_meta_desc_settings' ); add_action( 'wp_head', 'wpcom_vip_meta_desc' );

Returns

string —

The meta description

wpcom_vip_get_most_shared_posts()

wpcom_vip_get_most_shared_posts(integer  $limit = 5, integer  $cache_duration = 3600) : array

Get the most shared posts of the current blog, ordered DESC by share count

Parameters

integer $limit

Optional. Number of posts to retrieve. Defaults to 5.

integer $cache_duration

Optional. Length of time to cache the query. Defaults to 3600.

Returns

array —

Array of most shared post IDs

wpcom_vip_get_nav_menu_object()

wpcom_vip_get_nav_menu_object(  $menu) 

Parameters

$menu

wpcom_vip_get_page_by_path()

wpcom_vip_get_page_by_path(string  $page_path, string  $output = OBJECT, string  $post_type = 'page') : \WP_Post|null

Cached version of get_page_by_path so that we're not making unnecessary SQL all the time

Parameters

string $page_path

Page path

string $output

Optional. Output type; OBJECT*, ARRAY_N, or ARRAY_A.

string $post_type

Optional. Post type; default is 'page'.

Returns

\WP_Post|null —

WP_Post on success or null on failure

wpcom_vip_get_page_by_title()

wpcom_vip_get_page_by_title(  $title, string  $output = OBJECT, string  $post_type = 'page') : \WP_Post|null

Cached version of get_page_by_title so that we're not making unnecessary SQL all the time

Parameters

$title
string $output

Optional. Output type; OBJECT*, ARRAY_N, or ARRAY_A.

string $post_type

Optional. Post type; default is 'page'.

Returns

\WP_Post|null —

WP_Post on success or null on failure

wpcom_vip_get_post_pageviews()

wpcom_vip_get_post_pageviews(integer  $post_id = null, integer  $num_days = 1,   $end_date = false) : integer|false

Get the number of pageviews for a given post ID (defaults to the current post)

Note that it is not currently possible to retrieve the post views for the homepage using this function

Parameters

integer $post_id

Optional. The post ID to fetch stats for. Defaults to the $post global's value.

integer $num_days

Optional. How many days to go back to include in the stats. Default is 1. Maximum 90 days.

$end_date

Returns

integer|false —

Number of pageviews or false on error.

wpcom_vip_get_resized_attachment_url()

wpcom_vip_get_resized_attachment_url(integer  $attachment_id, integer  $width, integer  $height, boolean  $crop = false) : string

Returns a URL for a given attachment with the appropriate resizing querystring.

Typically, you should be using image sizes for handling this.

However, this function can come in handy if you want a specific artibitrary or varying image size.

Parameters

integer $attachment_id

ID of the attachment

integer $width

Width of our resized image

integer $height

Height of our resized image

boolean $crop

(optional) whether or not to crop the image

Returns

string —

URL of the resized attachmen

wpcom_vip_get_resized_remote_image_url()

wpcom_vip_get_resized_remote_image_url(string  $url, integer  $width, integer  $height, boolean  $escape = true) : string

Returns the URL to an image resized and cropped to the given dimensions.

You can use this image URL directly -- it's cached and such by our servers. Please use this function to generate the URL rather than doing it yourself as this function uses staticize_subdomain() makes it serve off our CDN network.

Somewhat contrary to the function's name, it can be used for ANY image URL, hosted by us or not. So even though it says "remote", you can use it for attachments hosted by us, etc.

Parameters

string $url

The raw URL to the image (URLs that redirect are currently not supported with the exception of http://foobar.wordpress.com/files/ type URLs)

integer $width

The desired width of the final image

integer $height

The desired height of the final image

boolean $escape

Optional. If true (the default), the URL will be run through esc_url(). Set this to false if you need the raw URL.

Returns

string

wpcom_vip_get_role_caps()

wpcom_vip_get_role_caps(string  $role) : array

Get a list of capabilities for a role.

Parameters

string $role

Role name

Returns

array —

Array of caps for the role

wpcom_vip_get_stats_array()

wpcom_vip_get_stats_array(string  $table = 'views',   $end_date = false, integer  $num_days = 1, string  $and = '', integer  $limit = 5, boolean  $summarize = NULL) : array

Get the WP.com stats

Parameters

string $table

Optional. Table for stats can be views, postviews, authorviews, referrers, searchterms, clicks. Default is views.

$end_date
integer $num_days

Optional. The length of the desired time frame. Default is 1. Maximum 90 days

string $and

Optional. Possibility to refine the query with additional AND condition. Usually unused.

integer $limit

Optional. The maximum number of records to return. Default is 5. Maximum 100.

boolean $summarize

If present, summarizes all matching records.

Returns

array —

Result as array.

wpcom_vip_get_stats_csv()

wpcom_vip_get_stats_csv(string  $table = 'views',   $end_date = false, integer  $num_days = 1, string  $and = '', integer  $limit = 5, boolean  $summarize = NULL) : string

Get the WP.com stats as CSV

Strings containing double quotes, commas, or "\n" are enclosed in double-quotes. Double-quotes in strings are escaped by inserting another double-quote. Example: "pet food" recipe Becomes: """pet food"" recipe"

Parameters

string $table

Optional. Table for stats can be views, postviews, referrers, searchterms, clicks. Default is views.

$end_date
integer $num_days

Optional. The length of the desired time frame. Default is 1. Maximum 90 days

string $and

Optional. Possibility to refine the query with additional AND condition. Usually unused.

integer $limit

Optional. The maximum number of records to return. Default is 5. Maximum 100.

boolean $summarize

Optional. If present, summarizes all matching records.

Returns

string —

Result format is CSV with one row per line and column names in first row.

wpcom_vip_get_stats_xml()

wpcom_vip_get_stats_xml(string  $table = 'views',   $end_date = false, integer  $num_days = 1, string  $and = '', integer  $limit = 5, boolean  $summarize = NULL) : string

Get the WP.com stats as XML

Parameters

string $table

Optional. Table for stats can be views, postviews, referrers, searchterms, clicks. Default is views.

$end_date
integer $num_days

Optional. The length of the desired time frame. Default is 1. Maximum 90 days

string $and

Optional. Possibility to refine the query with additional AND condition. Usually unused.

integer $limit

Optional. The maximum number of records to return. Default is 5. Maximum 100.

boolean $summarize

Optional. If present, summarizes all matching records.

Returns

string —

Result format is XML dataset.

wpcom_vip_get_term_by()

wpcom_vip_get_term_by(string  $field, string|integer  $value, string  $taxonomy, string  $output = OBJECT, string  $filter = 'raw') : mixed|null|boolean

Cached version of get_term_by.

Many calls to get_term_by (with name or slug lookup) across on a single pageload can easily add up the query count. This function helps prevent that by adding a layer of caching.

Parameters

string $field

Either 'slug', 'name', or 'id'

string|integer $value

Search for this term value

string $taxonomy

Taxonomy Name

string $output

Optional. Constant OBJECT, ARRAY_A, or ARRAY_N

string $filter

Optional. Default is 'raw' or no WordPress defined filter will applied.

Returns

mixed|null|boolean —

Term Row from database in the type specified by $filter. Will return false if $taxonomy does not exist or $term was not found.

wpcom_vip_get_term_link()

wpcom_vip_get_term_link(integer|string|object  $term, string  $taxonomy = null) : string|\WP_Error

Optimized version of get_term_link that adds caching for slug-based lookups.

Returns permalink for a taxonomy term archive, or a WP_Error object if the term does not exist.

Parameters

integer|string|object $term

The term object / term ID / term slug whose link will be retrieved.

string $taxonomy

The taxonomy slug. NOT required if you pass the term object in the first parameter

Returns

string|\WP_Error —

HTML link to taxonomy term archive on success, WP_Error if term does not exist.

wpcom_vip_get_user_profile()

wpcom_vip_get_user_profile(string|integer  $email_or_id) : false|array

Returns profile information for a WordPress/Gravatar user

Parameters

string|integer $email_or_id

Email, ID, or username for user to lookup

Returns

false|array —

Profile info formatted as noted here: http://en.gravatar.com/site/implement/profiles/php/. If user not found, returns false.

wpcom_vip_home_template_uri()

wpcom_vip_home_template_uri(string  $path) 

Get the URL of theme files relative to the home_url

Parameters

string $path

The path of the file to get a URL for

wpcom_vip_https_canonical_url()

wpcom_vip_https_canonical_url() 

Use secure URLs in rel_canonical

wpcom_vip_irc()

wpcom_vip_irc(  $channel_or_user,   $message,   $level,   $kind = '',   $interval) 

Send a message to IRC

$level can be an int of one of the following NONE = 0 WARNING = 1 ALERT = 2 CRITICAL = 3 RECOVERY = 4 INFORMATION = 5 SCALE = 6

Example Usage

wpcom_vip_irc( '@testuser', 'test message' ); // send testuser a pm on IRC from "a8c" wpcom_vip_irc( '@testuser', 'test message', 3 ); // send testuser a pm on IRC with level 'critical' wpcom_vip_irc( 'testing', 'test message' ); // have "a8c" join #testing and say something wpcom_vip_irc( 'testing', 'test message', 4 ); // have "a8c-test" join #testing and say something with level 'recovery'

Parameters

$channel_or_user
$message

(string) Message

$level

(int) Level The severity level of the message

$kind

string Cache slug

$interval

integer Interval in seconds between two messages sent from one DC

wpcom_vip_is_feedservice_ua()

wpcom_vip_is_feedservice_ua() : boolean

Returns if the current visitor has a feed service user agent

Returns

boolean —

Returns true if the current visitor has a feed service user agent.

wpcom_vip_is_main_feed_requested()

wpcom_vip_is_main_feed_requested() : boolean

Returns if any of the formats of the main feed are requested

Returns

boolean —

Returns true if main feed is requested

wpcom_vip_is_valid_domain()

wpcom_vip_is_valid_domain(string  $url, array  $whitelisted_domains) : boolean

Check if a URL is in a specified whitelist

Example whitelist: array( 'mydomain.com', 'mydomain.net' )

Parameters

string $url

URL to check for

array $whitelisted_domains

Array of whitelisted domains

Returns

boolean —

Returns true if $url is in the $whitelisted_domains

wpcom_vip_load_category_base()

wpcom_vip_load_category_base(string  $new_category_base) 

Enables a custom or no category base, if the site wants to use one that's not the WP.com default (/category/)

Usage: wpcom_vip_load_category_base( '' ); wpcom_vip_load_category_base( 'section' );

Parameters

string $new_category_base

New category base prefix

wpcom_vip_load_custom_cdn()

wpcom_vip_load_custom_cdn(array  $args) 

Use a custom CDN host for displaying theme images and media library content.

Please get in touch before using this as it can break your site.

Parameters

array $args

Array of args string|array cdn_host_media => Hostname of the CDN for media library assets. string|array cdn_host_static => Optional. Hostname of the CDN for static assets. bool include_admin => Optional. Whether the custom CDN host should be used in the admin context as well. bool disable_ssl => Optional. Whether SSL should be disabled for the custom CDN.

wpcom_vip_load_geolocation_styles_only_when_needed()

wpcom_vip_load_geolocation_styles_only_when_needed() 

Conditionally dequeues the geo-location-flair.css

wpcom_vip_load_helper()

wpcom_vip_load_helper() 

Loads the shared VIP helper file which defines some helpful functions.

wpcom_vip_load_helper_stats()

wpcom_vip_load_helper_stats() 

Loads the WordPress.com-only VIP helper file for stats which defines some helpful stats-related functions.

wpcom_vip_load_helper_wpcom()

wpcom_vip_load_helper_wpcom() 

Loads the WordPress.com-only VIP helper file which defines some helpful functions.

wpcom_vip_load_helpers_for_network_active_plugins()

wpcom_vip_load_helpers_for_network_active_plugins() 

Load `vipgo-helper.php` if it exists for a network-activated plugin

Technically tries to include the main plugin file again, but we don't care, because it uses include_once() and is called after Core loads the plugin

wpcom_vip_load_helpers_for_sites_core_plugins()

wpcom_vip_load_helpers_for_sites_core_plugins() 

Load `vipgo-helper.php` if it exists for a plugin loaded outside of our custom UI and helpers

Technically tries to include the main plugin file again, but we don't care, because it uses include_once() and is called after Core loads the plugin

wpcom_vip_load_permastruct()

wpcom_vip_load_permastruct(string  $new_permastruct) 

Enables a custom permastruct, if the site wants to use one that's not the WP.com default (/yyyy/mm/dd/post-name/)

Usage: wpcom_vip_load_permastruct( '/%category%/%postname%/' );

Parameters

string $new_permastruct

wpcom_vip_load_plugin()

wpcom_vip_load_plugin(string  $plugin = false, string  $folder = false,   $load_release_candidate_not_used = null) : boolean

Loads a plugin from your plugins folder.

Note - This function does not trigger plugin activation / deactivation hooks. As such, it may not be compatible with all plugins

Parameters

string $plugin

Optional. Plugin folder name of the plugin, or the folder and plugin file name (such as wp-api/plugin.php), relative to either the VIP shared-plugins folder, or WP_PLUGIN_DIR

string $folder

Subdirectory of WP_PLUGIN_DIR to load plugin from

$load_release_candidate_not_used

Returns

boolean —

True if the include was successful

wpcom_vip_load_tag_base()

wpcom_vip_load_tag_base(string  $new_tag_base) 

Enables a custom or no tag base, if the site wants to use one that's not the WP.com default (/tag/)

Usage: wpcom_vip_load_tag_base( 'section' );

Parameters

string $new_tag_base

New tag base prefix

wpcom_vip_maybe_skip_old_slug_redirect()

wpcom_vip_maybe_skip_old_slug_redirect() 

Potentially skip redirect for old slugs.

We're seeing an increase of URLs that match this pattern: http://example.com/http://othersite.com/random_text.

These then cause really slow lookups inside of wp_old_slug_redirect. Since wp_old_slug redirect does not match on full URLs but rather former slugs, it's safe to skip the lookup for these. Most of the calls are from bad ad providers that generate random URLs.

wpcom_vip_merge_role_caps()

wpcom_vip_merge_role_caps(string  $role, array  $caps) 

Add new or change existing capabilities for a given role

Usage: wpcom_vip_merge_role_caps( 'author', array( 'publish_posts' => false ) );

Parameters

string $role

Role name

array $caps

Key/value array of capabilities for this role

wpcom_vip_meta_desc()

wpcom_vip_meta_desc() 

Automatically insert meta description tag into posts/pages.

You shouldn't need to use this function nowadays because WordPress.com and Jetpack takes care of this for you.

wpcom_vip_noncdn_uri()

wpcom_vip_noncdn_uri(string  $path) : string

Returns the non-CDN'd URI to the specified path.

Parameters

string $path

Must be a full path, e.g. dirname( FILE )

Returns

string

wpcom_vip_notify_on_new_user_added_to_site()

wpcom_vip_notify_on_new_user_added_to_site(array  $emails) 

Sends an e-mail when a new user accepts an invite to join a site.

Parameters

array $emails

Array of email address to notify when a user accepts an invitation to a site

wpcom_vip_old_slug_redirect()

wpcom_vip_old_slug_redirect() 

Cached version of wp_old_slug_redirect.

Cache the results of the _wp_old_slug meta query, which can be expensive.

wpcom_vip_override_role_caps()

wpcom_vip_override_role_caps(string  $role, array  $caps) 

Completely override capabilities for a given role

Usage: wpcom_vip_override_role_caps( 'editor', array( 'level_0' => false ) );

Parameters

string $role

Role name

array $caps

Key/value array of capabilities for this role

wpcom_vip_plugin_is_loaded()

wpcom_vip_plugin_is_loaded(string  $plugin) : boolean

Check if plugin is loaded

Parameters

string $plugin

Plugin name and folder

Returns

boolean

wpcom_vip_plugins_ui_disable_activation()

wpcom_vip_plugins_ui_disable_activation() 

If you don't want people (de)activating plugins via this UI and only want to enable plugins via wpcom_vip_load_plugin() calls in your theme's functions.php file, then call this function to disable this plugin's (de)activation links.

wpcom_vip_plugins_url()

wpcom_vip_plugins_url(string  $url = '', string  $path = '', string  $plugin = '') : string

Filter plugins_url() so that it works for plugins inside the shared VIP plugins directory or a theme directory.

Props to the GigaOm dev team for coming up with this method.

Parameters

string $url

Optional. Absolute URL to the plugins directory.

string $path

Optional. Path relative to the plugins URL.

string $plugin

Optional. The plugin file that you want the URL to be relative to.

Returns

string

wpcom_vip_purge_edge_cache_for_post()

wpcom_vip_purge_edge_cache_for_post(object|integer  $post) : boolean

Clear the VIP Go edge cache at the URLs associated with a post

This includes:

  • The singular Post URL
  • The homepage
  • Main site posts feed
  • Main site comments feed
  • The archive URLs for all terms associated with the post, paged back five pages as default
  • The feeds for all terms associated with the post

You can filter how many of the pages of the archives are cleared using the wpcom_vip_cache_purge_urls_max_pages filter.

Parameters

object|integer $post

Either the WP Post object, or the post ID

Returns

boolean —

True on success

wpcom_vip_purge_edge_cache_for_term()

wpcom_vip_purge_edge_cache_for_term(object|integer  $term) : boolean

Clear the VIP Go edge cache at the URLs associated with a term

This includes:

  • The term archive URL, paged back five pages as default
  • The term feed

You can filter how many of the pages of the archives are cleared using the wpcom_vip_cache_purge_urls_max_pages filter.

Parameters

object|integer $term

Either the WP Term object, or the term_id

Returns

boolean —

True on success

wpcom_vip_purge_edge_cache_for_url()

wpcom_vip_purge_edge_cache_for_url(string  $url) : boolean

Clear the VIP Go edge cache for a specific URL

Parameters

string $url

The specific URL to purge the cache for

Returns

boolean —

True on success

wpcom_vip_refresh_wp_rewrite()

wpcom_vip_refresh_wp_rewrite() 

VIPs and other themes can declare the permastruct, tag and category bases in their themes.

This is done by filtering the option.

To ensure we're using the freshest values, and that the option value is available earlier than when the theme is loaded, we need to get each option, save it again, and then reinitialize wp_rewrite.

This is most commonly used in our code to flush rewrites

wpcom_vip_remove_feed_tracking_bug()

wpcom_vip_remove_feed_tracking_bug() 

Remove the tracking bug added to all WordPress.com feeds.

wpcom_vip_remove_livechat()

wpcom_vip_remove_livechat() 

Disables Olark live chat

wpcom_vip_remove_mediacontent_from_rss2_feed()

wpcom_vip_remove_mediacontent_from_rss2_feed() 

Removes the <media:content> tags from the RSS2 feed.

You should really call this when creating a custom feed (best to leave them in your normal feed).

wpcom_vip_remove_opensearch()

wpcom_vip_remove_opensearch() 

wpcom_vip_remove_playlist_styles()

wpcom_vip_remove_playlist_styles() 

Dequeue wp-mediaelement.css for sites which don't use the playlist shortcode and thus don't need the stylesheet

wpcom_vip_remove_polldaddy_rating()

wpcom_vip_remove_polldaddy_rating() 

Do not display the Polldaddy rating.

Usually used for a page or post where ratings are not wanted.

wpcom_vip_remove_role_caps()

wpcom_vip_remove_role_caps(string  $role, array  $caps) 

Remove capabilities from an existing role

Usage: wpcom_vip_remove_role_caps( 'author', array( 'publish_posts' ) );

Parameters

string $role

Role name

array $caps

Capabilities to remove from the role

wpcom_vip_require_lib()

wpcom_vip_require_lib(string  $slug) 

Require a library in the VIP shared code library.

Parameters

string $slug

wpcom_vip_rest_routes_for_newrelic()

wpcom_vip_rest_routes_for_newrelic(  $dispatch_results,   $request,   $route,   $handler) 

Name wp-api requests correctly in New Relic

By default wp-api requests are tagged under index.php We'd want to have them tagged with the proper rest route used. While we are using the rest_dispatch_request filter, we're using it as an action without modifying the results.

Parameters

$dispatch_results
$request
$route
$handler

wpcom_vip_set_image_quality()

wpcom_vip_set_image_quality(integer  $quality, string  $strip = false) 

Set the quality of jpeg images served from files.wordpress.com

On files.wordpress.com, we accept quality and strip as query parameters. wpcom_vip_set_image_quality sets these parameters on all jpeg images served from files.wordpress.com

Parameters

integer $quality

The quality of the image out of 100.

string $strip

What data to strip: exif|color|all

wpcom_vip_set_image_quality_for_url()

wpcom_vip_set_image_quality_for_url(  $attachment_url, integer  $quality = 100, string  $strip = false) : string

Set the quality of a jpeg image

Parameters

$attachment_url
integer $quality

The quality of the image out of 100.

string $strip

What data to strip: exif|color|all

Returns

string —

A url with proper quality and strip query parameters

wpcom_vip_set_old_slug_redirect_cache()

wpcom_vip_set_old_slug_redirect_cache(  $link) 

Parameters

$link

wpcom_vip_sharing_twitter_via()

wpcom_vip_sharing_twitter_via(string  $via = '') 

Allows you to customize the /via and follow recommendation for the WP.com Sharing Twitter button.

Parameters

string $via

Optional. What the /via should be set to. Empty value disables the feature (the default).

wpcom_vip_should_load_plugins()

wpcom_vip_should_load_plugins() 

Helper function to check if we can load plugins or not.

wpcom_vip_stats_roles()

wpcom_vip_stats_roles(array  $roles) 

Set the roles that can view stats

Parameters

array $roles

The roles that can view stats

wpcom_vip_term_exists()

wpcom_vip_term_exists(integer|string  $term, string  $taxonomy = '', integer  $parent = null) : mixed

Cached version of term_exists()

Term exists calls can pile up on a single pageload. This function adds a layer of caching to prevent lots of queries.

Parameters

integer|string $term

The term to check can be id, slug or name.

string $taxonomy

The taxonomy name to use

integer $parent

Optional. ID of parent term under which to confine the exists search.

Returns

mixed —

Returns null if the term does not exist. Returns the term ID if no taxonomy is specified and the term ID exists. Returns an array of the term ID and the term taxonomy ID the taxonomy is specified and the pairing exists.

wpcom_vip_theme_dir()

wpcom_vip_theme_dir(string  $theme = '') : string

Return the directory path for a given VIP theme

Parameters

string $theme

Optional. Name of the theme folder

Returns

string —

Path for the specified theme

wpcom_vip_theme_url()

wpcom_vip_theme_url(string  $path = '', string  $theme = '') : string|boolean

Return a URL for given VIP theme and path. Does not work with VIP shared plugins.

Parameters

string $path

Optional. Path to suffix to the theme URL.

string $theme

Optional. Name of the theme folder.

Returns

string|boolean —

URL for the specified theme and path. If path doesn't exist, returns false.

wpcom_vip_themes_root()

wpcom_vip_themes_root() : string

Returns the raw path to the VIP themes dir.

Returns

string

wpcom_vip_themes_root_uri()

wpcom_vip_themes_root_uri() : string

Returns the non-CDN URI to the VIP themes dir.

Sometimes enqueuing/inserting resources can trigger cross-domain errors when using the CDN, so this function allows bypassing the CDN to eradicate those unwanted errors.

Returns

string —

The URI

wpcom_vip_top_post_title()

wpcom_vip_top_post_title(integer  $days = 2) 

Prints the title of the most popular blog post

Parameters

integer $days

Optional. Number of recent days to find the most popular posts from. Minimum of 2.

wpcom_vip_top_posts_array()

wpcom_vip_top_posts_array(integer  $num_days = 30, integer  $limit = 10, string|boolean  $end_date = false) : array

Get the top posts by page view, using Jetpack's Stats module.

Reproduces the result of /wp-admin/index.php?page=stats&blog=&view=postviews&numdays=30&summarize returning the top 10 posts if called with default params.

Parameters

integer $num_days

The length of the desired time frame. Default is 30. Maximum 90 days.

integer $limit

The maximum number of records to return. Default is 10. Maximum 100.

string|boolean $end_date

The last day of the desired time frame. Format is 'Y-m-d' (e.g. 2007-05-01) and default is UTC date.

Returns

array —

{ An array of post view data, each post as an array

 array {
     The post view data for a single post

     @type int    $post_id        The ID of the post (note 0 is used for the homepage)
     @type string $post_title     The title of the post
     @type string $post_permalink The permalink for the post
     @type int    $views          The number of views for the post within the $num_days specified
 }

}

wpcom_vip_url_to_postid()

wpcom_vip_url_to_postid(string  $url) : integer

Cached version of url_to_postid, which can be expensive.

Examine a url and try to determine the post ID it represents.

Parameters

string $url

Permalink to check.

Returns

integer —

Post ID, or 0 on failure.

wpcom_vip_wp_oembed_get()

wpcom_vip_wp_oembed_get(string  $url, array  $args = array(), integer  $ttl = false) : string

A version of wp_oembed_get() that provides caching.

Note that if you're using this within the contents of a post, it's probably better to use the existing WordPress functionality: http://codex.wordpress.org/Embeds. This helper function is more meant for other places, such as sidebars.

Parameters

string $url

The URL that should be embedded

array $args

Addtional arguments and parameters the embed

integer $ttl

How long to cache for in seconds; minimum 18000 (5 Hours)

Returns

string

wpcom_vip_wp_old_slug_redirect()

wpcom_vip_wp_old_slug_redirect() 

This works by first looking in the cache to see if there is a value saved based on the name query var.

If one is found, redirect immediately. If nothing is found, including that there is no already cache "not_found" value we then add a hook to old_slug_redirect_url so that when the 'rea' wp_old_slug_redirect is run it will store the value in the cache @see wpcom_vip_set_old_slug_redirect_cache(). If we found a not_found we remove the template_redirect so the slow query is not run.

wpcom_vip_wpcli_for_newrelic()

wpcom_vip_wpcli_for_newrelic() 

Name wp-cli correctly in New Relic and do not count it as part of the Apdex score

We don't want to count ongoing WP-CLI requests as part of the apdex because it is not a user facing function and if a WP-CLI request is slow it doesn't imply that the site's performance is impacted. Without removing these WP-CLI requests from the apdex calculation it could flag the site as having performance problems, which would cause false positives in the monitoring.