#23: wp_sprintf_l

The wp_sprintf_l filter allows you to modify the default list item separators used in lists employing the %l specifier — such as when using the the_taxonomies() template tag. When we say “separators”, we’re talking about the punctuation and/or punctuation + words used to grammatically space items in a list.

For example:

  • If there are two taxonomy terms, the separator would be ‘ and ‘, e.g. ‘Something and Something Else’
  • If there are three or more terms, the separator ‘, ‘ would be used up until the last term, then the separator used would be ‘, and ‘, e.g. ‘Something, Something Else, and Something Else Again’

It is evaluated in wp_sprintf_l() in the wp-includes/formatting.php file. wp_sprintf_l() exists to make these default item separators localizable for different languages.

Important note: You should exercise caution modifying the default separators as translators use them as a guide.

wp_sprintf_l accepts a single argument that takes the form of an array. Each key/value pair in the array specifies a different type of list item separator:

  • 'between' => ', '
  • 'between_last_two' => ', and '
  • 'between_only_two' => ' and '

Example:

Let’s say you’re one of those people who just can’t stand the serial/Oxford comma, the following will modify the between_last_two key in the wp_sprint_l separators array.

View the code example on Gist.

#22: http_request_timeout

The http_request_timeout filter allows you to set the http request timeout duration in seconds.

It is evaluated in WP_http::request() method, which has a helper function, wp_remote_request() in the wp-includes/http.php file.

http_request_timeout accepts a single argument in the form of an integer that specifies the timeout duration in seconds.

Example:

The following example extends the timeout duration from 5 seconds to 30 seconds.

View the code example on Gist.

#21: xmlrpc_default_taxonomy_fields

The xmlrpc_default_taxonomy_fields XML-RPC filter allows you to modify the default array of taxonomy fields to be retrieve with various methods.

It is evaluated in the wp.getTaxonomy() and wp.getTaxonomies() XML-RPC methods in the wp-includes/class-wp-xmlrpc-server.php file.

xmlrpc_default_taxonomy_fields accepts 2 arguments:

  1. array An array of taxonomy fields to retrieve, defaults to labels, cap, and object_type
  2. string wp.getTaxonomy|getTaxonomies The method name with wp namespace

Example:

Let’s say you’re using the wp.getTaxonomy() or wp.getTaxonomies() method to retrieve taxonomy data for an XML-RPC project. And let’s say for some reason you won’t need to retrieve a taxonomy’s label data — maybe it’s for private use only or something. The following limits the taxonomy fields retrieved to cap, and object_type.

View the code example on Gist.