Ticket #17689: 17689.5.diff
File 17689.5.diff, 4.4 KB (added by , 6 years ago) 


tests/phpunit/tests/formatting/WPHumanizePlusMinus.php
1 <?php 2 3 /** 4 * @group formatting 5 */ 6 class Tests_Formatting_WPHumanizePlusMinus extends WP_UnitTestCase { 7 /** 8 * @dataProvider data_wp_humanize_plus_minus 9 */ 10 function test_wp_humanize_plus_minus( $actual, $expected ) { 11 $this>assertSame( $expected, wp_humanize_plus_minus( $actual ) ); 12 } 13 14 function data_wp_humanize_plus_minus() { 15 return array( 16 array( 'A+', 'A plus' ), 17 array( 'A++', 'A plus plus' ), 18 array( 'A+++', 'A plus plus plus' ), 19 array( 'A++++', 'A plus plus plus plus' ), 20 array( 'A', 'A minus' ), 21 array( 'A', 'A minus minus' ), 22 array( 'A', 'A minus minus minus' ), 23 array( 'A', 'A minus minus minus minus' ), 24 array( 'A +', 'A plus' ), 25 array( 'A ++', 'A plus plus' ), 26 array( 'A +++', 'A plus plus plus' ), 27 array( 'A ++++', 'A plus plus plus plus' ), 28 array( 'A ', 'A minus' ), 29 array( 'A ', 'A minus minus' ), 30 array( 'A ', 'A minus minus minus' ), 31 array( 'A ', 'A minus minus minus minus' ), 32 33 array( 'That was an A+ effort', 'That was an A plus effort' ), 34 array( 'That was an A++ effort', 'That was an A plus plus effort' ), 35 array( 'That was an A+++ effort', 'That was an A plus plus plus effort' ), 36 array( 'That was an A++++ effort', 'That was an A plus plus plus plus effort' ), 37 array( 'That was an A effort', 'That was an A minus effort' ), 38 array( 'That was an A effort', 'That was an A minus minus effort' ), 39 array( 'That was an A effort', 'That was an A minus minus minus effort' ), 40 array( 'That was an A effort', 'That was an A minus minus minus minus effort' ), 41 42 array( 'Me+You', 'Me+You' ), 43 array( 'Me + You', 'Me plus You' ), 44 ); 45 } 46 } 47 No newline at end of file 
src/wpincludes/taxonomy.php
2099 2099 $name = wp_unslash($name); 2100 2100 $description = wp_unslash($description); 2101 2101 2102 if ( empty( $slug) )2103 $ slug = sanitize_title($name);2102 if ( empty( $slug ) ) { 2103 $name = trim( $name ); 2104 2104 2105 // check for a term like "$$$" so it isn't repeatedly added 2106 if ( preg_match_all( '#[^azAZ09]#', $name, $matches ) && count( $matches[0] ) === strlen( $name ) ) { 2107 $exists = $wpdb>get_row( $wpdb>prepare( "SELECT term_id, slug FROM $wpdb>terms WHERE name = %s", $name ) ); 2108 if ( ! empty( $exists ) ) { 2109 if ( term_exists( $exists>term_id, $taxonomy ) ) 2110 return new WP_Error( 'term_exists', __( 'A term with the name provided already exists.' ) ); 2111 2112 // use the existing slug or the term will never match in term_exists 2113 $slug = $exists>slug; 2114 } 2115 2116 } else { 2117 $slug = sanitize_title( $name ); 2118 } 2119 } 2120 2105 2121 $term_group = 0; 2106 2122 if ( $alias_of ) { 2107 2123 $alias = $wpdb>get_row( $wpdb>prepare( "SELECT term_id, term_group FROM $wpdb>terms WHERE slug = %s", $alias_of) ); 
src/wpincludes/formatting.php
1006 1006 $title = utf8_uri_encode($title, 200); 1007 1007 } 1008 1008 1009 $title = wp_humanize_plus_minus( $title ); 1009 1010 $title = strtolower($title); 1010 1011 $title = preg_replace('/&.+?;/', '', $title); // kill entities 1011 1012 $title = str_replace('.', '', $title); … … 3426 3427 3427 3428 return false; 3428 3429 } 3430 3431 /** 3432 * Convert +/ to plus/minus 3433 * 3434 * @param string $str Input string. 3435 * @return string Formatted string. 3436 */ 3437 function wp_humanize_plus_minus( $str ) { 3438 $replacements = array( 3439 '' => ' minus minus', 3440 '++' => ' plus plus' 3441 ); 3442 3443 $new_str = str_replace( array_keys( $replacements ), array_values( $replacements ), $str ); 3444 3445 $patterns = array( 3446 '#([^])\s#' => '$1 minus ', 3447 '#([^])$#' => '$1 minus', 3448 '#([^+]+)\+\s#' => '$1 plus ', 3449 '#([^+]+)\+$#' => '$1 plus', 3450 ); 3451 3452 $new_str = preg_replace( array_keys( $patterns ), array_values( $patterns ), $new_str ); 3453 if ( $new_str !== $str ) 3454 $new_str = wp_humanize_plus_minus( $new_str ); 3455 3456 return $new_str; 3457 } 3458 No newline at end of file