Say Anything Open Byline Authors Import
<php
$url = 'https://gist.githubusercontent.com/rveitch/b378711961b0b14104cc/raw/9b38156421a1264ac65a3b2b7bc11d074ca87635/sa_oba_user_export_03-14-16.json';
fcc_get_json( $url );
function fcc_get_json( $url ){
$url = $url;
$response = file_get_contents( $url );
# Decode to ARRAY
$array = json_decode( $response, TRUE );
# Convert array to OBJECT
$authors = new stdClass();
foreach ($array as $key => $value) {
$authors->$key = $value;
$taxonomy = 'open_byline_author'; // ToDo: Include in JSON or function argument?
# User Data
$term = $value['display_name']; // Name (author)
$slug = $value['user_login']; // author_login
$description = $value['description'];
//$parent_term_id = ''; // Probably won't be used often
# User Meta
$user_email = $value['user_email'];
$first_name = $value['first_name'];
$last_name = $value['last_name'];
$avatar = $value['avatar'];
$old_id = $value['old_id'];
# Insert the Term & Return the Term ID
$oba_term_id = wp_insert_term(
$term,
$taxonomy,
array(
'description'=> $description,
'slug' => $slug,
//'parent'=> $parent_term_id
)
)['term_id'];
//echo $oba_term_id;
update_term_meta( $oba_term_id, 'user_email', $user_email );
update_term_meta( $oba_term_id, 'first_name', $first_name );
update_term_meta( $oba_term_id, 'last_name', $last_name );
update_term_meta( $oba_term_id, 'avatar_filename', $avatar );
//update_term_meta( $oba_term_id, 'image', $avatar ); // WP Term Image
update_term_meta( $oba_term_id, 'old_id', $old_id );
}
}
echo 'Import Complete';