Make WordPress Core

Changeset 35314


Ignore:
Timestamp:
10/21/2015 03:47:23 AM (9 years ago)
Author:
wonderboymusic
Message:

Formatting: move url_shorten() from wp-admin/includes/misc.php to wp-includes/formatting.php for more global access.

Adds unit tests.

Props mulvane, chriscct7.
Fixes #20166.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/misc.php

    r35267 r35314  
    289289}
    290290
    291 /**
    292  * Shorten an URL, to be used as link text
    293  *
    294  * @since 1.2.0
    295  *
    296  * @param string $url
    297  * @return string
    298  */
    299 function url_shorten( $url ) {
    300     $short_url = str_replace( array( 'http://', 'www.' ), '', $url );
    301     $short_url = untrailingslashit( $short_url );
    302     if ( strlen( $short_url ) > 35 )
    303         $short_url = substr( $short_url, 0, 32 ) . '…';
    304     return $short_url;
    305 }
    306291
    307292/**
  • trunk/src/wp-includes/formatting.php

    r35284 r35314  
    47704770    return $mail;
    47714771}
     4772
     4773/**
     4774 * Shorten an URL, to be used as link text
     4775 *
     4776 * @since 1.2.0
     4777 * @since 4.4.0 Moved to wp-includes/formatting.php from wp-admin/includes/misc.php and added $length param
     4778 *
     4779 * @param string $url URL to shorten
     4780 * @param  int $length Maxiumum length of url to return
     4781 * @return string
     4782*/
     4783function url_shorten( $url, $length = 35 ) {
     4784    $stripped = str_replace( array( 'https://', 'http://', 'www.' ), '', $url );
     4785    $short_url = untrailingslashit( $stripped );
     4786
     4787    if ( strlen( $short_url ) > $length ) {
     4788        $short_url = substr( $short_url, 0, $length - 3 ) . '…';
     4789    }
     4790    return $short_url;
     4791}
Note: See TracChangeset for help on using the changeset viewer.