Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created November 29, 2017 20:39
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 billerickson/4f712ee04e6e647c03729a863c1b8853 to your computer and use it in GitHub Desktop.
Save billerickson/4f712ee04e6e647c03729a863c1b8853 to your computer and use it in GitHub Desktop.
<?php
/**
* Comments Migration
*
*/
function ea_comments_migration() {
$site_url = 'https://yoursite.com';
$username = 'your_username';
$password = 'your_password';
$query_args = array(
'per_page' => 20,
'context' => 'edit',
);
$request_args = array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ),
),
);
$url = add_query_arg( $query_args, trailingslashit( $site_url ) . 'wp-json/wp/v2/comments' );
$response = wp_remote_get( $url, $request_args );
if( '200' != wp_remote_retrieve_response_code( $response ) )
return;
$comments = json_decode( wp_remote_retrieve_body( $response ) );
if( empty( $comments ) )
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment