capabilities(), true ); } public static function registry() { $drivers = array( 'facebook' => 'AIEO_Social_Driver_Facebook', ); $drivers = apply_filters( 'aieo_social_platforms', $drivers ); return is_array( $drivers ) ? $drivers : array(); } public static function get( $code ) { $reg = self::registry(); if ( empty( $reg[ $code ] ) ) { return null; } $class = $reg[ $code ]; if ( ! class_exists( $class ) ) { return null; } $driver = new $class(); return ( $driver instanceof self ) ? $driver : null; } protected function http_get( $url, array $args = array() ) { $defaults = array( 'timeout' => 20, 'headers' => array( 'Accept' => 'application/json' ), ); $response = wp_remote_get( $url, array_merge( $defaults, $args ) ); return $this->parse_response( $response ); } protected function http_post( $url, array $body = array(), array $args = array() ) { $defaults = array( 'timeout' => 20, 'headers' => array( 'Accept' => 'application/json' ), 'body' => $body, ); $response = wp_remote_post( $url, array_merge( $defaults, $args ) ); return $this->parse_response( $response ); } protected function parse_response( $response ) { if ( is_wp_error( $response ) ) { return $response; } $code = (int) wp_remote_retrieve_response_code( $response ); $raw = wp_remote_retrieve_body( $response ); $data = json_decode( $raw, true ); if ( null === $data && '' !== trim( (string) $raw ) && JSON_ERROR_NONE !== json_last_error() ) { return new WP_Error( 'aieo_social_bad_json', sprintf( 'Non-JSON response (HTTP %d).', $code ), array( 'status' => $code, 'body' => $raw ) ); } if ( ! is_array( $data ) ) { $data = array(); } return $data; } }