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