From 8eb3de46c9114b4f2270a957f670b69f011c012c Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 21 Oct 2015 03:48:24 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@35314 git-svn-id: http://core.svn.wordpress.org/trunk@35280 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/misc.php | 15 --------------- wp-includes/formatting.php | 20 ++++++++++++++++++++ wp-includes/version.php | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index d776681ccc..de6fc4e94c 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -288,21 +288,6 @@ function update_home_siteurl( $old_value, $value ) { } } -/** - * Shorten an URL, to be used as link text - * - * @since 1.2.0 - * - * @param string $url - * @return string - */ -function url_shorten( $url ) { - $short_url = str_replace( array( 'http://', 'www.' ), '', $url ); - $short_url = untrailingslashit( $short_url ); - if ( strlen( $short_url ) > 35 ) - $short_url = substr( $short_url, 0, 32 ) . '…'; - return $short_url; -} /** * Resets global variables based on $_GET and $_POST diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 65ef3e36d2..231c252ae4 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -4769,3 +4769,23 @@ function wp_staticize_emoji_for_email( $mail ) { return $mail; } + +/** + * Shorten an URL, to be used as link text + * + * @since 1.2.0 + * @since 4.4.0 Moved to wp-includes/formatting.php from wp-admin/includes/misc.php and added $length param + * + * @param string $url URL to shorten + * @param int $length Maxiumum length of url to return + * @return string +*/ +function url_shorten( $url, $length = 35 ) { + $stripped = str_replace( array( 'https://', 'http://', 'www.' ), '', $url ); + $short_url = untrailingslashit( $stripped ); + + if ( strlen( $short_url ) > $length ) { + $short_url = substr( $short_url, 0, $length - 3 ) . '…'; + } + return $short_url; +} \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index 0e6448f2a3..0b018097ab 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-35313'; +$wp_version = '4.4-alpha-35314'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.