6. Before AfterWord
2
Press
7
• Design & support own
implementation
• Branch code for multiple
transport implementations
• Duplication of code across
plugins
• Standard API for core and
plugins
• Wider environment support
with fallbacks
• OO and helper Functional
@akshayraje
8. wp_remote_get() Retrieves a URL using the GET
HTTP method.
wp_remote_post() Retrieves a URL using the POST
HTTP method.
wp_remote_head() Retrieves a URL using the HEAD
HTTP method.
wp_remote_request() Retrieves a URL using either the
default GET or a custom HTTP
method that you specify.
WP_HTTP Helper functions
@akshayraje
9. $url (string) (required) Site URL to retrieve.
Default: None
$args (array) (optional) Override the defaults.
Default: array()
WP_HTTP Helper functions
Parameters
Return Values
(WP_Error|array) The response or WP_Error on failure.
@akshayraje
21. Use the Transients API instead of
wp_cache functions if you need to
guarantee that your data will be cached. If
persistent caching is configured, then the
transients functions will use the wp_cache
functions. However if persistent caching
has not been enabled, then the data will
instead be cached to the options table.
Source: http://codex.wordpress.org/Class_Reference/WP_Object_Cache
“
@akshayraje
22. @akshayraje
$transient (string) (required) Unique transient name.
45 characters or less in length.
Default: None
Transients functions
get_transient( $transient )
Pretty much like get_option( $option )
23. @akshayraje
Transients functions
set_transient($transient, $value, $expiration)
Pretty much like set_option( $option, $value )
$transient (string) (required) Unique transient name.
45 characters or less in length.
Default: None
$value (mixed) (required) Transient value.
Default: None
$expiration (int) (optional) Time until expiration in
seconds from now, or 0 for never expires.
Default: 0.
24. @akshayraje
// Get any existing copy of transient data if available
if ( false === ( $response = get_transient( 'special_wp_remote_get' ) ) ) {
$response = wp_remote_get( 'http://httpbin.org/html' );
if ( !is_wp_error( $response ) ) {
set_transient( 'special_wp_remote_get', $response, 12 *
HOUR_IN_SECONDS );
}
}
// Use $response like you would have normally...
<?code Cached wp_remote_get
27. wp_remote_retrieve_body() Retrieves just the body from the
response.
wp_remote_retrieve_header() Gives you a single HTTP header
based on name from the
response.
wp_remote_retrieve_headers() Returns all of the HTTP headers
in an array for processing.
wp_remote_retrieve_response_code() Gives you the number for the
HTTP response. This should be
200, but could be 4xx or even
3xx on failure.
wp_remote_retrieve_response_message() Returns the response message
based on the response code.
WP_HTTP Helper functions
@akshayraje