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
This commit is contained in:
parent
e525ab849d
commit
8eb3de46c9
|
@ -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
|
* Resets global variables based on $_GET and $_POST
|
||||||
|
|
|
@ -4769,3 +4769,23 @@ function wp_staticize_emoji_for_email( $mail ) {
|
||||||
|
|
||||||
return $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;
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue