Ticket #42814: 42814.3.diff
File 42814.3.diff, 7.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 -1 as passed to get_post. 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 = -1 ) { 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 -1 as passed to get_post. 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 = -1 ) { 269 273 global $page, $more, $preview, $pages, $multipage; 270 274 271 $post = get_post();272 275 276 if ( -1 === $post ) { 277 $post = get_post(); 278 $elements = compact( $page, $more, $preview, $pages, $multipage ); 279 } else { 280 $post = get_post( $post ); 281 $elements = generate_postdata( $post ); 282 } 283 284 if( $post instanceof WP_Post || ! is_array( $elements ) ) { 285 return ''; 286 } 287 273 288 if ( null === $more_link_text ) { 274 289 $more_link_text = sprintf( 275 290 '<span aria-label="%1$s">%2$s</span>', … … 290 305 return get_the_password_form( $post ); 291 306 } 292 307 293 if ( $ page > count( $pages) ) { // if the requested page doesn't exist294 $ page = count( $pages); // give them the highest numbered page that DOES exist308 if ( $elements['page'] > count( $elements['pages'] ) ) { // if the requested page doesn't exist 309 $elements['page'] = count( $elements['pages'] ); // give them the highest numbered page that DOES exist 295 310 } 296 311 297 $content = $ pages[ $page- 1 ];312 $content = $elements['pages'][ $elements['page'] - 1 ]; 298 313 if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { 299 314 $content = explode( $matches[0], $content, 2 ); 300 315 if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) { … … 306 321 $content = array( $content ); 307 322 } 308 323 309 if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $ multipage || $page== 1 ) ) {324 if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || $elements['page'] == 1 ) ) { 310 325 $strip_teaser = true; 311 326 } 312 327 313 328 $teaser = $content[0]; 314 329 315 if ( $ more&& $strip_teaser && $has_teaser ) {330 if ( $elements['more'] && $strip_teaser && $has_teaser ) { 316 331 $teaser = ''; 317 332 } 318 333 … … 319 334 $output .= $teaser; 320 335 321 336 if ( count( $content ) > 1 ) { 322 if ( $ more) {337 if ( $elements['more'] ) { 323 338 $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; 324 339 } else { 325 340 if ( ! empty( $more_link_text ) ) { … … 338 353 } 339 354 } 340 355 341 if ( $ preview) { // Preview fix for JavaScript bug with foreign languages.356 if ( $elements['preview'] ) { // Preview fix for JavaScript bug with foreign languages. 342 357 $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); 343 358 } 344 359 -
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 }