@@ 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. |
@@ 101-122 (lines=22) @@ | ||
98 | * @param int $network_id The ID of the network to retrieve. |
|
99 | * @return WP_Network|bool The network's object if found. False if not. |
|
100 | */ |
|
101 | public static function get_instance( $network_id ) { |
|
102 | global $wpdb; |
|
103 | ||
104 | $network_id = (int) $network_id; |
|
105 | if ( ! $network_id ) { |
|
106 | return false; |
|
107 | } |
|
108 | ||
109 | $_network = wp_cache_get( $network_id, 'networks' ); |
|
110 | ||
111 | if ( ! $_network ) { |
|
112 | $_network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->site} WHERE id = %d LIMIT 1", $network_id ) ); |
|
113 | ||
114 | if ( empty( $_network ) || is_wp_error( $_network ) ) { |
|
115 | return false; |
|
116 | } |
|
117 | ||
118 | wp_cache_add( $network_id, $_network, 'networks' ); |
|
119 | } |
|
120 | ||
121 | return new WP_Network( $_network ); |
|
122 | } |
|
123 | ||
124 | /** |
|
125 | * Create a new WP_Network object. |
@@ 169-190 (lines=22) @@ | ||
166 | * @param int $site_id The ID of the site to retrieve. |
|
167 | * @return WP_Site|false The site's object if found. False if not. |
|
168 | */ |
|
169 | public static function get_instance( $site_id ) { |
|
170 | global $wpdb; |
|
171 | ||
172 | $site_id = (int) $site_id; |
|
173 | if ( ! $site_id ) { |
|
174 | return false; |
|
175 | } |
|
176 | ||
177 | $_site = wp_cache_get( $site_id, 'sites' ); |
|
178 | ||
179 | if ( ! $_site ) { |
|
180 | $_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) ); |
|
181 | ||
182 | if ( empty( $_site ) || is_wp_error( $_site ) ) { |
|
183 | return false; |
|
184 | } |
|
185 | ||
186 | wp_cache_add( $site_id, $_site, 'sites' ); |
|
187 | } |
|
188 | ||
189 | return new WP_Site( $_site ); |
|
190 | } |
|
191 | ||
192 | /** |
|
193 | * Creates a new WP_Site object. |