Skip to content

Instantly share code, notes, and snippets.

@DrewAPicture
Last active December 21, 2015 23:19
Show Gist options
  • Save DrewAPicture/6381149 to your computer and use it in GitHub Desktop.
Save DrewAPicture/6381149 to your computer and use it in GitHub Desktop.
Functional array docs ideas
<?php
/**
* @param array $date_query {
* @type string 'column' (optional) Column to query against, default is 'post_date'.
* @type string 'compare' (optional) Comparison operator, defaul is '='. @see WP_Date_Query::get_compare()
* @type string 'relation' (optional) How the sub-arrays should be compared, accepts 'AND' (default) or 'OR'.
* }
<?php
/**
* Short description (no period)
*
* Long description.
*
* @access (only if private)
* @since x.x.x
*
* @param type $var Description.
* @param array $args { // Add (optional) after variable if optional
* @type type 'array_key' Description (default <value>, accepts <value>, <value>).
* @type type 'array_key' Description.
* }
* @param type $var Description.
* @return type Description.
*/
<?php
/**
* $date_query = new WP_Date_Query( array(
* 'column' => 'optional, column to query against, default is post_date',
* 'compare' => 'optional, see WP_Date_Query::get_compare()',
* 'relation' => 'optional, OR or AND, how the sub-arrays should be compared, default is AND',
* array(
* 'column' => 'see above',
* 'compare' => 'see above',
* 'after' => 'string or array, see WP_Date_Query::build_mysql_datetime()',
* 'before' => 'string or array, see WP_Date_Query::build_mysql_datetime()',
* 'inclusive' => 'boolean, for after/before, whether exact value should be matched or not',
* 'year' => '4 digit int',
* 'month' => 'int, 1-12',
* 'week' => 'int, 0-53',
* 'day' => 'int, 1-31',
* 'hour' => 'int, 0-23',
* 'minute' => 'int, 0-60',
* 'second' => 'int, 0-60',
*
* ),
* array(
* ...
* ),
* ...
* ) );
<?php
/**
* Retrieve the raw response from the HTTP request.
*
* The array structure is a little complex.
*
* <code>
* $res = array(
* 'headers' => array(),
* 'response' => array(
* 'code' => int,
* 'message' => string
* ) );
* </code>
*
* All of the headers in $res['headers'] are with the name as the key and the
* value as the value. So to get the User-Agent, you would do the following.
*
* <code>
* $user_agent = $res['headers']['user-agent'];
* </code>
*
* The body is the raw response content and can be retrieved from $res['body'].
*
* This function is called first to make the request and there are other API
* functions to abstract out the above convoluted setup.
*
* @since 2.7.0
*
* @param string $url Site URL to retrieve.
* @param array $args (optional) {
* @type string 'method' The type of request (default 'GET', accepts 'GET', 'POST', 'HEAD').
* @type string 'timeout' The timeout duration, default is 5.
* @type string 'redirection' The redirection duration, default is 5.
* @type string 'httpversion' The HTTP version to use, default is '1.0'.
* @type string 'user-agent' The user agent, default is 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ).
* @type bool 'blocking' Whether to block stuff (?), default is true.
* @type array 'headers' What heads to send, default is empty array.
* @type array 'cookies' What cookies to send (?), default is empty array.
* @type string 'body' What to send as the request body, default is null.
* @type bool 'compress' Whether to send the request compressed, default is false.
* @type bool 'decompress' Whether to decompress the request, default is true.
* @type bool 'sslverify' Whether to verivy SSL, default is true.
* @type bool 'stream' Whether to stream the request (?), default is false.
* @type string 'filename' The filename, default is null.
* }
*
* @return WP_Error|array The response or WP_Error on failure.
*/
function wp_remote_request($url, $args = array()) {
$objFetchSite = _wp_http_get_object();
return $objFetchSite->request($url, $args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment