WP_Ooyala_Backlot::update PHP Method

update() public method

public update ( $body, $path )
    public function update($body, $path)
    {
        global $wp_version;
        $params = array('api_key' => $this->api_key, 'expires' => time() + 900);
        $path = '/v2/assets/' . $path;
        $params['signature'] = $this->sign_request(array('path' => $path, 'method' => 'PATCH', 'body' => $body), $params);
        foreach ($params as &$param) {
            $param = rawurlencode($param);
        }
        $url = add_query_arg($params, 'https://api.ooyala.com' . $path);
        if ($wp_version >= 3.4) {
            return wp_remote_request($url, array('headers' => array('Content-Type' => 'application/json'), 'method' => 'PATCH', 'body' => $body, 'timeout' => apply_filters('ooyala_http_request_timeout', 10)));
        }
        // Workaround for core bug - http://core.trac.wordpress.org/ticket/18589
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
        curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($curl);
        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);
        return array('body' => $response, 'response' => array('code' => $status));
    }

Usage Example

	.ooyala-item .item-title {text-align:center;}
</style>

<div class="wrap">
	<?php 
screen_icon('ooyala');
?>
	<h2>
		<?php 
esc_html_e('Ooyala Video Browser', 'ooyalavideo');
?>
	</h2>
	<?php 
$backlot = new WP_Ooyala_Backlot(get_option('ooyala'));
if (isset($_POST['submit'])) {
    $response = $backlot->update(json_encode(array('name' => sanitize_text_field($_POST['ooyala']['title']), 'embed_code' => sanitize_text_field($_POST['ooyala']['embed']), 'hosted_at' => sanitize_url($_POST['ooyala']['hosted_at']), 'description' => sanitize_text_field($_POST['ooyala']['description']))), sanitize_text_field($_POST['ooyala']['embed']));
    if (200 == wp_remote_retrieve_response_code($response)) {
        echo '<div id="message" class="updated below-h2"><p>' . esc_html__('Video updated.', 'ooyalavideo') . '</p></div>';
    } else {
        echo '<div id="message" class="error below-h2"><p>' . esc_html__('There was an error communicating with Ooyala API.', 'ooyalavideo') . '</p></div>';
    }
} elseif (!empty($_GET['edit'])) {
    $response = $backlot->query(array('where' => "embed_code='" . esc_attr($_GET['edit']) . "'"), array(), true);
} else {
    $key_word = isset($_GET['s']) ? esc_attr($_GET['s']) : '';
    $field = isset($_GET['ooyalasearchfield']) ? esc_attr($_GET['ooyalasearchfield']) : '';
    if ($key_word && $field) {
        $where = $field . "='" . $key_word . "' AND status='live'";
    } else {
        $where = "status='live'";
    }