Ticket #3794: generate_title_from_content.diff
| File generate_title_from_content.diff, 1.5 kB (added by Justinsomnia, 2 years ago) |
|---|
-
wp-includes/formatting.php
old new 313 313 return apply_filters('sanitize_user', $username, $raw_username, $strict); 314 314 } 315 315 316 function generate_title_from_content( $content, $title_length = 100, $ellipsis = '...' ) { 317 $title = ''; 318 $content = preg_replace('|\s+|', ' ', strip_tags($content)); 319 320 foreach ( explode(' ', $content) as $word ) { 321 if ( (strlen($title) + strlen($word)) > $title_length ) { 322 if ( empty($title) ) 323 $title = substr($content, 0, $title_length); 324 325 if ( !empty($title) ) 326 $title = trim($title) . $ellipsis; 327 328 break; 329 } 330 $title .= $word . " "; 331 } 332 return trim($title); 333 } 334 316 335 function sanitize_title($title, $fallback_title = '') { 317 336 $title = strip_tags($title); 318 337 $title = apply_filters('sanitize_title', $title); -
wp-includes/post.php
old new 538 538 // Create a valid post name. Drafts are allowed to have an empty 539 539 // post name. 540 540 if ( empty($post_name) ) { 541 if ( 'draft' != $post_status ) 541 if ( 'draft' != $post_status ) { 542 if ( empty($post_title) ) 543 $post_title = generate_title_from_content($post_excerpt . ' ' . $post_content); 542 544 $post_name = sanitize_title($post_title); 545 } 543 546 } else { 544 547 $post_name = sanitize_title($post_name); 545 548 }
