No hyphen in random keywords (#3353)
Fixes #2281 Fixes YOURLS/random-keywords#8
This commit is contained in:
parent
c588c1d729
commit
d85466307e
@ -168,11 +168,6 @@ function yourls_add_new_link( $url, $keyword = '', $title = '' ) {
|
|||||||
* @return string Acceptable charset for short URLS keywords
|
* @return string Acceptable charset for short URLS keywords
|
||||||
*/
|
*/
|
||||||
function yourls_get_shorturl_charset() {
|
function yourls_get_shorturl_charset() {
|
||||||
static $charset = null;
|
|
||||||
if ( $charset !== null ) {
|
|
||||||
return $charset;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( defined( 'YOURLS_URL_CONVERT' ) && in_array( YOURLS_URL_CONVERT, [ 62, 64 ] ) ) {
|
if ( defined( 'YOURLS_URL_CONVERT' ) && in_array( YOURLS_URL_CONVERT, [ 62, 64 ] ) ) {
|
||||||
$charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
$charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/**
|
||||||
Plugin Name: Allow Hyphens in Short URLs
|
* Plugin Name: Allow Hyphens in Short URLs
|
||||||
Plugin URI: http://yourls.org/
|
* Plugin URI: http://yourls.org/
|
||||||
Description: Allow hyphens in short URLs (like <tt>http://sho.rt/hello-world</tt>)
|
* Description: Allow hyphens in short URLs (like <tt>http://sho.rt/hello-world</tt>)
|
||||||
Version: 1.0
|
* Version: 1.1
|
||||||
Author: Ozh
|
* Author: Ozh
|
||||||
Author URI: http://ozh.org/
|
* Author URI: http://ozh.org/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** Release History:
|
||||||
|
*
|
||||||
|
* 1.0 Initial release
|
||||||
|
* 1.1 Modified: Make random keywords hyphen free
|
||||||
|
*/
|
||||||
|
|
||||||
// No direct call
|
// No direct call
|
||||||
if( !defined( 'YOURLS_ABSPATH' ) ) die();
|
if( !defined( 'YOURLS_ABSPATH' ) ) die();
|
||||||
|
|
||||||
|
// Add hyphen to the allowed character set
|
||||||
yourls_add_filter( 'get_shorturl_charset', 'ozh_hyphen_in_charset' );
|
yourls_add_filter( 'get_shorturl_charset', 'ozh_hyphen_in_charset' );
|
||||||
|
// Unless we are crafting a random keyword
|
||||||
|
yourls_add_action('add_new_link_create_keyword', function() {yourls_remove_filter('get_shorturl_charset', 'ozh_hyphen_in_charset');});
|
||||||
|
|
||||||
function ozh_hyphen_in_charset( $in ) {
|
function ozh_hyphen_in_charset( $in ) {
|
||||||
return $in.'-';
|
return $in.'-';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user