Make WordPress Core


Ignore:
Timestamp:
10/21/2015 03:47:23 AM (8 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.