Ticket #36235: 36235.patch
File 36235.patch, 17.7 KB (added by , 9 years ago) |
---|
-
wp-includes/class-wp-post.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
337 337 338 338 return $post; 339 339 } 340 341 /** 342 * Retrieve post meta field for a post. 343 * 344 * @since 4.6.0 345 * 346 * @param string $key Optional. The meta key to retrieve. By default, returns 347 * data for all keys. Default empty. 348 * @param bool $single Optional. Whether to return a single value. Default false. 349 * 350 * @return mixed Will be an array if $single is false. Will be value of meta data 351 * field if $single is true. 352 */ 353 public function get_meta( $key = '', $single = false ) { 354 return get_post_meta( $this->ID, $key, $single ); 355 } 356 357 /** 358 * Retrieve post thumbnail ID. 359 * 360 * @since 4.6.0 361 * 362 * @return string|int Post thumbnail ID or empty string. 363 */ 364 public function get_post_thumbnail_id() { 365 return $this->get_meta( '_thumbnail_id', true ); 366 } 367 368 /** 369 * Check if post has an image attached. 370 * 371 * @since 4.6.0 372 * 373 * @return bool Whether the post has an image attached. 374 */ 375 public function has_post_thumbnail(){ 376 return (bool)$this->get_post_thumbnail_id(); 377 } 378 379 /** 380 * Retrieve the post thumbnail. 381 * 382 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size 383 * is registered, which differs from the 'thumbnail' image size managed via the 384 * Settings > Media screen. 385 * 386 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image 387 * size is used by default, though a different size can be specified instead as needed. 388 * 389 * @since 4.6.0 390 * 391 * @param string|array $size Optional. Image size to use. Accepts any valid image size, or 392 * an array of width and height values in pixels (in that order). 393 * Default 'post-thumbnail'. 394 * @param string|array $attr Optional. Query string or array of attributes. Default empty. 395 * @return string The post thumbnail image tag. 396 */ 397 function get_the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) { 398 399 $post_thumbnail_id = $this->get_post_thumbnail_id(); 400 401 /** 402 * Filter the post thumbnail size. 403 * 404 * @since 2.9.0 405 * 406 * @param string|array $size The post thumbnail size. Image size or array of width and height 407 * values (in that order). Default 'post-thumbnail'. 408 */ 409 $size = apply_filters( 'post_thumbnail_size', $size ); 410 411 if ( $post_thumbnail_id ) { 412 413 /** 414 * Fires before fetching the post thumbnail HTML. 415 * 416 * Provides "just in time" filtering of all filters in wp_get_attachment_image(). 417 * 418 * @since 2.9.0 419 * 420 * @param int $post_id The post ID. 421 * @param string $post_thumbnail_id The post thumbnail ID. 422 * @param string|array $size The post thumbnail size. Image size or array of width 423 * and height values (in that order). Default 'post-thumbnail'. 424 */ 425 do_action( 'begin_fetch_post_thumbnail_html', $this->ID, $post_thumbnail_id, $size ); 426 if ( in_the_loop() ) 427 update_post_thumbnail_cache(); 428 $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr ); 429 430 /** 431 * Fires after fetching the post thumbnail HTML. 432 * 433 * @since 2.9.0 434 * 435 * @param int $post_id The post ID. 436 * @param string $post_thumbnail_id The post thumbnail ID. 437 * @param string|array $size The post thumbnail size. Image size or array of width 438 * and height values (in that order). Default 'post-thumbnail'. 439 */ 440 do_action( 'end_fetch_post_thumbnail_html', $this->ID, $post_thumbnail_id, $size ); 441 442 } else { 443 $html = ''; 444 } 445 /** 446 * Filter the post thumbnail HTML. 447 * 448 * @since 2.9.0 449 * 450 * @param string $html The post thumbnail HTML. 451 * @param int $post_id The post ID. 452 * @param string $post_thumbnail_id The post thumbnail ID. 453 * @param string|array $size The post thumbnail size. Image size or array of width and height 454 * values (in that order). Default 'post-thumbnail'. 455 * @param string $attr Query string of attributes. 456 */ 457 return apply_filters( 'post_thumbnail_html', $html, $this->ID, $post_thumbnail_id, $size, $attr ); 458 } 459 460 /** 461 * Return the post thumbnail URL. 462 * 463 * @since 4.6.0 464 * 465 * @param string|array $size Optional. Registered image size to retrieve the source for or a flat 466 * array of height and width dimensions. Default 'post-thumbnail'. 467 * @return string|false Post thumbnail URL or false if no URL is available. 468 */ 469 function get_the_post_thumbnail_url($size = 'post-thumbnail' ) { 470 $post_thumbnail_id = $this->get_post_thumbnail_id( ); 471 if ( ! $post_thumbnail_id ) { 472 return false; 473 } 474 return wp_get_attachment_image_url( $post_thumbnail_id, $size ); 475 } 476 477 /** 478 * Retrieve the Post Global Unique Identifier (guid). 479 * 480 * The guid will appear to be a link, but should not be used as an link to the 481 * post. The reason you should not use it as a link, is because of moving the 482 * blog across domains. 483 * 484 * @since 4.6.0 485 * 486 * @return string 487 */ 488 function get_the_guid( ) { 489 /** 490 * Filter the Global Unique Identifier (guid) of the post. 491 * 492 * @since 1.5.0 493 * 494 * @param string $guid Global Unique Identifier (guid) of the post. 495 * @param int $id The post ID. 496 */ 497 return apply_filters( 'get_the_guid', $this->guid, $this->ID ); 498 } 499 500 /** 501 * Retrieve the post content. 502 * 503 * @since 4.6.0 504 * 505 * @global int $page 506 * @global int $more 507 * @global bool $preview 508 * @global array $pages 509 * @global int $multipage 510 * 511 * @param string $more_link_text Optional. Content for when there is more text. 512 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. 513 * @return string 514 */ 515 function get_the_content( $more_link_text = null, $strip_teaser = false ) { 516 global $page, $more, $preview, $pages, $multipage; 517 518 if ( null === $more_link_text ) 519 $more_link_text = __( '(more…)' ); 520 521 $output = ''; 522 $has_teaser = false; 523 524 // If post password required and it doesn't match the cookie. 525 if ( post_password_required( $this ) ) 526 return get_the_password_form( $this ); 527 528 if ( $page > count( $pages ) ) // if the requested page doesn't exist 529 $page = count( $pages ); // give them the highest numbered page that DOES exist 530 531 $content = $pages[$page - 1]; 532 if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { 533 $content = explode( $matches[0], $content, 2 ); 534 if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) 535 $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); 536 537 $has_teaser = true; 538 } else { 539 $content = array( $content ); 540 } 541 542 if ( false !== strpos( $this->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) 543 $strip_teaser = true; 544 545 $teaser = $content[0]; 546 547 if ( $more && $strip_teaser && $has_teaser ) 548 $teaser = ''; 549 550 $output .= $teaser; 551 552 if ( count( $content ) > 1 ) { 553 if ( $more ) { 554 $output .= '<span id="more-' . $this->ID . '"></span>' . $content[1]; 555 } else { 556 if ( ! empty( $more_link_text ) ) 557 558 /** 559 * Filter the Read More link text. 560 * 561 * @since 2.8.0 562 * 563 * @param string $more_link_element Read More link element. 564 * @param string $more_link_text Read More text. 565 */ 566 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$this->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); 567 $output = force_balance_tags( $output ); 568 } 569 } 570 571 if ( $preview ) // Preview fix for JavaScript bug with foreign languages. 572 $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); 573 574 return $output; 575 } 576 577 /** 578 * Retrieves the post excerpt. 579 * 580 * @since 4.6.0 581 * 582 * @return string Post excerpt. 583 */ 584 function get_the_excerpt( ) { 585 586 if ( post_password_required( $this ) ) { 587 return __( 'There is no excerpt because this is a protected post.' ); 588 } 589 590 /** 591 * Filter the retrieved post excerpt. 592 * 593 * @since 1.2.0 594 * @since 4.5.0 Introduced the `$post` parameter. 595 * 596 * @param string $post_excerpt The post excerpt. 597 * @param WP_Post $post Post object. 598 */ 599 return apply_filters( 'get_the_excerpt', $this->post_excerpt, $this ); 600 } 601 602 /** 603 * Whether post has excerpt. 604 * 605 * @since 4.6.0 606 * 607 * @return bool 608 */ 609 function has_excerpt() { 610 return ( !empty( $this->post_excerpt ) ); 611 } 340 612 } -
wp-includes/post-thumbnail-template.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
19 19 * @return bool Whether the post has an image attached. 20 20 */ 21 21 function has_post_thumbnail( $post = null ) { 22 return (bool) get_post_thumbnail_id( $post ); 23 } 22 if ( $post = get_post( $post ) ) { 23 return $post->has_post_thumbnail(); 24 } 24 25 26 return false; 27 } 28 25 29 /** 26 30 * Retrieve post thumbnail ID. 27 31 * … … 32 36 * @return string|int Post thumbnail ID or empty string. 33 37 */ 34 38 function get_post_thumbnail_id( $post = null ) { 35 $post = get_post( $post );36 if ( ! $post ) {37 return '';38 } 39 return get_post_meta( $post->ID, '_thumbnail_id', true );40 } 39 if ( $post = get_post( $post ) ) { 40 return $post->get_post_thumbnail_id(); 41 } 42 43 return ''; 44 } 41 45 42 46 /** 43 47 * Display the post thumbnail. … … 112 116 * @return string The post thumbnail image tag. 113 117 */ 114 118 function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) { 115 $post = get_post( $post ); 116 if ( ! $post ) { 117 return ''; 119 if ( $post = get_post( $post ) ) { 120 return $post->get_the_post_thumbnail( $size, $attr ); 118 121 } 119 $post_thumbnail_id = get_post_thumbnail_id( $post );120 122 121 /** 122 * Filter the post thumbnail size. 123 * 124 * @since 2.9.0 125 * 126 * @param string|array $size The post thumbnail size. Image size or array of width and height 127 * values (in that order). Default 'post-thumbnail'. 128 */ 129 $size = apply_filters( 'post_thumbnail_size', $size ); 130 131 if ( $post_thumbnail_id ) { 132 133 /** 134 * Fires before fetching the post thumbnail HTML. 135 * 136 * Provides "just in time" filtering of all filters in wp_get_attachment_image(). 137 * 138 * @since 2.9.0 139 * 140 * @param int $post_id The post ID. 141 * @param string $post_thumbnail_id The post thumbnail ID. 142 * @param string|array $size The post thumbnail size. Image size or array of width 143 * and height values (in that order). Default 'post-thumbnail'. 144 */ 145 do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size ); 146 if ( in_the_loop() ) 147 update_post_thumbnail_cache(); 148 $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr ); 149 150 /** 151 * Fires after fetching the post thumbnail HTML. 152 * 153 * @since 2.9.0 154 * 155 * @param int $post_id The post ID. 156 * @param string $post_thumbnail_id The post thumbnail ID. 157 * @param string|array $size The post thumbnail size. Image size or array of width 158 * and height values (in that order). Default 'post-thumbnail'. 159 */ 160 do_action( 'end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size ); 161 162 } else { 163 $html = ''; 164 } 165 /** 166 * Filter the post thumbnail HTML. 167 * 168 * @since 2.9.0 169 * 170 * @param string $html The post thumbnail HTML. 171 * @param int $post_id The post ID. 172 * @param string $post_thumbnail_id The post thumbnail ID. 173 * @param string|array $size The post thumbnail size. Image size or array of width and height 174 * values (in that order). Default 'post-thumbnail'. 175 * @param string $attr Query string of attributes. 176 */ 177 return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr ); 178 } 123 return ''; 124 } 179 125 180 126 /** 181 127 * Return the post thumbnail URL. … … 188 134 * @return string|false Post thumbnail URL or false if no URL is available. 189 135 */ 190 136 function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) { 191 $post_thumbnail_id = get_post_thumbnail_id( $post ); 192 if ( ! $post_thumbnail_id ) { 193 return false; 137 if ( $post = get_post( $post ) ) { 138 return $post->get_the_post_thumbnail_url( $size ); 194 139 } 195 return wp_get_attachment_image_url( $post_thumbnail_id, $size ); 140 141 return false; 196 142 } 197 143 198 144 /** -
wp-includes/post-template.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
203 203 * @return string 204 204 */ 205 205 function get_the_guid( $post = 0 ) { 206 $post = get_post( $post ); 206 if ( $post = get_post( $post ) ) { 207 return $post->get_the_guid(); 208 } 207 209 208 $guid = isset( $post->guid ) ? $post->guid : ''; 209 $id = isset( $post->ID ) ? $post->ID : 0; 210 211 /** 212 * Filter the Global Unique Identifier (guid) of the post. 213 * 214 * @since 1.5.0 215 * 216 * @param string $guid Global Unique Identifier (guid) of the post. 217 * @param int $id The post ID. 218 */ 219 return apply_filters( 'get_the_guid', $guid, $id ); 210 return ''; 220 211 } 221 212 222 213 /** … … 258 249 * @return string 259 250 */ 260 251 function get_the_content( $more_link_text = null, $strip_teaser = false ) { 261 global $page, $more, $preview, $pages, $multipage; 262 263 $post = get_post(); 264 265 if ( null === $more_link_text ) 266 $more_link_text = __( '(more…)' ); 267 268 $output = ''; 269 $has_teaser = false; 270 271 // If post password required and it doesn't match the cookie. 272 if ( post_password_required( $post ) ) 273 return get_the_password_form( $post ); 274 275 if ( $page > count( $pages ) ) // if the requested page doesn't exist 276 $page = count( $pages ); // give them the highest numbered page that DOES exist 277 278 $content = $pages[$page - 1]; 279 if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { 280 $content = explode( $matches[0], $content, 2 ); 281 if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) 282 $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); 283 284 $has_teaser = true; 285 } else { 286 $content = array( $content ); 287 } 252 return get_post()->get_the_content( $more_link_text, $strip_teaser ); 253 } 288 254 289 if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) 290 $strip_teaser = true; 291 292 $teaser = $content[0]; 293 294 if ( $more && $strip_teaser && $has_teaser ) 295 $teaser = ''; 296 297 $output .= $teaser; 298 299 if ( count( $content ) > 1 ) { 300 if ( $more ) { 301 $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; 302 } else { 303 if ( ! empty( $more_link_text ) ) 304 305 /** 306 * Filter the Read More link text. 307 * 308 * @since 2.8.0 309 * 310 * @param string $more_link_element Read More link element. 311 * @param string $more_link_text Read More text. 312 */ 313 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); 314 $output = force_balance_tags( $output ); 315 } 316 } 317 318 if ( $preview ) // Preview fix for JavaScript bug with foreign languages. 319 $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); 320 321 return $output; 322 } 323 324 /** 255 /** 325 256 * Preview fix for JavaScript bug with foreign languages. 326 257 * 327 258 * @since 3.1.0 … … 367 298 _deprecated_argument( __FUNCTION__, '2.3' ); 368 299 } 369 300 370 $post = get_post( $post ); 371 if ( empty( $post ) ) { 372 return ''; 301 if ( $post = get_post( $post ) ) { 302 return $post->get_the_excerpt(); 373 303 } 374 304 375 if ( post_password_required( $post ) ) { 376 return __( 'There is no excerpt because this is a protected post.' ); 377 } 305 return ''; 306 } 378 307 379 /** 380 * Filter the retrieved post excerpt. 381 * 382 * @since 1.2.0 383 * @since 4.5.0 Introduced the `$post` parameter. 384 * 385 * @param string $post_excerpt The post excerpt. 386 * @param WP_Post $post Post object. 387 */ 388 return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ); 389 } 390 391 /** 308 /** 392 309 * Whether post has excerpt. 393 310 * 394 311 * @since 2.3.0 … … 397 314 * @return bool 398 315 */ 399 316 function has_excerpt( $id = 0 ) { 400 $post = get_post( $id ); 401 return ( !empty( $post->post_excerpt ) ); 317 if ( $post = get_post( $id ) ) { 318 return $post->has_excerpt(); 319 } 320 321 return ''; 402 322 } 403 323 404 324 /**