Ticket #42814: 42814.4.diff
File 42814.4.diff, 8.5 KB (added by , 6 years ago) |
---|
-
src/wp-includes/class-wp-query.php
4133 4133 return; 4134 4134 } 4135 4135 4136 $elements = $this->generate_postdata( $post ); 4137 if( false === $elements ){ 4138 return; 4139 } 4140 4141 $id = $elements['id']; 4142 $authordata = $elements['authordata']; 4143 $currentday = $elements['currentday']; 4144 $currentmonth = $elements['currentmonth']; 4145 $page = $elements['page']; 4146 $pages = $elements['pages']; 4147 $multipage = $elements['multipage']; 4148 $more = $elements['more']; 4149 $numpages = $elements['numpages']; 4150 4151 return true; 4152 } 4153 4154 /** 4155 * Generate post data. 4156 * 4157 * @param WP_Post|object|int $post WP_Post instance or Post ID/object. 4158 * @return array $elements Elements of post 4159 */ 4160 public function generate_postdata( $post ) { 4161 4162 if ( ! ( $post instanceof WP_Post ) ) { 4163 $post = get_post( $post ); 4164 } 4165 4166 if ( ! $post ) { 4167 return false; 4168 } 4169 4136 4170 $id = (int) $post->ID; 4137 4171 4138 4172 $authordata = get_userdata( $post->post_author ); … … 4209 4243 */ 4210 4244 do_action_ref_array( 'the_post', array( &$post, &$this ) ); 4211 4245 4212 return true; 4246 $elements = compact( $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages ); 4247 4248 return $elements; 4213 4249 } 4214 4250 /** 4215 4251 * After looping through a nested query, this function -
src/wp-includes/default-filters.php
170 170 add_filter( 'the_excerpt', 'convert_chars' ); 171 171 add_filter( 'the_excerpt', 'wpautop' ); 172 172 add_filter( 'the_excerpt', 'shortcode_unautop' ); 173 add_filter( 'get_the_excerpt', 'wp_trim_excerpt' );173 add_filter( 'get_the_excerpt', 'wp_trim_excerpt', 10, 2 ); 174 174 175 175 add_filter( 'the_post_thumbnail_caption', 'wptexturize' ); 176 176 add_filter( 'the_post_thumbnail_caption', 'convert_smilies' ); -
src/wp-includes/formatting.php
3625 3625 * The ' […]' string can be modified by plugins/themes using the {@see 'excerpt_more'} filter 3626 3626 * 3627 3627 * @since 1.5.0 3628 * @since 5.0.0 Added '$post' param 3628 3629 * 3629 3630 * @param string $text Optional. The excerpt. If set to empty, an excerpt is generated. 3631 * @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default is null. 3630 3632 * @return string The excerpt. 3631 3633 */ 3632 function wp_trim_excerpt( $text = '' ) {3634 function wp_trim_excerpt( $text = '', $post = null ) { 3633 3635 $raw_excerpt = $text; 3634 3636 if ( '' == $text ) { 3635 $text = get_the_content( '' ); 3637 $post = get_post( $post ); 3638 $text = get_the_content( '', false, $post ); 3636 3639 3637 3640 $text = strip_shortcodes( $text ); 3638 3641 -
src/wp-includes/post-template.php
230 230 * Display the post content. 231 231 * 232 232 * @since 0.71 233 * @since 5.0.0 Added '$post' param 233 234 * 234 235 * @param string $more_link_text Optional. Content for when there is more text. 235 236 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. 237 * @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default is null. 236 238 */ 237 function the_content( $more_link_text = null, $strip_teaser = false ) {238 $content = get_the_content( $more_link_text, $strip_teaser );239 function the_content( $more_link_text = null, $strip_teaser = false, $post = null ) { 240 $content = get_the_content( $more_link_text, $strip_teaser, $post ); 239 241 240 242 /** 241 243 * Filters the post content. … … 253 255 * Retrieve the post content. 254 256 * 255 257 * @since 0.71 258 * @since 5.0.0 Added '$post' param 256 259 * 257 260 * @global int $page Page number of a single post/page. 258 261 * @global int $more Boolean indicator for whether single post/page is being viewed. … … 263 266 * 264 267 * @param string $more_link_text Optional. Content for when there is more text. 265 268 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. 269 * @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default is null. 266 270 * @return string 267 271 */ 268 function get_the_content( $more_link_text = null, $strip_teaser = false ) {272 function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) { 269 273 global $page, $more, $preview, $pages, $multipage; 270 274 271 $post = get_post();272 275 276 $_post = get_post( $post ); 277 278 if ( ! ( $_post instanceof WP_Post ) ) { 279 return ''; 280 } 281 282 if ( null === $post ) { 283 $elements = compact( $page, $more, $preview, $pages, $multipage ); 284 } else { 285 $elements = generate_postdata( $_post ); 286 } 287 288 273 289 if ( null === $more_link_text ) { 274 290 $more_link_text = sprintf( 275 291 '<span aria-label="%1$s">%2$s</span>', 276 292 sprintf( 277 293 /* translators: %s: Name of current post */ 278 294 __( 'Continue reading %s' ), 279 the_title_attribute( array( 'echo' => false ) )295 the_title_attribute( array( 'echo' => false, 'post' => $_post, ) ) 280 296 ), 281 297 __( '(more…)' ) 282 298 ); … … 286 302 $has_teaser = false; 287 303 288 304 // If post password required and it doesn't match the cookie. 289 if ( post_password_required( $ post ) ) {290 return get_the_password_form( $ post );305 if ( post_password_required( $_post ) ) { 306 return get_the_password_form( $_post ); 291 307 } 292 308 293 if ( $ page > count( $pages) ) { // if the requested page doesn't exist294 $ page = count( $pages); // give them the highest numbered page that DOES exist309 if ( $elements['page'] > count( $elements['pages'] ) ) { // if the requested page doesn't exist 310 $elements['page'] = count( $elements['pages'] ); // give them the highest numbered page that DOES exist 295 311 } 296 312 297 $content = $ pages[ $page- 1 ];313 $content = $elements['pages'][ $elements['page'] - 1 ]; 298 314 if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { 299 315 $content = explode( $matches[0], $content, 2 ); 300 316 if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) { … … 306 322 $content = array( $content ); 307 323 } 308 324 309 if ( false !== strpos( $ post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page== 1 ) ) {325 if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || $elements['page'] == 1 ) ) { 310 326 $strip_teaser = true; 311 327 } 312 328 313 329 $teaser = $content[0]; 314 330 315 if ( $ more&& $strip_teaser && $has_teaser ) {331 if ( $elements['more'] && $strip_teaser && $has_teaser ) { 316 332 $teaser = ''; 317 333 } 318 334 … … 319 335 $output .= $teaser; 320 336 321 337 if ( count( $content ) > 1 ) { 322 if ( $ more) {323 $output .= '<span id="more-' . $ post->ID . '"></span>' . $content[1];338 if ( $elements['more'] ) { 339 $output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1]; 324 340 } else { 325 341 if ( ! empty( $more_link_text ) ) { 326 342 … … 332 348 * @param string $more_link_element Read More link element. 333 349 * @param string $more_link_text Read More text. 334 350 */ 335 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink( ) . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );351 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink( $_post ) . "#more-{$_post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); 336 352 } 337 353 $output = force_balance_tags( $output ); 338 354 } 339 355 } 340 356 341 if ( $ preview) { // Preview fix for JavaScript bug with foreign languages.357 if ( $elements['preview'] ) { // Preview fix for JavaScript bug with foreign languages. 342 358 $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); 343 359 } 344 360 -
src/wp-includes/query.php
1111 1111 1112 1112 return false; 1113 1113 } 1114 1115 /** 1116 * Generate post data. 1117 * 1118 * @since 5.0.0 1119 * 1120 * @global WP_Query $wp_query Global WP_Query instance. 1121 * 1122 * @param WP_Post|object|int $post WP_Post instance or Post ID/object. 1123 * @return bool True when finished. 1124 */ 1125 function generate_postdata( $post ) { 1126 global $wp_query; 1127 1128 if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) { 1129 return $wp_query->generate_postdata( $post ); 1130 } 1131 1132 return false; 1133 }