diff options
author | ྅༻ Ǭɀħ ༄༆ཉ <ozh@ozh.org> | 2022-05-29 15:18:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-29 15:18:34 +0300 |
commit | d85466307e43875b41c0f1e2253f894a5fb8d20c (patch) | |
tree | 58f1ee71f5b57fc65e113d0581cb320b811c926a | |
parent | c588c1d729ed83b9d075687e16c0781a0527a66d (diff) |
No hyphen in random keywords (#3353)
Fixes #2281
Fixes YOURLS/random-keywords#8
-rw-r--r-- | includes/functions-shorturls.php | 5 | ||||
-rw-r--r-- | user/plugins/hyphens-in-urls/plugin.php | 28 |
2 files changed, 18 insertions, 15 deletions
diff --git a/includes/functions-shorturls.php b/includes/functions-shorturls.php index f8ec0af2..0036b10d 100644 --- a/includes/functions-shorturls.php +++ b/includes/functions-shorturls.php @@ -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'; } diff --git a/user/plugins/hyphens-in-urls/plugin.php b/user/plugins/hyphens-in-urls/plugin.php index 38034121..c604dd58 100644 --- a/user/plugins/hyphens-in-urls/plugin.php +++ b/user/plugins/hyphens-in-urls/plugin.php @@ -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.'-'; } - - |