AnsPress_Prod_Updater::api_request( string $_action, array $_data )

Description #

Calls the API and, if successfull, returns the object delivered by the API.

Parameters #

  • $_action
    string (Required) The requested action.
  • $_data
    array (Required) Parameters for the API action.

Source #

File: admin/updater.php

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
private function api_request( $_action, $_data ) {
 
    global $wp_version;
 
    $data = array_merge( $this->api_data, $_data );
 
    if ( $data['slug'] != $this->slug ) {
        return;
    }
 
    if ( $this->api_url == home_url() ) {
        return false; // Don't allow a plugin to ping itself
    }
 
    $api_params = array(
        'edd_action'   => 'get_version',
        'license'      => ! empty( $data['license'] ) ? $data['license'] : '',
        'item_name'    => isset( $data['item_name'] ) ? $data['item_name'] : false,
        'item_id'      => isset( $data['item_id'] ) ? $data['item_id'] : false,
        'slug'         => $data['slug'],
        'author'       => $data['author'],
        'url'          => home_url(),
        'anspress_ver' => AP_VERSION,
    );
 
    $request = wp_remote_post(
        $this->api_url, array(
            'timeout'   => 15,
            'sslverify' => false,
            'body'      => $api_params,
        )
    );
 
    if ( ! is_wp_error( $request ) ) {
        $request = json_decode( wp_remote_retrieve_body( $request ) );
    }
 
    if ( $request && isset( $request->sections ) ) {
        $request->sections = maybe_unserialize( $request->sections );
    } else {
        $request = false;
    }
 
    return $request;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment