You would replace this:
$dataOrig = file_get_contents('http://twitter.com/users/show/'.$twitter_user);
if (is_wp_error($dataOrig)) {
return 'Error!!!';
}else{
$profile = new SimpleXMLElement ( $dataOrig );
$countOrig = $profile->followers_count;
$count = strval ( $countOrig );
}
With this:
$dataOrig = wp_remote_get('http://twitter.com/users/show/'.$twitter_user);
if (is_wp_error($dataOrig)) {
return 'Error!!!';
} else {
$profile = new SimpleXMLElement ( $dataOrig['body'] );
$countOrig = $profile->followers_count;
$count = strval ( $countOrig );
}
Note that wp_remote_get
returns an array with the body of the page in body
.
Edit: Using wp_remote_retrieve_body
…
$dataOrig = wp_remote_get( 'https://twitter.com/users/show/'.$twitter_user );
if ( is_wp_error( $dataOrig ) ) {
return printf( '%s: %s', $dataOrig->get_error_code(), $dataOrig->get_error_message );
} elseif(
empty( $dataOrig )
OR 200 !== wp_remote_retrieve_response_code( $dataOrig )
OR 'OK' !== wp_remote_retrieve_response_message( $dataOrig )
) {
return _e( 'Nothing available', 'your_textdomain' );
} else {
$dataContent = wp_remote_retrieve_body( $dataOrig );
$profile = new SimpleXMLElement ( $dataContent );
$countOrig = $profile->followers_count;
$count = strval ( $countOrig );
}