Code Duplication    Length = 22-22 lines in 3 locations

src/wp-includes/class-wp-comment.php 1 location

@@ 191-212 (lines=22) @@
188
	 * @param int $id Comment ID.
189
	 * @return WP_Comment|false Comment object, otherwise false.
190
	 */
191
	public static function get_instance( $id ) {
192
		global $wpdb;
193
194
		$comment_id = (int) $id;
195
		if ( ! $comment_id ) {
196
			return false;
197
		}
198
199
		$_comment = wp_cache_get( $comment_id, 'comment' );
200
201
		if ( ! $_comment ) {
202
			$_comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id ) );
203
204
			if ( ! $_comment ) {
205
				return false;
206
			}
207
208
			wp_cache_add( $_comment->comment_ID, $_comment, 'comment' );
209
		}
210
211
		return new WP_Comment( $_comment );
212
	}
213
214
	/**
215
	 * Constructor.

src/wp-includes/class-wp-network.php 1 location

@@ 97-118 (lines=22) @@
94
	 * @param int $network_id The ID of the network to retrieve.
95
	 * @return WP_Network|bool The network's object if found. False if not.
96
	 */
97
	public static function get_instance( $network_id ) {
98
		global $wpdb;
99
100
		$network_id = (int) $network_id;
101
		if ( ! $network_id ) {
102
			return false;
103
		}
104
105
		$_network = wp_cache_get( $network_id, 'networks' );
106
107
		if ( ! $_network ) {
108
			$_network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->site} WHERE id = %d LIMIT 1", $network_id ) );
109
110
			if ( empty( $_network ) || is_wp_error( $_network ) ) {
111
				return false;
112
			}
113
114
			wp_cache_add( $network_id, $_network, 'networks' );
115
		}
116
117
		return new WP_Network( $_network );
118
	}
119
120
	/**
121
	 * Create a new WP_Network object.

src/wp-includes/class-wp-site.php 1 location

@@ 162-183 (lines=22) @@
159
	 * @param int $site_id The ID of the site to retrieve.
160
	 * @return WP_Site|false The site's object if found. False if not.
161
	 */
162
	public static function get_instance( $site_id ) {
163
		global $wpdb;
164
165
		$site_id = (int) $site_id;
166
		if ( ! $site_id ) {
167
			return false;
168
		}
169
170
		$_site = wp_cache_get( $site_id, 'sites' );
171
172
		if ( ! $_site ) {
173
			$_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) );
174
175
			if ( empty( $_site ) || is_wp_error( $_site ) ) {
176
				return false;
177
			}
178
179
			wp_cache_add( $site_id, $_site, 'sites' );
180
		}
181
182
		return new WP_Site( $_site );
183
	}
184
185
	/**
186
	 * Creates a new WP_Site object.