wp/wp-admin/includes/class-wp-importer.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-admin/includes/class-wp-importer.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/includes/class-wp-importer.php	Tue Dec 15 13:49:49 2020 +0100
@@ -25,18 +25,18 @@
 		$limit  = 100;
 		$offset = 0;
 
-		// Grab all posts in chunks
+		// Grab all posts in chunks.
 		do {
 			$meta_key = $importer_name . '_' . $bid . '_permalink';
 			$sql      = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit );
 			$results  = $wpdb->get_results( $sql );
 
-			// Increment offset
+			// Increment offset.
 			$offset = ( $limit + $offset );
 
 			if ( ! empty( $results ) ) {
 				foreach ( $results as $r ) {
-					// Set permalinks into array
+					// Set permalinks into array.
 					$hashtable[ $r->meta_value ] = intval( $r->post_id );
 				}
 			}
@@ -62,9 +62,9 @@
 
 		$count = 0;
 
-		// Get count of permalinks
+		// Get count of permalinks.
 		$meta_key = $importer_name . '_' . $bid . '_permalink';
-		$sql      = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = '%s'", $meta_key );
+		$sql      = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key );
 
 		$result = $wpdb->get_results( $sql );
 
@@ -94,21 +94,21 @@
 		$limit  = 100;
 		$offset = 0;
 
-		// Grab all comments in chunks
+		// 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
+			// Increment offset.
 			$offset = ( $limit + $offset );
 
 			if ( ! empty( $results ) ) {
 				foreach ( $results as $r ) {
-					// Explode comment_agent key
+					// Explode comment_agent key.
 					list ( $ca_bid, $source_comment_id ) = explode( '-', $r->comment_agent );
 					$source_comment_id                   = intval( $source_comment_id );
 
-					// Check if this comment came from this blog
+					// Check if this comment came from this blog.
 					if ( $bid == $ca_bid ) {
 						$hashtable[ $source_comment_id ] = intval( $r->comment_ID );
 					}
@@ -130,10 +130,11 @@
 		if ( is_numeric( $blog_id ) ) {
 			$blog_id = (int) $blog_id;
 		} else {
-			$blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
-			if ( ( ! $parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) {
+			$blog   = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
+			$parsed = parse_url( $blog );
+			if ( ! $parsed || empty( $parsed['host'] ) ) {
 				fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" );
-				exit();
+				exit;
 			}
 			if ( empty( $parsed['path'] ) ) {
 				$parsed['path'] = '/';
@@ -147,7 +148,7 @@
 			);
 			if ( ! $blogs ) {
 				fwrite( STDERR, "Error: Could not find blog\n" );
-				exit();
+				exit;
 			}
 			$blog    = array_shift( $blogs );
 			$blog_id = (int) $blog->blog_id;
@@ -175,7 +176,7 @@
 
 		if ( ! $user_id || ! wp_set_current_user( $user_id ) ) {
 			fwrite( STDERR, "Error: can not find user\n" );
-			exit();
+			exit;
 		}
 
 		return $user_id;
@@ -202,7 +203,7 @@
 	 * @return array
 	 */
 	public function get_page( $url, $username = '', $password = '', $head = false ) {
-		// Increase the timeout
+		// Increase the timeout.
 		add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
 
 		$headers = array();
@@ -266,7 +267,7 @@
 		global $wpdb, $wp_actions;
 		// Or define( 'WP_IMPORTING', true );
 		$wpdb->queries = array();
-		// Reset $wp_actions to keep it from growing out of control
+		// Reset $wp_actions to keep it from growing out of control.
 		$wp_actions = array();
 	}
 }
@@ -306,27 +307,27 @@
 			$last_arg = $key;
 		} elseif ( (bool) preg_match( '/^-([a-zA-Z0-9]+)/', $args[ $i ], $match ) ) {
 			for ( $j = 0, $jl = strlen( $match[1] ); $j < $jl; $j++ ) {
-				$key         = $match[1]{$j};
+				$key         = $match[1][ $j ];
 				$out[ $key ] = true;
 			}
 
 			$last_arg = $key;
-		} elseif ( $last_arg !== null ) {
+		} elseif ( null !== $last_arg ) {
 			$out[ $last_arg ] = $args[ $i ];
 		}
 	}
 
-	// Check array for specified param
+	// Check array for specified param.
 	if ( isset( $out[ $param ] ) ) {
-		// Set return value
+		// Set return value.
 		$return = $out[ $param ];
 	}
 
-	// Check for missing required param
+	// Check for missing required param.
 	if ( ! isset( $out[ $param ] ) && $required ) {
-		// Display message and exit
+		// Display message and exit.
 		echo "\"$param\" parameter is required but was not specified\n";
-		exit();
+		exit;
 	}
 
 	return $return;