Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like SAL_Post often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SAL_Post, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | abstract class SAL_Post { |
||
| 15 | public $post; |
||
| 16 | public $context; |
||
| 17 | public $site; |
||
| 18 | |||
| 19 | function __construct( $site, $post, $context ) { |
||
| 20 | $this->post = $post; |
||
| 21 | $this->context = $context; |
||
| 22 | $this->site = $site; |
||
| 23 | } |
||
| 24 | |||
| 25 | public function __set( $key, $value ) { |
||
| 26 | $this->post->{ $key } = $value; |
||
| 27 | } |
||
| 28 | |||
| 29 | public function __get( $key ) { |
||
| 30 | if ( $key === 'links' ) { |
||
| 31 | require_once dirname( __FILE__ ) . '/class.json-api-links.php'; |
||
| 32 | return WPCOM_JSON_API_Links::getInstance(); |
||
| 33 | } |
||
| 34 | return $this->post->{ $key }; |
||
| 35 | } |
||
| 36 | |||
| 37 | public function __call( $name, $arguments ) { |
||
| 38 | if ( is_callable( array( $this->post, $name ) ) ) { |
||
| 39 | return call_user_func_array( array( $this->post, $name ), $arguments ); |
||
| 40 | } else { |
||
| 41 | trigger_error("Call to undefined method '{$name}'"); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | public function __isset ( $name ) { |
||
| 46 | return isset( $this->post->{ $name } ); |
||
| 47 | } |
||
| 48 | |||
| 49 | abstract public function get_like_count(); |
||
| 50 | abstract public function is_liked(); |
||
| 51 | abstract public function is_reblogged(); |
||
| 52 | abstract public function is_following(); |
||
| 53 | abstract public function get_global_id(); |
||
| 54 | abstract public function get_geo(); |
||
| 55 | |||
| 56 | public function get_menu_order() { |
||
| 57 | return (int) $this->post->menu_order; |
||
| 58 | } |
||
| 59 | |||
| 60 | public function get_guid() { |
||
| 61 | return (string) $this->post->guid; |
||
| 62 | } |
||
| 63 | |||
| 64 | public function get_type() { |
||
| 65 | return (string) $this->post->post_type; |
||
| 66 | } |
||
| 67 | |||
| 68 | public function get_tags() { |
||
| 69 | $tags = array(); |
||
| 70 | $terms = wp_get_post_tags( $this->post->ID ); |
||
| 71 | foreach ( $terms as $term ) { |
||
| 72 | if ( !empty( $term->name ) ) { |
||
| 73 | $tags[$term->name] = $this->format_taxonomy( $term, 'post_tag', 'display' ); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | return (object) $tags; |
||
| 77 | } |
||
| 78 | |||
| 79 | public function get_categories() { |
||
| 80 | $categories = array(); |
||
| 81 | $terms = wp_get_object_terms( $this->post->ID, 'category', array( 'fields' => 'all' ) ); |
||
| 82 | View Code Duplication | foreach ( $terms as $term ) { |
|
| 83 | if ( !empty( $term->name ) ) { |
||
| 84 | $categories[$term->name] = $this->format_taxonomy( $term, 'category', 'display' ); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | return (object) $categories; |
||
| 88 | } |
||
| 89 | |||
| 90 | public function get_attachments_and_count() { |
||
| 91 | $attachments = array(); |
||
| 92 | $_attachments = new WP_Query( array( 'post_parent' => $this->post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'posts_per_page' => '20' ) ); |
||
| 93 | foreach ( $_attachments->posts as $attachment ) { |
||
| 94 | $attachments[$attachment->ID] = $this->get_media_item_v1_1( $attachment->ID ); |
||
| 95 | } |
||
| 96 | return array( (object) $attachments, (int) $_attachments->found_posts ); |
||
| 97 | } |
||
| 98 | |||
| 99 | public function get_metadata() { |
||
| 100 | $metadata = array(); |
||
| 101 | foreach ( (array) has_meta( $this->post->ID ) as $meta ) { |
||
| 102 | // Don't expose protected fields. |
||
| 103 | $meta_key = $meta['meta_key']; |
||
| 104 | |||
| 105 | $show = !( WPCOM_JSON_API_Metadata::is_internal_only( $meta_key ) ) |
||
| 106 | && |
||
| 107 | ( |
||
| 108 | WPCOM_JSON_API_Metadata::is_public( $meta_key ) |
||
| 109 | || |
||
| 110 | current_user_can( 'edit_post_meta', $this->post->ID , $meta_key ) |
||
| 111 | ); |
||
| 112 | |||
| 113 | if ( $show ) { |
||
| 114 | $metadata[] = array( |
||
| 115 | 'id' => $meta['meta_id'], |
||
| 116 | 'key' => $meta['meta_key'], |
||
| 117 | 'value' => maybe_unserialize( $meta['meta_value'] ), |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | if ( ! empty( $metadata ) ) { |
||
| 123 | return $metadata; |
||
| 124 | } else { |
||
| 125 | return false; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | public function get_meta() { |
||
| 130 | $meta = (object) array( |
||
| 131 | 'links' => (object) array( |
||
| 132 | 'self' => (string) $this->get_post_link(), |
||
| 133 | 'help' => (string) $this->get_post_link( 'help' ), |
||
| 134 | 'site' => (string) $this->get_site_link(), |
||
| 135 | 'replies' => (string) $this->get_post_link( 'replies/' ), |
||
| 136 | 'likes' => (string) $this->get_post_link( 'likes/' ), |
||
| 137 | ), |
||
| 138 | ); |
||
| 139 | |||
| 140 | // add autosave link if a more recent autosave exists |
||
| 141 | if ( 'edit' === $this->context ) { |
||
| 142 | $autosave = wp_get_post_autosave( $this->post->ID ); |
||
| 143 | if ( $autosave && $autosave->post_modified > $this->post->post_modified ) |
||
| 144 | $meta->links->autosave = (string) $this->get_post_link() . '/autosave'; |
||
| 145 | } |
||
| 146 | |||
| 147 | return $meta; |
||
| 148 | } |
||
| 149 | |||
| 150 | public function get_current_user_capabilities() { |
||
| 151 | return array( |
||
| 152 | 'publish_post' => current_user_can( 'publish_post', $this->post ), |
||
| 153 | 'delete_post' => current_user_can( 'delete_post', $this->post ), |
||
| 154 | 'edit_post' => current_user_can( 'edit_post', $this->post ) |
||
| 155 | ); |
||
| 156 | } |
||
| 157 | |||
| 158 | public function get_revisions() { |
||
| 159 | if ( 'edit' !== $this->context ) { |
||
| 160 | return false; |
||
| 161 | } |
||
| 162 | |||
| 163 | $revisions = array(); |
||
| 164 | $post_revisions = wp_get_post_revisions( $this->post->ID ); |
||
| 165 | |||
| 166 | foreach ( $post_revisions as $_post ) { |
||
| 167 | $revisions[] = $_post->ID; |
||
| 168 | } |
||
| 169 | |||
| 170 | return $revisions; |
||
| 171 | } |
||
| 172 | |||
| 173 | public function get_other_urls() { |
||
| 174 | $other_urls = array(); |
||
| 175 | |||
| 176 | if ( 'publish' !== $this->post->post_status ) { |
||
| 177 | $other_urls = $this->get_permalink_suggestions( $this->post->post_title ); |
||
| 178 | } |
||
| 179 | |||
| 180 | return (object) $other_urls; |
||
| 181 | } |
||
| 182 | |||
| 183 | protected function get_site_link() { |
||
| 184 | return $this->links->get_site_link( $this->site->blog_id ); |
||
|
|
|||
| 185 | } |
||
| 186 | |||
| 187 | protected function get_post_link( $path = null ) { |
||
| 188 | return $this->links->get_post_link( $this->site->blog_id, $this->post->ID, $path ); |
||
| 189 | } |
||
| 190 | |||
| 191 | public function get_publicize_urls() { |
||
| 192 | $publicize_URLs = array(); |
||
| 193 | $publicize = get_post_meta( $this->post->ID, 'publicize_results', true ); |
||
| 194 | View Code Duplication | if ( $publicize ) { |
|
| 195 | foreach ( $publicize as $service => $data ) { |
||
| 196 | switch ( $service ) { |
||
| 197 | case 'twitter' : |
||
| 198 | foreach ( $data as $datum ) { |
||
| 199 | $publicize_URLs[] = esc_url_raw( "https://twitter.com/{$datum['user_id']}/status/{$datum['post_id']}" ); |
||
| 200 | } |
||
| 201 | break; |
||
| 202 | case 'fb' : |
||
| 203 | foreach ( $data as $datum ) { |
||
| 204 | $publicize_URLs[] = esc_url_raw( "https://www.facebook.com/permalink.php?story_fbid={$datum['post_id']}&id={$datum['user_id']}" ); |
||
| 205 | } |
||
| 206 | break; |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 | return (array) $publicize_URLs; |
||
| 211 | } |
||
| 212 | |||
| 213 | public function get_page_template() { |
||
| 214 | return (string) get_post_meta( $this->post->ID, '_wp_page_template', true ); |
||
| 215 | } |
||
| 216 | |||
| 217 | // note this is overridden in jetpack-shadow |
||
| 218 | public function get_featured_image() { |
||
| 219 | $image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $this->post->ID ), 'full' ); |
||
| 220 | if ( is_array( $image_attributes ) && isset( $image_attributes[0] ) ) { |
||
| 221 | return (string) $image_attributes[0]; |
||
| 222 | } else { |
||
| 223 | return ''; |
||
| 224 | } |
||
| 225 | } |
||
| 226 | |||
| 227 | public function get_post_thumbnail() { |
||
| 228 | $thumb = null; |
||
| 229 | |||
| 230 | $thumb_id = get_post_thumbnail_id( $this->post->ID ); |
||
| 231 | |||
| 232 | View Code Duplication | if ( ! empty( $thumb_id ) ) { |
|
| 233 | $attachment = get_post( $thumb_id ); |
||
| 234 | if ( ! empty( $attachment ) ) |
||
| 235 | $featured_image_object = $this->get_attachment( $attachment ); |
||
| 236 | |||
| 237 | if ( ! empty( $featured_image_object ) ) { |
||
| 238 | $thumb = (object) $featured_image_object; |
||
| 239 | } |
||
| 240 | } |
||
| 241 | |||
| 242 | return $thumb; |
||
| 243 | } |
||
| 244 | |||
| 245 | public function get_format() { |
||
| 246 | $format = (string) get_post_format( $this->post->ID ); |
||
| 247 | if ( !$format ) { |
||
| 248 | $format = 'standard'; |
||
| 249 | } |
||
| 250 | |||
| 251 | return $format; |
||
| 252 | } |
||
| 253 | |||
| 254 | View Code Duplication | private function get_attachment( $attachment ) { |
|
| 255 | $metadata = wp_get_attachment_metadata( $attachment->ID ); |
||
| 256 | |||
| 257 | $result = array( |
||
| 258 | 'ID' => (int) $attachment->ID, |
||
| 259 | 'URL' => (string) wp_get_attachment_url( $attachment->ID ), |
||
| 260 | 'guid' => (string) $attachment->guid, |
||
| 261 | 'mime_type' => (string) $attachment->post_mime_type, |
||
| 262 | 'width' => (int) isset( $metadata['width'] ) ? $metadata['width'] : 0, |
||
| 263 | 'height' => (int) isset( $metadata['height'] ) ? $metadata['height'] : 0, |
||
| 264 | ); |
||
| 265 | |||
| 266 | if ( isset( $metadata['duration'] ) ) { |
||
| 267 | $result['duration'] = (int) $metadata['duration']; |
||
| 268 | } |
||
| 269 | |||
| 270 | /** This filter is documented in class.jetpack-sync.php */ |
||
| 271 | return (object) apply_filters( 'get_attachment', $result ); |
||
| 272 | } |
||
| 273 | |||
| 274 | public function get_date() { |
||
| 275 | return (string) WPCOM_JSON_API_Date::format_date( $this->post->post_date_gmt, $this->post->post_date ); |
||
| 276 | } |
||
| 277 | |||
| 278 | public function get_modified_date() { |
||
| 279 | return (string) WPCOM_JSON_API_Date::format_date( $this->post->post_modified_gmt, $this->post->post_modified ); |
||
| 280 | } |
||
| 281 | |||
| 282 | public function get_title() { |
||
| 283 | if ( 'display' === $this->context ) { |
||
| 284 | return (string) get_the_title( $this->post->ID ); |
||
| 285 | } else { |
||
| 286 | return (string) htmlspecialchars_decode( $this->post->post_title, ENT_QUOTES ); |
||
| 287 | } |
||
| 288 | } |
||
| 289 | |||
| 290 | public function get_url() { |
||
| 291 | if ( 'revision' === $this->post->post_type ) { |
||
| 292 | return (string) esc_url_raw( get_permalink( $this->post->post_parent ) ); |
||
| 293 | } else { |
||
| 294 | return (string) esc_url_raw( get_permalink( $this->post->ID ) ); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | public function get_shortlink() { |
||
| 299 | return (string) esc_url_raw( wp_get_shortlink( $this->post->ID ) ); |
||
| 300 | } |
||
| 301 | |||
| 302 | public function get_content() { |
||
| 303 | if ( 'display' === $this->context ) { |
||
| 304 | // TODO: move this WPCOM-specific hack |
||
| 305 | add_filter( 'the_password_form', array( $this, 'the_password_form' ) ); |
||
| 306 | $content = (string) $this->get_the_post_content_for_display(); |
||
| 307 | remove_filter( 'the_password_form', array( $this, 'the_password_form' ) ); |
||
| 308 | return $content; |
||
| 309 | } else { |
||
| 310 | return (string) $this->post->post_content; |
||
| 311 | } |
||
| 312 | } |
||
| 313 | |||
| 314 | public function get_excerpt() { |
||
| 315 | if ( 'display' === $this->context ) { |
||
| 316 | add_filter( 'the_password_form', array( $this, 'the_password_form' ) ); |
||
| 317 | ob_start(); |
||
| 318 | the_excerpt(); |
||
| 319 | $response = (string) ob_get_clean(); |
||
| 320 | remove_filter( 'the_password_form', array( $this, 'the_password_form' ) ); |
||
| 321 | } else { |
||
| 322 | $response = htmlspecialchars_decode( (string) $this->post->post_excerpt, ENT_QUOTES ); |
||
| 323 | } |
||
| 324 | return $response; |
||
| 325 | } |
||
| 326 | |||
| 327 | public function get_status() { |
||
| 328 | return (string) get_post_status( $this->post->ID ); |
||
| 329 | } |
||
| 330 | |||
| 331 | public function is_sticky() { |
||
| 332 | return (bool) is_sticky( $this->post->ID ); |
||
| 333 | } |
||
| 334 | |||
| 335 | public function get_slug() { |
||
| 336 | return (string) $this->post->post_name; |
||
| 337 | } |
||
| 338 | |||
| 339 | public function get_password() { |
||
| 340 | $password = (string) $this->post->post_password; |
||
| 341 | if ( 'edit' === $this->context ) { |
||
| 342 | $password = htmlspecialchars_decode( (string) $password, ENT_QUOTES ); |
||
| 343 | } |
||
| 344 | return $password; |
||
| 345 | } |
||
| 346 | |||
| 347 | public function get_parent() { |
||
| 348 | if ( $this->post->post_parent ) { |
||
| 349 | $parent = get_post( $this->post->post_parent ); |
||
| 350 | if ( 'display' === $this->context ) { |
||
| 351 | $parent_title = (string) get_the_title( $parent->ID ); |
||
| 352 | } else { |
||
| 353 | $parent_title = (string) htmlspecialchars_decode( $this->post->post_title, ENT_QUOTES ); |
||
| 354 | } |
||
| 355 | return (object) array( |
||
| 356 | 'ID' => (int) $parent->ID, |
||
| 357 | 'type' => (string) $parent->post_type, |
||
| 358 | 'link' => (string) $this->links->get_post_link( $this->site->blog_id, $parent->ID ), |
||
| 359 | 'title' => $parent_title, |
||
| 360 | ); |
||
| 361 | } else { |
||
| 362 | return false; |
||
| 363 | } |
||
| 364 | } |
||
| 365 | |||
| 366 | function the_password_form() { |
||
| 367 | return __( 'This post is password protected.', 'jetpack' ); |
||
| 368 | } |
||
| 369 | |||
| 370 | public function get_discussion() { |
||
| 371 | return array( |
||
| 372 | 'comments_open' => (bool) comments_open( $this->post->ID ), |
||
| 373 | 'comment_status' => (string) $this->post->comment_status, |
||
| 374 | 'pings_open' => (bool) pings_open( $this->post->ID ), |
||
| 375 | 'ping_status' => (string) $this->post->ping_status, |
||
| 376 | 'comment_count' => (int) $this->post->comment_count, |
||
| 377 | ); |
||
| 378 | } |
||
| 379 | |||
| 380 | public function is_likes_enabled() { |
||
| 381 | /** This filter is documented in modules/likes.php */ |
||
| 382 | $sitewide_likes_enabled = (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) ); |
||
| 383 | $post_likes_switched = (bool) get_post_meta( $this->post->ID, 'switch_like_status', true ); |
||
| 384 | $post_likes_enabled = $sitewide_likes_enabled; |
||
| 385 | if ( $post_likes_switched ) { |
||
| 386 | $post_likes_enabled = ! $post_likes_enabled; |
||
| 387 | } |
||
| 388 | return (bool) $post_likes_enabled; |
||
| 389 | } |
||
| 390 | |||
| 391 | public function is_sharing_enabled() { |
||
| 392 | $show = true; |
||
| 393 | /** This filter is documented in modules/sharedaddy/sharing-service.php */ |
||
| 394 | $show = apply_filters( 'sharing_show', $show, $this->post ); |
||
| 395 | |||
| 396 | $switched_status = get_post_meta( $this->post->ID, 'sharing_disabled', false ); |
||
| 397 | |||
| 398 | if ( !empty( $switched_status ) ) |
||
| 399 | $show = false; |
||
| 400 | |||
| 401 | return (bool) $show; |
||
| 402 | } |
||
| 403 | |||
| 404 | // No Blog ID parameter. No Post ID parameter. Depends on globals. |
||
| 405 | // Expects setup_postdata() to already have been run |
||
| 406 | View Code Duplication | function get_the_post_content_for_display() { |
|
| 407 | global $pages, $page; |
||
| 408 | |||
| 409 | $old_pages = $pages; |
||
| 410 | $old_page = $page; |
||
| 411 | |||
| 412 | $content = join( "\n\n", $pages ); |
||
| 413 | $content = preg_replace( '/<!--more(.*?)?-->/', '', $content ); |
||
| 414 | $pages = array( $content ); |
||
| 415 | $page = 1; |
||
| 416 | |||
| 417 | ob_start(); |
||
| 418 | the_content(); |
||
| 419 | $return = ob_get_clean(); |
||
| 420 | |||
| 421 | $pages = $old_pages; |
||
| 422 | $page = $old_page; |
||
| 423 | |||
| 424 | return $return; |
||
| 425 | } |
||
| 426 | |||
| 427 | public function get_author() { |
||
| 428 | if ( 0 == $this->post->post_author ) |
||
| 429 | return null; |
||
| 430 | |||
| 431 | $show_email = $this->context === 'edit' && current_user_can( 'edit_post', $this->post ); |
||
| 432 | |||
| 433 | $user = get_user_by( 'id', $this->post->post_author ); |
||
| 434 | |||
| 435 | if ( ! $user || is_wp_error( $user ) ) { |
||
| 436 | trigger_error( 'Unknown user', E_USER_WARNING ); |
||
| 437 | |||
| 438 | return null; |
||
| 439 | } |
||
| 440 | |||
| 441 | // TODO factor this out |
||
| 442 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
| 443 | $active_blog = get_active_blog_for_user( $user->ID ); |
||
| 444 | $site_id = $active_blog->blog_id; |
||
| 445 | $profile_URL = "http://en.gravatar.com/{$user->user_login}"; |
||
| 446 | } else { |
||
| 447 | $profile_URL = 'http://en.gravatar.com/' . md5( strtolower( trim( $user->user_email ) ) ); |
||
| 448 | $site_id = -1; |
||
| 449 | } |
||
| 450 | |||
| 451 | $author = array( |
||
| 452 | 'ID' => (int) $user->ID, |
||
| 453 | 'login' => (string) $user->user_login, |
||
| 454 | 'email' => $show_email ? (string) $user->user_email : false, // (string|bool) |
||
| 455 | 'name' => (string) $user->display_name, |
||
| 456 | 'first_name' => (string) $user->first_name, |
||
| 457 | 'last_name' => (string) $user->last_name, |
||
| 458 | 'nice_name' => (string) $user->user_nicename, |
||
| 459 | 'URL' => (string) esc_url_raw( $user->user_url ), |
||
| 460 | 'avatar_URL' => (string) esc_url_raw( $this->get_avatar_url( $user->user_email ) ), |
||
| 461 | 'profile_URL' => (string) esc_url_raw( $profile_URL ) |
||
| 462 | ); |
||
| 463 | |||
| 464 | if ($site_id > -1) { |
||
| 465 | $author['site_ID'] = (int) $site_id; |
||
| 466 | } |
||
| 467 | |||
| 468 | return (object) $author; |
||
| 469 | } |
||
| 470 | |||
| 471 | protected function get_avatar_url( $email, $avatar_size = 96 ) { |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Get extra post permalink suggestions |
||
| 482 | * @return array array of permalink suggestions: 'permalink_URL', 'suggested_slug' |
||
| 483 | */ |
||
| 484 | public function get_permalink_suggestions( $title ) { |
||
| 489 | |||
| 490 | private function format_taxonomy( $taxonomy, $taxonomy_type, $context ) { |
||
| 491 | // Permissions |
||
| 492 | View Code Duplication | switch ( $context ) { |
|
| 493 | case 'edit' : |
||
| 494 | $tax = get_taxonomy( $taxonomy_type ); |
||
| 495 | if ( !current_user_can( $tax->cap->edit_terms ) ) |
||
| 496 | return new WP_Error( 'unauthorized', 'User cannot edit taxonomy', 403 ); |
||
| 497 | break; |
||
| 498 | case 'display' : |
||
| 499 | if ( -1 == get_option( 'blog_public' ) && ! current_user_can( 'read' ) ) { |
||
| 500 | return new WP_Error( 'unauthorized', 'User cannot view taxonomy', 403 ); |
||
| 501 | } |
||
| 502 | break; |
||
| 503 | default : |
||
| 504 | return new WP_Error( 'invalid_context', 'Invalid API CONTEXT', 400 ); |
||
| 505 | } |
||
| 506 | |||
| 507 | $response = array(); |
||
| 508 | $response['ID'] = (int) $taxonomy->term_id; |
||
| 509 | $response['name'] = (string) $taxonomy->name; |
||
| 510 | $response['slug'] = (string) $taxonomy->slug; |
||
| 511 | $response['description'] = (string) $taxonomy->description; |
||
| 512 | $response['post_count'] = (int) $taxonomy->count; |
||
| 513 | |||
| 514 | if ( 'category' === $taxonomy_type ) |
||
| 515 | $response['parent'] = (int) $taxonomy->parent; |
||
| 516 | |||
| 517 | $response['meta'] = (object) array( |
||
| 518 | 'links' => (object) array( |
||
| 519 | 'self' => (string) $this->links->get_taxonomy_link( $this->site->blog_id, $taxonomy->slug, $taxonomy_type ), |
||
| 520 | 'help' => (string) $this->links->get_taxonomy_link( $this->site->blog_id, $taxonomy->slug, $taxonomy_type, 'help' ), |
||
| 521 | 'site' => (string) $this->links->get_site_link( $this->site->blog_id ), |
||
| 522 | ), |
||
| 523 | ); |
||
| 524 | |||
| 525 | return (object) $response; |
||
| 526 | } |
||
| 527 | |||
| 528 | // TODO: factor this out into site |
||
| 529 | private function get_media_item_v1_1( $media_id ) { |
||
| 530 | $media_item = get_post( $media_id ); |
||
| 531 | |||
| 532 | if ( ! $media_item || is_wp_error( $media_item ) ) |
||
| 533 | return new WP_Error( 'unknown_media', 'Unknown Media', 404 ); |
||
| 534 | |||
| 535 | $file = basename( wp_get_attachment_url( $media_item->ID ) ); |
||
| 536 | $file_info = pathinfo( $file ); |
||
| 537 | $ext = $file_info['extension']; |
||
| 538 | |||
| 651 | } |
||
| 652 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.