• Resolved Cam

    (@crazycoolcam)


    I know the default behavior of YOURLS is to not allow hyphens in the shortlink, however when I enable “Allow Hyphens in Short URLs” plugin on the YOURLS server, they are still stripped out of my shortlinks in this plugin before they reach my YOURLS server.

    While this is more of an edge-case scenario, it would be nice if either hyphens were added to the accepted character list:

    public static function prepare_api_keyword( $string = '' ) {
    		return preg_replace( '/[^A-Za-z0-9\-]/', '', $string );
    	}

    or if the regex pattern could be filtered and modified by another function or plugin (so I can don’t have to modify the plugin code directly):

    public static function prepare_api_keyword( $string = '' ) {
    		$regex = '/[^A-Za-z0-9]/';
    		$filtered = apply_filters( 'YOURLS_shortlink_regex', $regex );
    		return preg_replace( $filtered', '', $string );
    	}

    Note: These blocks of code are for reference only (to give you a starting point) and have not been fully tested.

    ~Cam
    P.S. Thank you for a great plugin. It has made my YOURLS link creation way easier than before!

    https://wordpress.org/plugins/yourls-link-creator/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Andrew Norcross

    (@norcross)

    let me take a look and see what’s available. I may be able to add a filter for your edge case, I tend to avoid using regex unless I have to in favor of the sanitation methods in core.

    Thread Starter Cam

    (@crazycoolcam)

    Thank you. I’m looking forward to what you are able to find.

    ~Cam

    Plugin Author Andrew Norcross

    (@norcross)

    sorry for the delay, coming back to this. so if I understand correctly, you’re putting hyphens in your custom keyword ones?

    Thread Starter Cam

    (@crazycoolcam)

    Yes.

    So for example my shortlink would be “yourls.com/3-4”.

    The yourls installation has a plugin that will allow hypens, which I have enabled. (By default, though I’m not sure why, hypens are not allowed as characters, so my case is definitely more “edge-like”.)

    Thank you for picking this back up.

    ~Cam

    Thread Starter Cam

    (@crazycoolcam)

    A tiny additional piece of info you can use for testing:

    The plugin I am using on yourls to allow hyphens is the one called “Allow Hyphens in Short URLs” by Ozh. I believe it is one of the plugins that is bundled with all yourls installations.

    Thank you again for your help.

    ~Cam

    Plugin Author Andrew Norcross

    (@norcross)

    yep. this is gonna be a filter that you use to modify the keyword sanitation. since its something that isn’t always on by default, you’ll need to enable it. I’ll give you an example when I release the update.

    Thread Starter Cam

    (@crazycoolcam)

    Cool. Thanks!

    Plugin Author Andrew Norcross

    (@norcross)

    Just pushed the update. Here’s the filter you will need to add into your theme / functionality plugin (not the YOURLS plugin itself, of course) to handle it

    function rkv_allow_yourls_hyphens( $filter ) {
    	return '/[^A-Za-z0-9-]/';
    }
    add_filter( 'yourls_keyword_filter', 'rkv_allow_yourls_hyphens' );
    Thread Starter Cam

    (@crazycoolcam)

    Thanks Andrew.
    I have updated the plugin, added the filter into my files, and everything is working great.

    Thank you for the update and for the great plugin!

    ~Cam

    Plugin Author Andrew Norcross

    (@norcross)

    fantastic!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Plugin strips hyphens out of shortlink’ is closed to new replies.