Skip to content

Instantly share code, notes, and snippets.

@tommusrhodus
Created February 14, 2019 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommusrhodus/80eaf6c04c6220b88470d2e58033c7b4 to your computer and use it in GitHub Desktop.
Save tommusrhodus/80eaf6c04c6220b88470d2e58033c7b4 to your computer and use it in GitHub Desktop.
ORCID Data Scraping From WordPress
<?php
/**
* This function has zero error handling and is currently a proof of concept.
* Don't use this in a live project unless you plan on creating issues for yourself.
*/
function scholar_vitae_get_orc_id_values( $id ){
$response = wp_remote_get( 'https://pub.orcid.org/v2.1/'. $id .'/record' );
$response = preg_replace( "/(<\/?)(\w+):([^>]*>)/", "$1$2$3", wp_remote_retrieve_body( $response ) );
$xml = new SimpleXMLElement( $response );
$array = json_decode( json_encode( (array) $xml ), TRUE );
recursive_unset( $array, '@attributes' );
unset( $array['commonorcid-identifier'] );
unset( $array['preferencespreferences'] );
unset( $array['historyhistory'] );
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment