WP_Importer::get_imported_comments
Sets array with imported comments from WordPress database.
Method of the class: WP_Importer{}
No Hooks.
Returns
Array.
Usage
$WP_Importer = new WP_Importer(); $WP_Importer->get_imported_comments( $blog_id );
- $blog_id(string) (required)
- .
Notes
- Global. wpdb.
$wpdbWordPress database abstraction object.
WP_Importer::get_imported_comments() WP Importer::get imported comments code WP 7.0
public function get_imported_comments( $blog_id ) {
global $wpdb;
$hashtable = array();
$limit = 100;
$offset = 0;
// Grab all comments in chunks.
do {
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d",
$offset,
$limit
)
);
// Increment offset.
$offset = ( $limit + $offset );
if ( ! empty( $results ) ) {
foreach ( $results as $r ) {
// Explode comment_agent key.
list ( $comment_agent_blog_id, $source_comment_id ) = explode( '-', $r->comment_agent );
$source_comment_id = (int) $source_comment_id;
// Check if this comment came from this blog.
if ( (int) $blog_id === (int) $comment_agent_blog_id ) {
$hashtable[ $source_comment_id ] = (int) $r->comment_ID;
}
}
}
} while ( count( $results ) === $limit );
return $hashtable;
}