: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Performs a request to the Smash Balloon Twitter API.
namespace TwitterFeed\SmashTwitter;
protected $error_message;
public function __construct($endpoint, $term, $args = array(), $auth_token = false)
$this->endpoint = $endpoint;
$this->auth_token = $auth_token;
'Accept' => 'application/json',
'Content-Type' => 'application/json'
$headers['Authorization'] = 'Bearer ' . $this->auth_token;
$this->args['headers'] = $headers;
$endpoint_relative_url = '';
$this->args['method'] = 'POST';
if ( empty( $this->args['timeout'] ) ) {
$this->args['timeout'] = 20;
if ( $this->endpoint === 'usertimeline' ) {
$this->args['method'] = 'GET';
$endpoint_relative_url = SMASH_TWITTER_TIMELINE_PATH . '?tweet_mode=extended&screen_name=' . urlencode( trim( $this->term ) ) . '&user_type=licenseless';
} elseif ( $this->endpoint === 'register' ) {
$endpoint_relative_url = '1.1/auth/register';
} elseif ( $this->endpoint === 'license' ) {
$endpoint_relative_url = '1.1/auth/license';
$endpoint_url = SMASH_TWITTER_URL . $endpoint_relative_url . SMASH_TWITTER_URL_EXTRA_GET_PARAMS;
if ( $method === 'get' ) {
$return = wp_remote_get( $endpoint_url, $args );
$return = wp_remote_post( $endpoint_url, $args );
if ( is_wp_error( $return ) ) {
$response_code = wp_remote_retrieve_response_code( $return );
if ( $response_code >= 200 && $response_code < 300 ) {
if ( isset( $return['body'] )) {
$decoded = json_decode( $body, true );
if ( isset( $return['body'] )) {
$this->error_code = $response_code;
$this->error_message = $return['body'];
public function get_error() {
if ( empty( $this->error_code ) ) {
'code' => $this->error_code,
'message' => $this->error_message