No hyphen in random keywords (#3353)

Fixes  #2281
Fixes YOURLS/random-keywords#8
This commit is contained in:
྅༻ Ǭɀħ ༄༆ཉ 2022-05-29 14:18:34 +02:00 committed by GitHub
parent c588c1d729
commit d85466307e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 15 deletions

View File

@ -168,11 +168,6 @@ function yourls_add_new_link( $url, $keyword = '', $title = '' ) {
* @return string Acceptable charset for short URLS keywords
*/
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 ] ) ) {
$charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
}

View File

@ -1,19 +1,27 @@
<?php
/*
Plugin Name: Allow Hyphens in Short URLs
Plugin URI: http://yourls.org/
Description: Allow hyphens in short URLs (like <tt>http://sho.rt/hello-world</tt>)
Version: 1.0
Author: Ozh
Author URI: http://ozh.org/
*/
/**
* Plugin Name: Allow Hyphens in Short URLs
* Plugin URI: http://yourls.org/
* Description: Allow hyphens in short URLs (like <tt>http://sho.rt/hello-world</tt>)
* Version: 1.1
* Author: Ozh
* Author URI: http://ozh.org/
*/
/** Release History:
*
* 1.0 Initial release
* 1.1 Modified: Make random keywords hyphen free
*/
// No direct call
if( !defined( 'YOURLS_ABSPATH' ) ) die();
// Add hyphen to the allowed character set
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 ) {
return $in.'-';
}