WP_Importer::get_imported_comments() WordPress Method

The get_imported_comments() method is used to get the list of comments that have been imported into a WordPress site. This is useful for checking if comments have been imported correctly, or for finding out how many comments have been imported.

WP_Importer::get_imported_comments( string $blog_id ) #

Set array with imported comments from WordPress database


Parameters

$blog_id

(string)(Required)


Top ↑

Return

(array)


Top ↑

Source

File: wp-admin/includes/class-wp-importer.php

	public function get_imported_comments( $blog_id ) {
		global $wpdb;

		$hashtable = array();

		$limit  = 100;
		$offset = 0;

		// Grab all comments in chunks.
		do {
			$sql     = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit );
			$results = $wpdb->get_results( $sql );

			// 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 ( $blog_id == $comment_agent_blog_id ) {
						$hashtable[ $source_comment_id ] = (int) $r->comment_ID;
					}
				}
			}
		} while ( count( $results ) == $limit );

		return $hashtable;
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.